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
`static long[]` `EMPTY_ARRAY` Empty array.

### Fields inherited from interface org.apache.ignite.plugin.extensions.communication.Message

`DIRECT_TYPE_SIZE`

### Constructor Summary

Constructors
`GridLongList()`
`GridLongList​(int size)`
`GridLongList​(long[] arr)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `add​(long x)` Add element to this array.
`void` `addAll​(GridLongList l)`
`long[]` `array()`
`static GridLongList` `asList​(long... vals)`
`void` `clear()` Clears the list.
`boolean` `contains​(long l)`
`GridLongList` `copyWithout​(GridLongList l)` Returns (possibly reordered) copy of this list, excluding all elements of given list.
`short` `directType()` Gets message type.
`boolean` `equals​(Object o)`
`byte` `fieldsCount()` Gets fields count.
`long` `get​(int i)`
`int` `hashCode()`
`boolean` `isEmpty()`
`void` `onAckReceived()` Method called when ack message received.
`void` `readExternal​(ObjectInput in)`
`boolean` `readFrom​(ByteBuffer buf, MessageReader reader)` Reads this message from provided byte buffer.
`long` `remove()` Removes and returns the last element of the list.
`long` `removeIndex​(int i)` Removes element by given index.
`int` `removeValue​(int startIdx, long val)` Removes value from this list.
`int` `size()`
`GridLongList` `sort()` Sorts this list.
`String` `toString()`
`void` `truncate​(int size, boolean last)`
`void` `writeExternal​(ObjectOutput out)`
`boolean` `writeTo​(ByteBuffer buf, MessageWriter writer)` Writes this message to provided byte buffer.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### EMPTY_ARRAY

    public static final long[] EMPTY_ARRAY

Empty array.

### Constructor Detail

#### GridLongList

    public GridLongList()

#### GridLongList

    public GridLongList​(int size)

Parameters:
  `size` - Size.

#### GridLongList

    public GridLongList​(long[] arr)

Parameters:
  `arr` - Array.

### Method Detail

#### asList

    public static GridLongList asList​(long... vals)

Parameters:
  `vals` - Values.
Returns:
  List from values.

#### equals

    public boolean equals​(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### 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 NoSuchElementException

Removes and returns the last element of the list. Complementary method to `add(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:
  `True` if this list has no elements.

#### contains

    public boolean contains​(long l)

Parameters:
  `l` - Element to find.
Returns:
  `True` if found.

#### truncate

    public void truncate​(int size,
                         boolean last)

Parameters:
  `size` - New size.
  `last` - If `true` the 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 `-1` otherwise.

#### array

    public long[] array()

Returns:
  Array copy.

#### writeExternal

    public void writeExternal​(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal​(ObjectInput in)
                      throws IOException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### sort

    public GridLongList sort()

Sorts this list. Use `copy().sort()` if you need a defensive copy.

Returns:
  `this` For chaining.

#### onAckReceived

    public void onAckReceived()

Method called when ack message received.

Specified by:
  `onAckReceived` in interface `Message`

#### writeTo

    public boolean writeTo​(ByteBuffer buf,
                           MessageWriter writer)

Writes this message to provided byte buffer.

Specified by:
  `writeTo` in interface `Message`
Parameters:
  `buf` - Byte buffer.
  `writer` - Writer.
Returns:
  Whether message was fully written.

#### readFrom

    public boolean readFrom​(ByteBuffer buf,
                            MessageReader reader)

Reads this message from provided byte buffer.

Specified by:
  `readFrom` in interface `Message`
Parameters:
  `buf` - Byte buffer.
  `reader` - Reader.
Returns:
  Whether message was fully read.

#### directType

    public short directType()

Gets message type.

Specified by:
  `directType` in interface `Message`
Returns:
  Message type.

#### fieldsCount

    public byte fieldsCount()

Gets fields count.

Specified by:
  `fieldsCount` in interface `Message`
Returns:
  Fields count.