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 TypeMethodDescriptionboolean
Adds the given element to this list.void
addInteger
(int value) Adds the given element as theint
primitive type.void
clear()
Discarts all elements in this list.clone()
Returns a clone of this list.void
fill
(int value) Fills the list with the given value.get
(int index) Returns the element at the given index.int
getInteger
(int index) Returns the element at the given index as theint
primitive type.int
Returns the maximal value that can be stored in this list.int
occurence
(int value) Returns the occurence of the given value in this list.void
resize
(int size) Sets the list size to the given value.Sets the element at the given index.void
setInteger
(int index, int value) Sets the element at the given index as theint
primitive type.int
size()
Returns the current number of values in this list.void
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 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:
size
in interfaceCollection<Integer>
- Specified by:
size
in interfaceList<Integer>
- Specified by:
size
in 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 tosize
exclusive.- Parameters:
value
- The value to set.
-
clear
public void clear()Discarts all elements in this list.- Specified by:
clear
in interfaceCollection<Integer>
- Specified by:
clear
in interfaceList<Integer>
- Overrides:
clear
in classAbstractList<Integer>
-
add
Adds the given element to this list.- Specified by:
add
in interfaceCollection<Integer>
- Specified by:
add
in interfaceList<Integer>
- Overrides:
add
in 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 theint
primitive 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:
get
in interfaceList<Integer>
- Specified by:
get
in 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 theint
primitive 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:
set
in interfaceList<Integer>
- Overrides:
set
in 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 theint
primitive 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.
-