您现在的位置是:主页 > news > 美仑美家具的网站谁做的/潍坊seo招聘
美仑美家具的网站谁做的/潍坊seo招聘
admin2025/5/18 2:31:15【news】
简介美仑美家具的网站谁做的,潍坊seo招聘,多梦主题建设的网站,网站建设打造FastList 是 HikariCP数据库连接池中使用的自定义的list。其实也没什么特别的,主要就是去掉了range check取数据更快一些。 (1)类定义 public final class FastList<T> extends ArrayList<T> 继承自ArrayList, &a…
FastList 是 HikariCP数据库连接池中使用的自定义的list。其实也没什么特别的,主要就是去掉了range check取数据更快一些。
(1)类定义
public final class FastList<T> extends ArrayList<T>
继承自ArrayList,
(2)成员变量
private final Class<?> clazz;private T[] elementData;private int size;
clazz :list中存储的数据类型class。
elementData:存储数据的源数组。
size:列表目前大小
(3)构造函数
@SuppressWarnings("unchecked")public FastList(Class<?> clazz){this.elementData = (T[]) Array.newInstance(clazz, 32);this.clazz = clazz;}@SuppressWarnings("unchecked")public FastList(Class<?> clazz, int capacity){this.elementData = (T[]) Array.newInstance(clazz, capacity);this.clazz = clazz;}
传递数据类型和初始的数组容量,默认容量大小为32,,不同于size。
(4)add添加一个元素
@Overridepublic boolean add(T element){try {elementData[size++] = element;}catch (ArrayIndexOutOfBoundsException e) {// overflow-conscious codefinal int oldCapacity = elementData.length;final int newCapacity = oldCapacity << 1;@SuppressWarnings("unchecked")final T[] newElementData = (T[]) Array.newInstance(clazz, newCapacity);System.arraycopy(elementData, 0, newElementData, 0, oldCapacity);newElementData[size - 1] = element;elementData = newElementData;}return true;}
重写了add方法。
往数组里面插入元素,size增加1,如果是数组越界,扩容为原来容量的2倍。最后将扩容后的数组赋值给源数组。
(5)get获取指定位置的元素
@Overridepublic T get(int index){return elementData[index];}
重写了get方法。
直接获取数组的index下标,越界直接抛出异常。
(6)移除最后一个元素
public T removeLast(){T element = elementData[--size];elementData[size] = null;return element;}
将size -1 的位置元素取出来,然后置空,size 减1;
(7)移除指定元素
@Overridepublic boolean remove(Object element){for (int index = size - 1; index >= 0; index--) {if (element == elementData[index]) {final int numMoved = size - index - 1;if (numMoved > 0) {System.arraycopy(elementData, index + 1, elementData, index, numMoved);}elementData[--size] = null;return true;}}return false;}
从数组的最后面往前面找,如果碰到第一个相同的元素的时候就直接移除,并且copy原来的数组,size减1.注意的是判断相等是用的最基础的 ==。
(8)清除所有的元素
@Overridepublic void clear(){for (int i = 0; i < size; i++) {elementData[i] = null;}size = 0;}
从头到尾(size)设置为空,size = 0;
(9)返回大小,判断是否为空,不多说
@Overridepublic int size(){return size;}@Overridepublic boolean isEmpty(){return size == 0;}
(10)最后还是源码直接粘贴一下吧
/** Copyright (C) 2013, 2014 Brett Wooldridge** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package com.zaxxer.hikari.util;import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;/*** Fast list without range checking.** @author Brett Wooldridge*/
public final class FastList<T> extends ArrayList<T>
{private static final long serialVersionUID = -4598088075242913858L;private final Class<?> clazz;private T[] elementData;private int size;/*** Construct a FastList with a default size of 32.* @param clazz the Class stored in the collection*/@SuppressWarnings("unchecked")public FastList(Class<?> clazz){this.elementData = (T[]) Array.newInstance(clazz, 32);this.clazz = clazz;}/*** Construct a FastList with a specified size.* @param clazz the Class stored in the collection* @param capacity the initial size of the FastList*/@SuppressWarnings("unchecked")public FastList(Class<?> clazz, int capacity){this.elementData = (T[]) Array.newInstance(clazz, capacity);this.clazz = clazz;}/*** Add an element to the tail of the FastList.** @param element the element to add*/@Overridepublic boolean add(T element){try {elementData[size++] = element;}catch (ArrayIndexOutOfBoundsException e) {// overflow-conscious codefinal int oldCapacity = elementData.length;final int newCapacity = oldCapacity << 1;@SuppressWarnings("unchecked")final T[] newElementData = (T[]) Array.newInstance(clazz, newCapacity);System.arraycopy(elementData, 0, newElementData, 0, oldCapacity);newElementData[size - 1] = element;elementData = newElementData;}return true;}/*** Get the element at the specified index.** @param index the index of the element to get* @return the element, or ArrayIndexOutOfBounds is thrown if the index is invalid*/@Overridepublic T get(int index){return elementData[index];}/*** Remove the last element from the list. No bound check is performed, so if this* method is called on an empty list and ArrayIndexOutOfBounds exception will be* thrown.** @return the last element of the list*/public T removeLast(){T element = elementData[--size];elementData[size] = null;return element;}/*** This remove method is most efficient when the element being removed* is the last element. Equality is identity based, not equals() based.* Only the first matching element is removed.** @param element the element to remove*/@Overridepublic boolean remove(Object element){for (int index = size - 1; index >= 0; index--) {if (element == elementData[index]) {final int numMoved = size - index - 1;if (numMoved > 0) {System.arraycopy(elementData, index + 1, elementData, index, numMoved);}elementData[--size] = null;return true;}}return false;}/*** Clear the FastList.*/@Overridepublic void clear(){for (int i = 0; i < size; i++) {elementData[i] = null;}size = 0;}/*** Get the current number of elements in the FastList.** @return the number of current elements*/@Overridepublic int size(){return size;}/** {@inheritDoc} */@Overridepublic boolean isEmpty(){return size == 0;}/** {@inheritDoc} */@Overridepublic T set(int index, T element){T old = elementData[index];elementData[index] = element;return old;}/** {@inheritDoc} */@Overridepublic T remove(int index){if (size == 0) {return null;}final T old = elementData[index];final int numMoved = size - index - 1;if (numMoved > 0) {System.arraycopy(elementData, index + 1, elementData, index, numMoved);}elementData[--size] = null;return old;}/** {@inheritDoc} */@Overridepublic boolean contains(Object o){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic Iterator<T> iterator(){return new Iterator<T>() {private int index;@Overridepublic boolean hasNext(){return index < size;}@Overridepublic T next(){if (index < size) {return elementData[index++];}throw new NoSuchElementException("No more elements in FastList"); }};}/** {@inheritDoc} */@Overridepublic Object[] toArray(){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic <E> E[] toArray(E[] a){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic boolean containsAll(Collection<?> c){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic boolean addAll(Collection<? extends T> c){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic boolean addAll(int index, Collection<? extends T> c){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic boolean removeAll(Collection<?> c){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic boolean retainAll(Collection<?> c){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic void add(int index, T element){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic int indexOf(Object o){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic int lastIndexOf(Object o){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic ListIterator<T> listIterator(){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic ListIterator<T> listIterator(int index){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic List<T> subList(int fromIndex, int toIndex){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic void trimToSize(){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic void ensureCapacity(int minCapacity){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overridepublic Object clone(){throw new UnsupportedOperationException();}/** {@inheritDoc} */@Overrideprotected void removeRange(int fromIndex, int toIndex){throw new UnsupportedOperationException();}/** {@inheritDoc} */public void forEach(Consumer<? super T> action){throw new UnsupportedOperationException();}/** {@inheritDoc} */public Spliterator<T> spliterator(){throw new UnsupportedOperationException();}/** {@inheritDoc} */public boolean removeIf(Predicate<? super T> filter){throw new UnsupportedOperationException();}/** {@inheritDoc} */public void replaceAll(UnaryOperator<T> operator){throw new UnsupportedOperationException();}/** {@inheritDoc} */public void sort(Comparator<? super T> c){throw new UnsupportedOperationException();}
}