Class IntArray

java.lang.Object
org.yamcs.utils.IntArray

public class IntArray extends Object
expandable array of ints
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a sorted int array with a default initial capacity
    IntArray(int capacity)
    Creates an IntArray with a given initial capacity
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int x)
    add value to the array
    void
    add(int pos, int x)
     
    int[]
    get the backing array
    int
    binarySearch(int x)
    Assuming that the array is sorted, performs a binary search and returns the position of the found element.
    static int
    Compares two arrays.
    boolean
     
    int
    get(int pos)
    get element at position
    int
     
    int
    indexOf(int x)
    Returns the index of the first occurrence of the specified element in the array, or -1 if the array does not contain the element.
    int
    return the number of elements of the intersection of the two arrays
    boolean
     
    int
    remove(int pos)
    Remove element at position shifting all subsequent elements to the left
    void
    set(int pos, int x)
     
    int
     
    void
     
    void
    sort(List<?> list)
    Sort the array concurrently swapping the elements in the list such that the correspondence is kept.
     
    int[]
     
     
    static IntArray
    union(IntArray a1, IntArray a2, int sizeHint)
    Assuming that a1 and a2 are sorted, returns a new array storing the union.
    static IntArray
    wrap(int... array)
    Creates the IntArray with the backing array

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • IntArray

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

      public IntArray(int capacity)
      Creates an IntArray with a given initial capacity
      Parameters:
      capacity -
  • Method Details

    • wrap

      public static IntArray wrap(int... array)
      Creates the IntArray with the backing array
      Parameters:
      array -
      Returns:
      a new object containing all the values from the passed array
    • add

      public void add(int x)
      add value to the array
      Parameters:
      x - * - value to be added
    • add

      public void add(int pos, int x)
    • get

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

      public int remove(int pos)
      Remove element at position shifting all subsequent elements to the left
      Parameters:
      pos -
      Returns:
      the element removed
    • stream

      public IntStream stream()
    • isEmpty

      public boolean isEmpty()
    • toArray

      public int[] toArray()
    • size

      public int size()
      Returns:
      the size of the array (which is smaller or equal than the length of the underlying int[] array)
    • set

      public void set(int pos, int x)
    • indexOf

      public int indexOf(int x)
      Returns the index of the first occurrence of the specified element in the array, or -1 if the array does not contain the element.
      Parameters:
      x - element which is searched for
      Returns:
      the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
    • array

      public int[] array()
      get the backing array
      Returns:
      the backing array
    • binarySearch

      public int binarySearch(int x)
      Assuming that the array is sorted, performs a binary search and returns the position of the found element. See Arrays.binarySearch(int[], int) for details. If the array is not sorted, the behaviour is undefined.
      Parameters:
      x - - the value to be searched for
      Returns:
    • intersectionSize

      public int intersectionSize(IntArray input)
      return the number of elements of the intersection of the two arrays

      both this and input have to be sorted

    • union

      public static IntArray union(IntArray a1, IntArray a2, int sizeHint)
      Assuming that a1 and a2 are sorted, returns a new array storing the union.

      sizeHint is the expected size of the returned array

    • sort

      public void sort()
    • sort

      public void sort(List<?> list)
      Sort the array concurrently swapping the elements in the list such that the correspondence is kept. The list has to contain the same number of elements as the array
      Parameters:
      list -
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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

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

      public static int compare(IntArray a1, IntArray a2)
      Compares two arrays. Assuming that the arrays a1 and a2 are sorted, it returns
      • 0 if a1 == a2
      • 1 if a1 is a subset of a2
      • 2 if a2 is a subset of a1
      • -1 otherwise
      If the arrays are not sorted the return is meaningless.
      Parameters:
      a1 - - first array
      a2 - - second array