APIdia Launch Partner
Top Description Fields Constructors Methods
sun.swing

public Class BakedArrayList<E>

extends ArrayList<E>
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.util.*

Warning

This class is an implementation detail and is only public so that it can be used by two packages. You should NOT consider this public API.

WARNING 2: This is not a general purpose List implementation! It has a specific use and will not work correctly if you use it outside of its use.

A specialized ArrayList that caches its hashCode as well as overriding equals to avoid creating an Iterator. This class is useful in scenarios where the list won't change and you want to avoid the overhead of hashCode iterating through the elements invoking hashCode. This also assumes you'll only ever compare a BakedArrayList to another BakedArrayList.

Author
Scott Violet

Field Summary

Modifier and TypeField and Description
private int
_hashCode

The cached hashCode.

Constructor Summary

AccessConstructor and Description
public
BakedArrayList(int size)

public
BakedArrayList(List<? extends E> data)

Method Summary

Modifier and TypeMethod and Description
public void
cacheHashCode()

Caches the hash code.

public boolean
equals(Object o)

Overrides java.util.ArrayList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.

public int
hashCode()

Overrides java.util.ArrayList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.

Inherited from java.util.ArrayList:
addaddaddAlladdAlladdFirstaddLastclearclonecontainsensureCapacityforEachgetgetFirstgetLastindexOfisEmptyiteratorlastIndexOflistIteratorlistIteratorremoveremoveremoveAllremoveFirstremoveIfremoveLastremoveRangereplaceAllretainAllsetsizesortspliteratorsubListtoArraytoArraytrimToSize

Field Detail

_hashCodeback to summary
private int _hashCode

The cached hashCode.

Constructor Detail

BakedArrayListback to summary
public BakedArrayList(int size)
BakedArrayListback to summary
public BakedArrayList(List<? extends E> data)

Method Detail

cacheHashCodeback to summary
public void cacheHashCode()

Caches the hash code. It is assumed you won't modify the list, or that if you do you'll call cacheHashCode again.

equalsback to summary
public boolean equals(Object o)

Overrides java.util.ArrayList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.ArrayList.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if Objects.equals(e1, e2).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

hashCodeback to summary
public int hashCode()

Overrides java.util.ArrayList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.ArrayList.hashCode.

Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:

int hashCode = 1;
    for (E e : list)
        hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object#hashCode.