org.apache.ignite.internal.util

## Class GridIntList

- java.lang.Object
- - org.apache.ignite.internal.util.GridIntList

All Implemented Interfaces:
  Externalizable, Serializable, Message

    public class GridIntList
    extends Object
    implements Message, Externalizable

Minimal list API to work with primitive ints. This list exists to avoid boxing/unboxing when using standard list from Java.

See Also:
  Serialized Form

### Field Summary

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

`DIRECT_TYPE_SIZE`

### Constructor Summary

Constructors
Constructor and Description
`GridIntList()`
`GridIntList(int size)`
`GridIntList(int[] arr)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `add(int x)` Add element to this array.
`void` `addAll(GridIntList l)`
`static GridIntList` `addAll(GridIntList to, GridIntList from)`
`int[]` `array()`
`static GridIntList` `asList(int... vals)`
`void` `clear()` Clears the list.
`boolean` `contains(int l)`
`boolean` `containsAll(GridIntList l)`
`GridIntList` `copy()`
`GridIntList` `copyWithout(GridIntList l)` Returns (possibly reordered) copy of this list, excluding all elements of given list.
`short` `directType()` Gets message type.
`boolean` `distinct()`
`boolean` `equals(Object o)`
`byte` `fieldsCount()` Gets fields count.
`int` `get(int i)`
`int` `hashCode()`
`boolean` `isEmpty()`
`GridIntIterator` `iterator()`
`int` `last()` Gets the last element.
`void` `onAckReceived()` Method called when ack message received.
`void` `pop(int cnt)` Removes given number of elements from the end.
`void` `readExternal(ObjectInput in)`
`boolean` `readFrom(ByteBuffer buf, MessageReader reader)` Reads this message from provided byte buffer.
`static GridIntList` `readFrom(DataInput in)`
`int` `remove()` Removes and returns the last element of the list.
`int` `removeIndex(int i)` Removes element by given index.
`int` `removeValue(int startIdx, int val)` Removes value from this list.
`int` `replaceValue(int startIdx, int oldVal, int newVal)` Removes value from this list.
`int` `size()`
`GridIntList` `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.
`static void` `writeTo(DataOutput out, GridIntList list)`

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

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

### Constructor Detail

#### GridIntList

    public GridIntList()

#### GridIntList

    public GridIntList(int size)

Parameters:
  `size` - Size.

#### GridIntList

    public GridIntList(int[] arr)

Parameters:
  `arr` - Array.

### Method Detail

#### asList

    public static GridIntList asList(int... vals)

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

#### copy

    public GridIntList copy()

Returns:
  Copy of this list.

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### addAll

    public void addAll(GridIntList l)

Parameters:
  `l` - List to add all elements of.

#### add

    public void add(int x)

Add element to this array.

Parameters:
  `x` - Value.

#### clear

    public void clear()

Clears the list.

#### last

    public int last()

Gets the last element.

Returns:
  The last element.

#### remove

    public int remove()
               throws NoSuchElementException

Removes and returns the last element of the list. Complementary method to `add(int)` for stack like usage.

Returns:
  Removed element.
Throws:
  `NoSuchElementException` - If the list is empty.

#### copyWithout

    public GridIntList copyWithout(GridIntList 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 int 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(int l)

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

#### containsAll

    public boolean containsAll(GridIntList l)

Parameters:
  `l` - List to check.
Returns:
  `True` if this list contains all the elements of passed in list.

#### distinct

    public boolean distinct()

Returns:
  `True` if there are no duplicates.

#### 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 int removeIndex(int i)

Removes element by given index.

Parameters:
  `i` - Index.
Returns:
  Removed value.

#### removeValue

    public int removeValue(int startIdx,
                           int 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.

#### replaceValue

    public int replaceValue(int startIdx,
                            int oldVal,
                            int 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 `-1` otherwise.

#### array

    public int[] 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,
                             ClassNotFoundException

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

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### readFrom

    @Nullable
    public static GridIntList readFrom(DataInput in)
                                          throws IOException

Parameters:
  `in` - Input to read list from.
Returns:
  Grid int list.
Throws:
  `IOException` - If failed.

#### writeTo

    public static void writeTo(DataOutput out,
                               @Nullable
                               GridIntList list)
                        throws IOException

Parameters:
  `out` - Output to write to.
  `list` - List.
Throws:
  `IOException` - If failed.

#### addAll

    public static GridIntList addAll(@Nullable
                                     GridIntList to,
                                     GridIntList from)

Parameters:
  `to` - To list.
  `from` - From list.
Returns:
  To list (passed in or created).

#### sort

    public GridIntList sort()

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

Returns:
  `this` For 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.

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

#### iterator

    public GridIntIterator iterator()

Returns:
  Iterator.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.5.0
Release Date | : May 23 2018