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 boolean
add(Integer value)
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.IntegerList
clone()
Returns a clone of this list.void
fill(int value)
Fills the list with the given value.Integer
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
maximalValue()
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.Integer
set(int index, Integer 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
trimToSize()
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:
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
public boolean add(Integer value) throws IllegalArgumentException
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
public void addInteger(int value) throws IllegalArgumentException
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
public Integer get(int index) throws IndexOutOfBoundsException
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
public int getInteger(int index) throws IndexOutOfBoundsException
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
public Integer set(int index, Integer value) throws IndexOutOfBoundsException
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
public void setInteger(int index, int value) throws IndexOutOfBoundsException
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
public IntegerList clone()
Returns a clone of this list.- Specified by:
clone
in interfaceCloneable
- Overrides:
clone
in classObject
- Returns:
- A clone of this list.
- See Also:
Object.clone()
-
-