java.lang.Object
org.yamcs.utils.SortedIntArray
- All Implemented Interfaces:
Serializable
sorted int array
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a sorted int array with a default initial capacitySortedIntArray(int capacity) Creates a sorted int array with a given initial capacitySortedIntArray(int... array) Creates the SortedIntArray by copying all values from the input array and sorting themSortedIntArray(IntArray pids) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int x) Change the elements of the array by adding x to each elementbooleancontains(int x) Performs a binary search and returns true if this array contains the value.static SortedIntArraydecodeFromVarIntArray(byte[] buf) booleanvoidforEach(IntConsumer action) intget(int pos) get element at positionint[]getArray()getAscendingIterator(int startFrom) Constructs an ascending iterator starting from a specified value (inclusive)getDescendingIterator(int startFrom) Constructs an descending iterator starting from a specified value (exclusive)inthashCode()intinsert(int x) Inserts value to the array and return the position on which has been inserted.booleanisEmpty()intsearch(int x) performs a binary search in the array.intsize()toString()
-
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
-
-
Method Details
-
insert
public int insert(int x) Inserts value to the array and return the position on which has been inserted.In case
xis 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
Constructs an ascending iterator starting from a specified value (inclusive)- Parameters:
startFrom-- Returns:
- an iterator starting from the specified value
-
getDescendingIterator
Constructs an descending iterator starting from a specified value (exclusive)- Parameters:
startFrom-- Returns:
- an descending iterator starting from the specified value
-
forEach
-
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
-
equals
-
add
public void add(int x) Change the elements of the array by adding x to each element- Parameters:
x-
-
toString
-
hashCode
public int hashCode()
-