Package org.geotools.util
Class 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:
-
Field Summary
Fields inherited from class AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionIntegerList(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
Modifier and TypeMethodDescriptionbooleanAdds the given element to this list.voidaddInteger(int value) Adds the given element as theintprimitive type.voidclear()Discarts all elements in this list.clone()Returns a clone of this list.voidfill(int value) Fills the list with the given value.get(int index) Returns the element at the given index.intgetInteger(int index) Returns the element at the given index as theintprimitive type.intReturns 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.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.voidTrims 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, subListMethods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Constructor Details
-
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 Details
-
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
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
Adds the given element as theintprimitive type.- Parameters:
value- The value to add.- Throws:
IllegalArgumentException- if the given value is out of bounds.
-
get
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
Returns 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
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
Sets 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
Returns a clone of this list.
-