Class GridLongList

java.lang.Object
org.apache.ignite.internal.util.GridLongList
Direct Known Subclasses:
LongListReuseBag

public class GridLongList extends Object
Minimal list API to work with primitive longs. This list exists to avoid boxing/unboxing when using standard list from Java.
  • Field Details

    • EMPTY_ARRAY

      public static final long[] EMPTY_ARRAY
      Empty 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

      public static GridLongList asList(long... vals)
      Parameters:
      vals - Values.
      Returns:
      List from values.
    • copy

      public GridLongList 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(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.
    • last

      public long last()
      Gets the last element.
      Returns:
      The last element.
    • 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.
    • containsAll

      public boolean containsAll(GridLongList 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 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.
    • 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 -1 otherwise.
    • array

      public long[] array()
      Returns:
      Array copy.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readFrom

      public static GridLongList readFrom(DataInput in) throws IOException
      Parameters:
      in - Input to read list from.
      Returns:
      Grid long list.
      Throws:
      IOException - If failed.
    • writeTo

      public static void writeTo(DataOutput out, GridLongList list) throws IOException
      Parameters:
      out - Output to write to.
      list - List.
      Throws:
      IOException - If failed.
    • addAll

      public static GridLongList addAll(GridLongList to, GridLongList from)
      Parameters:
      to - To list.
      from - From list.
      Returns:
      To list (passed in or created).
    • sort

      public GridLongList 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.