Class SortedIntArray

java.lang.Object
org.yamcs.utils.SortedIntArray
All Implemented Interfaces:
Serializable

public class SortedIntArray extends Object implements Serializable
sorted int array
See Also:
  • Field Details

    • DEFAULT_CAPACITY

      public static int DEFAULT_CAPACITY
  • Constructor Details

    • SortedIntArray

      public SortedIntArray()
      Creates a sorted int array with a default initial capacity
    • SortedIntArray

      public SortedIntArray(int capacity)
      Creates a sorted int array with a given initial capacity
      Parameters:
      capacity -
    • SortedIntArray

      public SortedIntArray(int... array)
      Creates the SortedIntArray by copying all values from the input array and sorting them
      Parameters:
      array -
    • SortedIntArray

      public SortedIntArray(IntArray pids)
  • Method Details

    • insert

      public int insert(int x)
      Inserts value to the array and return the position on which has been inserted.

      In case x is already present in the array, this function inserts the new value at a position after the values already present

      Parameters:
      x - - value to be inserted
      Returns:
      the position on which the value has been inserted
    • search

      public int search(int x)
      performs a binary search in the array.
      Parameters:
      x -
      Returns:
      result of the binarySearch, @see java.util.Arrays#binarySearch(int[], int)
      See Also:
    • get

      public int get(int pos)
      get element at position
      Parameters:
      pos -
      Returns:
      the element at position
    • isEmpty

      public boolean isEmpty()
    • getArray

      public int[] getArray()
    • size

      public int size()
    • getAscendingIterator

      public PrimitiveIterator.OfInt getAscendingIterator(int startFrom)
      Constructs an ascending iterator starting from a specified value (inclusive)
      Parameters:
      startFrom -
      Returns:
      an iterator starting from the specified value
    • getDescendingIterator

      public PrimitiveIterator.OfInt getDescendingIterator(int startFrom)
      Constructs an descending iterator starting from a specified value (exclusive)
      Parameters:
      startFrom -
      Returns:
      an descending iterator starting from the specified value
    • forEach

      public void forEach(IntConsumer action)
    • contains

      public boolean contains(int x)
      Performs a binary search and returns true if this array contains the value.
      Parameters:
      x - - value to check
      Returns:
      true of the array contains the specified value
    • decodeFromVarIntArray

      public static SortedIntArray decodeFromVarIntArray(byte[] buf)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • addToAll

      public void addToAll(int x)
      Change the elements of the array by adding x to each element
    • addIfGreaterThan

      public void addIfGreaterThan(int v, int x)
      Add x to the elements of the array whose value is greater than v
    • toString

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

      public int hashCode()
      Overrides:
      hashCode in class Object