- java.lang.Object
-
- org.arakhne.afc.util.IntegerList
-
- All Implemented Interfaces:
Iterable<Integer>
,Collection<Integer>
,List<Integer>
,Set<Integer>
,SortedSet<Integer>
public class IntegerList extends Object implements SortedSet<Integer>, List<Integer>
This class represents a list of numbers. The list is always sorted by number values.- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- util
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
IntegerList.IntegerSegment
This class describes a integers' segment.
-
Constructor Summary
Constructors Constructor Description IntegerList()
Create a list with the specified values.IntegerList(int value)
Create a list with the specified value.IntegerList(int start, int end)
Create a list with the specified values.IntegerList(Collection<? extends Integer> collection)
Create a list with the specified values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, Integer element)
boolean
add(Integer value)
boolean
addAll(int index, Collection<? extends Integer> collection)
boolean
addAll(Collection<? extends Integer> collection)
void
clear()
Comparator<? super Integer>
comparator()
boolean
contains(Object obj)
boolean
containsAll(Collection<?> collection)
Integer
first()
Integer
get(int index)
protected boolean
get(int offset, int[] tofill)
Replies the segment index for the specified value.protected int
getFirstValueOnSegment(int idxSegment)
Replies the first value of a segment.protected int
getLastValueOnSegment(int idxSegment)
Replies the last value of a segment.protected int
getSegmentCount()
Replies the count of segments.protected int
getSegmentIndexFor(int value)
Replies the segment index for the specified value.SortedSet<Integer>
headSet(Integer toElement)
int
indexOf(Object obj)
boolean
isEmpty()
Iterator<Integer>
iterator()
Integer
last()
int
lastIndexOf(Object obj)
ListIterator<Integer>
listIterator()
ListIterator<Integer>
listIterator(int index)
Integer
remove(int index)
boolean
remove(Object obj)
boolean
removeAll(Collection<?> collection)
protected boolean
removeElementInSegment(int segmentIndex, int element)
Remove theelement
in the segment starting at indexsegmentIndex
.protected boolean
removeSegment(int segmentIndex)
Remove theelement
in the segment starting at indexsegmentIndex
.boolean
retainAll(Collection<?> collection)
Iterator<IntegerList.IntegerSegment>
segmentIterator()
Returns an iterator over the segments in this list in proper sequence.Integer
set(int index, Integer element)
void
set(SortedSet<? extends Number> collection)
Set the content of this list from the specified collection.int
size()
Spliterator<Integer>
spliterator()
List<Integer>
subList(int fromIndex, int toIndex)
SortedSet<Integer>
subSet(Integer fromElement, Integer toElement)
SortedSet<Integer>
tailSet(Integer fromElement)
Object[]
toArray()
<T> T[]
toArray(T[] array)
int[]
toIntArray()
Returns an array containing all of the elements in this list in proper sequence (from first to last element).Iterable<IntegerList.IntegerSegment>
toSegmentIterable()
Returns an iterable object over the segments in this list in proper sequence.SortedSet<Integer>
toSortedSet()
Replies the complete list of stored integers.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort
-
-
-
-
Constructor Detail
-
IntegerList
public IntegerList()
Create a list with the specified values.
-
IntegerList
public IntegerList(int value)
Create a list with the specified value.- Parameters:
value
- is the initial value.
-
IntegerList
public IntegerList(int start, int end)
Create a list with the specified values.- Parameters:
start
- is the first initial valueend
- is the last initial value
-
IntegerList
public IntegerList(Collection<? extends Integer> collection)
Create a list with the specified values.- Parameters:
collection
- is the list of initial values
-
-
Method Detail
-
comparator
@Pure public Comparator<? super Integer> comparator()
- Specified by:
comparator
in interfaceSortedSet<Integer>
-
add
public boolean add(Integer value)
-
addAll
public final boolean addAll(int index, Collection<? extends Integer> collection)
-
addAll
public boolean addAll(Collection<? extends Integer> collection)
-
clear
public void clear()
-
contains
@Pure public boolean contains(Object obj)
-
containsAll
@Pure public boolean containsAll(Collection<?> collection)
- Specified by:
containsAll
in interfaceCollection<Integer>
- Specified by:
containsAll
in interfaceList<Integer>
- Specified by:
containsAll
in interfaceSet<Integer>
-
isEmpty
@Pure public boolean isEmpty()
-
segmentIterator
@Pure public Iterator<IntegerList.IntegerSegment> segmentIterator()
Returns an iterator over the segments in this list in proper sequence.- Returns:
- an iterator over the segments in this list in proper sequence
-
toSegmentIterable
@Pure public Iterable<IntegerList.IntegerSegment> toSegmentIterable()
Returns an iterable object over the segments in this list in proper sequence.- Returns:
- an iterable object over the segments in this list in proper sequence
-
remove
public boolean remove(Object obj)
-
removeElementInSegment
protected boolean removeElementInSegment(int segmentIndex, int element)
Remove theelement
in the segment starting at indexsegmentIndex
.- Parameters:
segmentIndex
- is the index of the segment from which the element must be removed.element
- is the element to remove.- Returns:
true
if the element was removed, otherwhisefalse
-
removeSegment
protected boolean removeSegment(int segmentIndex)
Remove theelement
in the segment starting at indexsegmentIndex
.- Parameters:
segmentIndex
- is the index of the segment to remove.- Returns:
true
if the element was removed, otherwhisefalse
-
removeAll
public boolean removeAll(Collection<?> collection)
-
retainAll
public boolean retainAll(Collection<?> collection)
-
set
public void set(SortedSet<? extends Number> collection)
Set the content of this list from the specified collection.- Parameters:
collection
- is the values to pout inside this list.
-
size
@Pure public int size()
-
getSegmentCount
protected int getSegmentCount()
Replies the count of segments.- Returns:
- the count of segments.
-
getLastValueOnSegment
protected int getLastValueOnSegment(int idxSegment)
Replies the last value of a segment.- Parameters:
idxSegment
- is the index of the segment. It must be a multiple of 2.- Returns:
- the last value in the segment.
-
getFirstValueOnSegment
protected int getFirstValueOnSegment(int idxSegment)
Replies the first value of a segment.- Parameters:
idxSegment
- is the index of the segment. It must be a multiple of 2.- Returns:
- the first value in the segment
-
getSegmentIndexFor
protected int getSegmentIndexFor(int value)
Replies the segment index for the specified value.- Parameters:
value
- is the value to search for.- Returns:
- the index or
-1
. It is a multiple of 2.
-
get
protected boolean get(int offset, int[] tofill)
Replies the segment index for the specified value.The given array must be pre-allocated with at least 2 cells. The first cell will the the index of the segment. The second cell will be the first integer value.
- Parameters:
offset
- is the number of integer values to skip from the begining of the value set.tofill
- is the 2-cell array to fill- Returns:
true
on success,false
otherwise.
-
toArray
@Pure public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] array)
-
toIntArray
@Pure public int[] toIntArray()
Returns an array containing all of the elements in this list in proper sequence (from first to last element).The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
- Returns:
- an array containing all of the elements in this list in proper sequence
- See Also:
Arrays.asList(Object[])
-
toSortedSet
@Pure public SortedSet<Integer> toSortedSet()
Replies the complete list of stored integers.- Returns:
- the set of values.
-
lastIndexOf
@Pure public int lastIndexOf(Object obj)
- Specified by:
lastIndexOf
in interfaceList<Integer>
-
listIterator
@Pure public ListIterator<Integer> listIterator()
- Specified by:
listIterator
in interfaceList<Integer>
-
listIterator
@Pure public ListIterator<Integer> listIterator(int index)
- Specified by:
listIterator
in interfaceList<Integer>
-
spliterator
@Pure public Spliterator<Integer> spliterator()
- Specified by:
spliterator
in interfaceCollection<Integer>
- Specified by:
spliterator
in interfaceIterable<Integer>
- Specified by:
spliterator
in interfaceList<Integer>
- Specified by:
spliterator
in interfaceSet<Integer>
- Specified by:
spliterator
in interfaceSortedSet<Integer>
-
-