Package org.apache.ignite.internal.util
Class GridLongList
java.lang.Object
org.apache.ignite.internal.util.GridLongList
- Direct Known Subclasses:
LongListReuseBag
Minimal list API to work with primitive longs. This list exists
to avoid boxing/unboxing when using standard list from Java.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long x) Add element to this array.voidstatic GridLongListaddAll(GridLongList to, GridLongList from) long[]array()static GridLongListasList(long... vals) voidclear()Clears the list.booleancontains(long l) booleancopy()Returns (possibly reordered) copy of this list, excluding all elements of given list.booleandistinct()booleanlongget(int i) inthashCode()booleanisEmpty()longlast()Gets the last element.voidpop(int cnt) Removes given number of elements from the end.static GridLongListlongremove()Removes and returns the last element of the list.longremoveIndex(int i) Removes element by given index.intremoveValue(int startIdx, long val) Removes value from this list.intreplaceValue(int startIdx, long oldVal, long newVal) Removes value from this list.intsize()sort()Sorts this list.toString()voidtruncate(int size, boolean last) static voidwriteTo(DataOutput out, GridLongList list)
-
Field Details
-
EMPTY_ARRAY
public static final long[] EMPTY_ARRAYEmpty array.
-
-
Constructor Details
-
GridLongList
public GridLongList() -
GridLongList
public GridLongList(int size) - Parameters:
size- Size.
-
GridLongList
public GridLongList(long[] arr) - Parameters:
arr- Array.
-
-
Method Details
-
asList
- Parameters:
vals- Values.- Returns:
- List from values.
-
copy
- Returns:
- Copy of this list.
-
equals
-
hashCode
public int hashCode() -
addAll
- Parameters:
l- List to add all elements of.
-
add
public void add(long x) Add element to this array.- Parameters:
x- Value.
-
clear
public void clear()Clears the list. -
last
public long last()Gets the last element.- Returns:
- The last element.
-
remove
Removes and returns the last element of the list. Complementary method toadd(long)for stack like usage.- Returns:
- Removed element.
- Throws:
NoSuchElementException- If the list is empty.
-
copyWithout
Returns (possibly reordered) copy of this list, excluding all elements of given list.- Parameters:
l- List of elements to remove.- Returns:
- New list without all elements from
l.
-
get
public long get(int i) - Parameters:
i- Index.- Returns:
- Value.
-
size
public int size()- Returns:
- Size.
-
isEmpty
public boolean isEmpty()- Returns:
Trueif this list has no elements.
-
contains
public boolean contains(long l) - Parameters:
l- Element to find.- Returns:
Trueif found.
-
containsAll
- Parameters:
l- List to check.- Returns:
Trueif this list contains all the elements of passed in list.
-
distinct
public boolean distinct()- Returns:
Trueif there are no duplicates.
-
truncate
public void truncate(int size, boolean last) - Parameters:
size- New size.last- Iftruethe last elements will be removed, otherwise the first.
-
removeIndex
public long removeIndex(int i) Removes element by given index.- Parameters:
i- Index.- Returns:
- Removed value.
-
removeValue
public int removeValue(int startIdx, long val) Removes value from this list.- Parameters:
startIdx- Index to begin search with.val- Value.- Returns:
- Index of removed value if the value was found and removed or
-1otherwise.
-
replaceValue
public int replaceValue(int startIdx, long oldVal, long newVal) Removes value from this list.- Parameters:
startIdx- Index to begin search with.oldVal- Old value.newVal- New value.- Returns:
- Index of replaced value if the value was found and replaced or
-1otherwise.
-
array
public long[] array()- Returns:
- Array copy.
-
toString
-
readFrom
- Parameters:
in- Input to read list from.- Returns:
- Grid long list.
- Throws:
IOException- If failed.
-
writeTo
- Parameters:
out- Output to write to.list- List.- Throws:
IOException- If failed.
-
addAll
- Parameters:
to- To list.from- From list.- Returns:
- To list (passed in or created).
-
sort
Sorts this list. Usecopy().sort()if you need a defensive copy.- Returns:
thisFor chaining.
-
pop
public void pop(int cnt) Removes given number of elements from the end. If the given number of elements is higher than list size, then list will be cleared.- Parameters:
cnt- Count to pop from the end.
-