org.matheclipse.core.generic.util
Class HMArrayList<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.matheclipse.core.generic.util.HMArrayList<E>
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess
- Direct Known Subclasses:
- AST
public class HMArrayList<E> extends java.util.AbstractList<E> implements java.util.List<E>, java.lang.Cloneable, java.io.Serializable, java.util.RandomAccessHMArrayList is an implementation ofList, backed by an array. All optional operations adding, removing, and replacing are supported. The elements can be any objects. Copied and modified from the Apache Harmony project.- Since:
- 1.2
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description HMArrayList()Constructs a new instance ofArrayListwith ten capacity.HMArrayList(java.util.Collection<? extends E> collection)Constructs a new instance ofArrayListcontaining the elements of the specified collection.HMArrayList(E ex, E... es)HMArrayList(int capacity)Constructs a new instance ofArrayListwith the specified capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(E object)Adds the specified object at the end of thisArrayList.voidadd(int location, E object)Inserts the specified object into thisArrayListat the specified location.booleanaddAll(java.util.Collection<? extends E> collection)Adds the objects in the specified collection to thisArrayList.booleanaddAll(int location, java.util.Collection<? extends E> collection)Inserts the objects in the specified collection at the specified location in this List.voidclear()Removes all elements from thisArrayList, leaving it empty.java.lang.Objectclone()Returns a newArrayListwith the same elements, the same size and the same capacity as thisArrayList.booleancontains(java.lang.Object object)Searches thisArrayListfor the specified object.voidensureCapacity(int minimumCapacity)Ensures that after this operation theArrayListcan hold the specified number of elements without further growing.booleanequals(java.lang.Object obj)Eget(int location)inthashCode()intindexOf(java.lang.Object object)booleanisEmpty()booleanisSameHead(E head)Check if the object at index 0 (i.e.booleanisSameHead(E head, int length)Check if the object at index 0 (i.e.booleanisSameHeadSizeGE(E head, int length)Check if the object at index 0 (i.e.intlastIndexOf(java.lang.Object object)Eremove(int location)Removes the object at the specified location from this list.booleanremove(java.lang.Object object)Eset(int location, E object)Replaces the element at the specified location in thisArrayListwith the specified object.intsize()Returns the number of elements in thisArrayList.java.lang.Object[]toArray()Returns a new array containing all elements contained in thisArrayList.<T> T[]toArray(T[] contents)Returns an array containing all elements contained in thisArrayList.voidtrimToSize()Sets the capacity of thisArrayListto be the same as the current size.-
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
-
-
-
-
Constructor Detail
-
HMArrayList
public HMArrayList()
Constructs a new instance ofArrayListwith ten capacity.
-
HMArrayList
public HMArrayList(int capacity)
Constructs a new instance ofArrayListwith the specified capacity.- Parameters:
capacity- the initial capacity of thisArrayList.
-
HMArrayList
public HMArrayList(java.util.Collection<? extends E> collection)
Constructs a new instance ofArrayListcontaining the elements of the specified collection. The initial size of theArrayListwill be 10% higher than the size of the specified collection.- Parameters:
collection- the collection of elements to add.
-
-
Method Detail
-
add
public void add(int location, E object)Inserts the specified object into thisArrayListat the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of thisArrayList, the object is added at the end.
-
add
public boolean add(E object)
Adds the specified object at the end of thisArrayList.
-
addAll
public boolean addAll(int location, java.util.Collection<? extends E> collection)Inserts the objects in the specified collection at the specified location in this List. The objects are added in the order they are returned from the collection's iterator.- Specified by:
addAllin interfacejava.util.List<E>- Overrides:
addAllin classjava.util.AbstractList<E>- Parameters:
location- the index at which to insert.collection- the collection of objects.- Returns:
trueif thisArrayListis modified,falseotherwise.- Throws:
java.lang.IndexOutOfBoundsException- whenlocation < 0 || > size()
-
addAll
public boolean addAll(java.util.Collection<? extends E> collection)
Adds the objects in the specified collection to thisArrayList.
-
clear
public void clear()
Removes all elements from thisArrayList, leaving it empty.
-
clone
public java.lang.Object clone()
Returns a newArrayListwith the same elements, the same size and the same capacity as thisArrayList.- Overrides:
clonein classjava.lang.Object- Returns:
- a shallow copy of this
ArrayList - See Also:
Cloneable
-
contains
public boolean contains(java.lang.Object object)
Searches thisArrayListfor the specified object.
-
ensureCapacity
public void ensureCapacity(int minimumCapacity)
Ensures that after this operation theArrayListcan hold the specified number of elements without further growing.- Parameters:
minimumCapacity- the minimum capacity asked for.
-
equals
public boolean equals(java.lang.Object obj)
-
isSameHead
public final boolean isSameHead(E head)
Check if the object at index 0 (i.e. the head of the list) is the same object asheadand if the size of the list equalslength.- Parameters:
head- object to compare with element at location0- Returns:
-
isSameHead
public final boolean isSameHead(E head, int length)
Check if the object at index 0 (i.e. the head of the list) is the same object asheadand if the size of the list equalslength.- Parameters:
head- object to compare with element at location0length-- Returns:
-
isSameHeadSizeGE
public final boolean isSameHeadSizeGE(E head, int length)
Check if the object at index 0 (i.e. the head of the list) is the same object asheadand if the size of the list is greater or equallength.- Parameters:
head- object to compare with element at location0length-- Returns:
-
get
public E get(int location)
-
hashCode
public int hashCode()
-
indexOf
public int indexOf(java.lang.Object object)
-
isEmpty
public boolean isEmpty()
-
lastIndexOf
public int lastIndexOf(java.lang.Object object)
-
remove
public E remove(int location)
Removes the object at the specified location from this list.
-
remove
public boolean remove(java.lang.Object object)
-
set
public E set(int location, E object)
Replaces the element at the specified location in thisArrayListwith the specified object.- Specified by:
setin interfacejava.util.List<E>- Overrides:
setin classjava.util.AbstractList<E>- Parameters:
location- the index at which to put the specified object.object- the object to add.- Returns:
- the previous element at the index.
- Throws:
java.lang.IndexOutOfBoundsException- whenlocation < 0 || >= size()
-
size
public int size()
Returns the number of elements in thisArrayList.
-
toArray
public java.lang.Object[] toArray()
Returns a new array containing all elements contained in thisArrayList.
-
toArray
public <T> T[] toArray(T[] contents)
Returns an array containing all elements contained in thisArrayList. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than thisArrayList, the array element following the collection elements is set to null.- Specified by:
toArrayin interfacejava.util.Collection<E>- Specified by:
toArrayin interfacejava.util.List<E>- Overrides:
toArrayin classjava.util.AbstractCollection<E>- Parameters:
contents- the array.- Returns:
- an array of the elements from this
ArrayList. - Throws:
java.lang.ArrayStoreException- when the type of an element in thisArrayListcannot be stored in the type of the specified array.
-
trimToSize
public void trimToSize()
Sets the capacity of thisArrayListto be the same as the current size.- See Also:
size()
-
-
DMelt 3.0 © DataMelt by jWork.ORG