Package org.apache.sis.util.collection
Class IntegerList
- All Implemented Interfaces:
- Serializable,- Cloneable,- Iterable<Integer>,- Collection<Integer>,- List<Integer>,- RandomAccess
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 responsibility.
- Since:
- 0.7
- See Also:
Defined in the sis-utility module
- 
Field SummaryFields inherited from class AbstractListmodCount
- 
Constructor SummaryConstructorsConstructorDescriptionIntegerList(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 SummaryModifier and TypeMethodDescriptionbooleanAdds the given element to this list.voidaddInt(int value) Adds the given element as theintprimitive type.voidclear()Discards all elements in this list.clone()Returns a clone of this list.booleanCompares the content of this list with the given object.voidfill(int value) Fills the list with the given value.get(int index) Returns the element at the given index.intgetInt(int index) Returns the element at the given index as theintprimitive type.iterator()Returns an iterator over the elements in this list in increasing index order.intReturns the maximal value that can be stored in this list.intoccurrence(int value) Returns the occurrence of the given value in this list.remove(int index) Removes the element at the given index.intRetrieves and remove the last element of this list.protected voidremoveRange(int lower, int upper) Removes all values in the given range of index.voidresize(int size) Sets the list size to the given value.Sets the element at the given index.voidsetInt(int index, int value) Sets the element at the given index as theintprimitive type.intsize()Returns the current number of values in this list.Returns an spliterator over the elements in this list in increasing index order.stream(boolean parallel) Returns a stream of integers with thisIntegerListas its source.voidTrims the capacity of this list to be its current size.Methods inherited from class AbstractListadd, addAll, hashCode, indexOf, lastIndexOf, listIterator, listIterator, subListMethods inherited from class AbstractCollectionaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface CollectionparallelStream, removeIf, stream, toArrayMethods inherited from interface ListaddAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, toArray, toArray
- 
Constructor Details- 
IntegerListpublic 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.
 
- 
IntegerListpublic 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- if- true, the initial size is set to the initial capacity with all values set to 0.
 
 
- 
- 
Method Details- 
maximalValuepublic int maximalValue()Returns the maximal value that can be stored in this list. May be slightly higher than the value given to the constructor.- Returns:
- the maximal value, inclusive.
 
- 
sizepublic int size()Returns the current number of values in this list.- Specified by:
- sizein interface- Collection<Integer>
- Specified by:
- sizein interface- List<Integer>
- Specified by:
- sizein class- AbstractCollection<Integer>
- Returns:
- the number of values.
 
- 
resizepublic 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 discarded. If the new size is greater than the previous one, then the extra elements are initialized to 0.- Parameters:
- size- the new size.
- See Also:
 
- 
fillpublic 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.
 
- 
clearpublic void clear()Discards all elements in this list.- Specified by:
- clearin interface- Collection<Integer>
- Specified by:
- clearin interface- List<Integer>
- Overrides:
- clearin class- AbstractList<Integer>
 
- 
addAdds the given element to this list.- Specified by:
- addin interface- Collection<Integer>
- Specified by:
- addin interface- List<Integer>
- Overrides:
- addin class- AbstractList<Integer>
- Parameters:
- value- the value to add.
- Returns:
- always true.
- Throws:
- NullPointerException- if the given value is null.
- IllegalArgumentException- if the given value is out of bounds.
 
- 
addIntAdds the given element as theintprimitive type.- Parameters:
- value- the value to add.
- Throws:
- IllegalArgumentException- if the given value is out of bounds.
- See Also:
 
- 
getReturns the element at the given index.- Specified by:
- getin interface- List<Integer>
- Specified by:
- getin class- AbstractList<Integer>
- Parameters:
- index- the element index.
- Returns:
- the value at the given index.
- Throws:
- IndexOutOfBoundsException- if the given index is out of bounds.
 
- 
getIntReturns 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.
 
- 
setSets the element at the given index.- Specified by:
- setin interface- List<Integer>
- Overrides:
- setin class- AbstractList<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.
 
- 
setIntSets 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.
 
- 
removeRemoves the element at the given index.- Specified by:
- removein interface- List<Integer>
- Overrides:
- removein class- AbstractList<Integer>
- Parameters:
- index- the index of the element to remove.
- Returns:
- the previous value of the element at the given index.
- Throws:
- IndexOutOfBoundsException- if the given index is out of bounds.
 
- 
removeLastRetrieves and remove the last element of this list.- Returns:
- the tail of this list.
- Throws:
- NoSuchElementException- if this list is empty.
 
- 
removeRangeprotected void removeRange(int lower, int upper) Removes all values in the given range of index. Shifts any succeeding elements to the left (reduces their index).- Overrides:
- removeRangein class- AbstractList<Integer>
- Parameters:
- lower- index of the first element to remove, inclusive.
- upper- index after the last element to be removed.
 
- 
occurrencepublic int occurrence(int value) Returns the occurrence 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.
 
- 
iteratorReturns an iterator over the elements in this list in increasing index order. The iterator is fail-fast and supports the remove operation.
- 
spliteratorReturns an spliterator over the elements in this list in increasing index order. The iterator is fail-fast.- Specified by:
- spliteratorin interface- Collection<Integer>
- Specified by:
- spliteratorin interface- Iterable<Integer>
- Specified by:
- spliteratorin interface- List<Integer>
- Returns:
- spliterator over the integer values in this list.
- Since:
- 0.8-jdk8
 
- 
streamReturns a stream of integers with thisIntegerListas its source. This method is similar toCollection.stream(), but does not box the values. The returned stream is fail-fast, meaning that any modification to the list while using the stream will cause aConcurrentModificationExceptionto be thrown.The default implementation creates a parallel or sequential stream from spliterator().- Parameters:
- parallel-- truefor a parallel stream, or- falsefor a sequential stream.
- Returns:
- a stream of values in this list as primitive types.
- Since:
- 0.8-jdk8
 
- 
trimToSizepublic void trimToSize()Trims the capacity of this list to be its current size.- See Also:
 
- 
equalsCompares the content of this list with the given object. This method overrides thedefault implementationfor performance reasons.- Specified by:
- equalsin interface- Collection<Integer>
- Specified by:
- equalsin interface- List<Integer>
- Overrides:
- equalsin class- AbstractList<Integer>
- Parameters:
- other- the other object to compare with this list.
- Returns:
- trueif both object are equal.
- Since:
- 1.1
 
- 
cloneReturns a clone of this list.
 
-