Package org.geotools.util
Class IntegerList
- Object
-
- AbstractCollection<E>
-
- AbstractList<Integer>
-
- IntegerList
-
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Integer>,Collection<Integer>,List<Integer>,RandomAccess,Cloneable
public class IntegerList extends AbstractList<Integer> implements RandomAccess, Serializable, Cloneable
A list of unsigned integer values. This class packs the values in the minimal amount of bits required for storing unsigned integers of the given maximal value.This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.
- Since:
- 2.5
- Author:
- Martin Desruisseaux (Geomatys)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description IntegerList(int initialCapacity, int maximalValue)Creates an initially empty list with the given initial capacity.IntegerList(int initialCapacity, int maximalValue, boolean fill)Creates a new list with the given initial size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Integer value)Adds the given element to this list.voidaddInteger(int value)Adds the given element as theintprimitive type.voidclear()Discarts all elements in this list.IntegerListclone()Returns a clone of this list.voidfill(int value)Fills the list with the given value.Integerget(int index)Returns the element at the given index.intgetInteger(int index)Returns the element at the given index as theintprimitive type.intmaximalValue()Returns the maximal value that can be stored in this list.intoccurence(int value)Returns the occurence of the given value in this list.voidresize(int size)Sets the list size to the given value.Integerset(int index, Integer value)Sets the element at the given index.voidsetInteger(int index, int value)Sets the element at the given index as theintprimitive type.intsize()Returns the current number of values in this list.voidtrimToSize()Trims the capacity of this list to be its current size.-
Methods inherited from class AbstractList
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
-
Methods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
IntegerList
public IntegerList(int initialCapacity, int maximalValue)Creates an initially empty list with the given initial capacity.- Parameters:
initialCapacity- The initial capacity.maximalValue- The maximal value to be allowed, inclusive.
-
IntegerList
public IntegerList(int initialCapacity, int maximalValue, boolean fill)Creates a new list with the given initial size. The value of all elements are initialized to 0.- Parameters:
initialCapacity- The initial capacity.maximalValue- The maximal value to be allowed, inclusive.fill- Iftrue, the initial size is set to the initial capacity with all values set to 0.
-
-
Method Detail
-
maximalValue
public int maximalValue()
Returns the maximal value that can be stored in this list. May be slighly higher than the value given to the constructor.- Returns:
- The maximal value, inclusive.
-
size
public int size()
Returns the current number of values in this list.- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceList<Integer>- Specified by:
sizein classAbstractCollection<Integer>- Returns:
- The number of values.
-
resize
public void resize(int size)
Sets the list size to the given value. If the new size is lower than previous size, then the elements after the new size are discarted. If the new size is greater than the previous one, then the extra elements are initialized to 0.- Parameters:
size- The new size.
-
fill
public void fill(int value)
Fills the list with the given value. Every existing values are overwritten from index 0 inclusive up tosizeexclusive.- Parameters:
value- The value to set.
-
clear
public void clear()
Discarts all elements in this list.- Specified by:
clearin interfaceCollection<Integer>- Specified by:
clearin interfaceList<Integer>- Overrides:
clearin classAbstractList<Integer>
-
add
public boolean add(Integer value) throws IllegalArgumentException
Adds the given element to this list.- Specified by:
addin interfaceCollection<Integer>- Specified by:
addin interfaceList<Integer>- Overrides:
addin classAbstractList<Integer>- Parameters:
value- The value to add.- Throws:
NullPointerException- if the given value is null.IllegalArgumentException- if the given value is out of bounds.
-
addInteger
public void addInteger(int value) throws IllegalArgumentExceptionAdds the given element as theintprimitive type.- Parameters:
value- The value to add.- Throws:
IllegalArgumentException- if the given value is out of bounds.
-
get
public Integer get(int index) throws IndexOutOfBoundsException
Returns the element at the given index.- Specified by:
getin interfaceList<Integer>- Specified by:
getin classAbstractList<Integer>- Parameters:
index- The element index.- Returns:
- The value at the given index.
- Throws:
IndexOutOfBoundsException- if the given index is out of bounds.
-
getInteger
public int getInteger(int index) throws IndexOutOfBoundsExceptionReturns the element at the given index as theintprimitive type.- Parameters:
index- The element index.- Returns:
- The value at the given index.
- Throws:
IndexOutOfBoundsException- if the given index is out of bounds.
-
set
public Integer set(int index, Integer value) throws IndexOutOfBoundsException
Sets the element at the given index.- Specified by:
setin interfaceList<Integer>- Overrides:
setin classAbstractList<Integer>- Parameters:
index- The element index.value- The value at the given index.- Returns:
- The previous value at the given index.
- Throws:
IndexOutOfBoundsException- if the given index is out of bounds.IllegalArgumentException- if the given value is out of bounds.NullPointerException- if the given value is null.
-
setInteger
public void setInteger(int index, int value) throws IndexOutOfBoundsExceptionSets the element at the given index as theintprimitive type.- Parameters:
index- The element index.value- The value at the given index.- Throws:
IndexOutOfBoundsException- if the given index is out of bounds.IllegalArgumentException- if the given value is out of bounds.
-
occurence
public int occurence(int value)
Returns the occurence of the given value in this list.- Parameters:
value- The value to search for.- Returns:
- The number of time the given value occurs in this list.
-
trimToSize
public void trimToSize()
Trims the capacity of this list to be its current size.
-
clone
public IntegerList clone()
Returns a clone of this list.- Specified by:
clonein interfaceCloneable- Overrides:
clonein classObject- Returns:
- A clone of this list.
- See Also:
Object.clone()
-
-