Package org.apache.ignite.internal.util
Class GridLongList
- java.lang.Object
-
- org.apache.ignite.internal.util.GridLongList
-
- All Implemented Interfaces:
Externalizable,Serializable,Message
- Direct Known Subclasses:
LongListReuseBag
public class GridLongList extends Object implements Message, Externalizable
Minimal list API to work with primitive longs. This list exists to avoid boxing/unboxing when using standard list from Java.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static long[]EMPTY_ARRAYEmpty array.-
Fields inherited from interface org.apache.ignite.plugin.extensions.communication.Message
DIRECT_TYPE_SIZE
-
-
Constructor Summary
Constructors Constructor Description GridLongList()GridLongList(int size)GridLongList(long[] arr)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long x)Add element to this array.voidaddAll(GridLongList l)long[]array()static GridLongListasList(long... vals)voidclear()Clears the list.booleancontains(long l)GridLongListcopyWithout(GridLongList l)Returns (possibly reordered) copy of this list, excluding all elements of given list.shortdirectType()Gets message type.booleanequals(Object o)bytefieldsCount()Gets fields count.longget(int i)inthashCode()booleanisEmpty()voidonAckReceived()Method called when ack message received.voidreadExternal(ObjectInput in)booleanreadFrom(ByteBuffer buf, MessageReader reader)Reads this message from provided byte buffer.longremove()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.intsize()GridLongListsort()Sorts this list.StringtoString()voidtruncate(int size, boolean last)voidwriteExternal(ObjectOutput out)booleanwriteTo(ByteBuffer buf, MessageWriter writer)Writes this message to provided byte buffer.
-
-
-
Method Detail
-
asList
public static GridLongList asList(long... vals)
- Parameters:
vals- Values.- Returns:
- List from values.
-
addAll
public void addAll(GridLongList l)
- 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.
-
remove
public long remove() throws NoSuchElementExceptionRemoves 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
public GridLongList copyWithout(GridLongList l)
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.
-
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.
-
array
public long[] array()
- Returns:
- Array copy.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOException
-
sort
public GridLongList sort()
Sorts this list. Usecopy().sort()if you need a defensive copy.- Returns:
thisFor chaining.
-
onAckReceived
public void onAckReceived()
Method called when ack message received.- Specified by:
onAckReceivedin interfaceMessage
-
writeTo
public boolean writeTo(ByteBuffer buf, MessageWriter writer)
Writes this message to provided byte buffer.
-
readFrom
public boolean readFrom(ByteBuffer buf, MessageReader reader)
Reads this message from provided byte buffer.
-
directType
public short directType()
Gets message type.- Specified by:
directTypein interfaceMessage- Returns:
- Message type.
-
fieldsCount
public byte fieldsCount()
Gets fields count.- Specified by:
fieldsCountin interfaceMessage- Returns:
- Fields count.
-
-