Package org.yamcs.utils
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CAPACITY
-
Constructor Summary
Constructors Constructor Description SortedIntArray()
Creates 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 them
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int x)
Change the elements of the array by adding x to each elementboolean
contains(int x)
Performs a binary search and returns true if this array contains the value.static SortedIntArray
decodeFromVarIntArray(byte[] buf)
boolean
equals(Object obj)
void
forEach(IntConsumer action)
int
get(int pos)
get element at positionint[]
getArray()
PrimitiveIterator.OfInt
getAscendingIterator(int startFrom)
Constructs an ascending iterator starting from a specified value (inclusive)PrimitiveIterator.OfInt
getDescendingIterator(int startFrom)
Constructs an descending iterator starting from a specified value (exclusive)int
hashCode()
int
insert(int x)
Inserts value to the array and return the position on which has been insertedboolean
isEmpty()
int
search(int x)
performs a binary search in the array.int
size()
String
toString()
-
-
-
Constructor Detail
-
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
-
-
-
Method Detail
-
insert
public int insert(int x)
Inserts value to the array and return the position on which has been inserted- 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:
Arrays.binarySearch(int[], int)
-
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)
-
add
public void add(int x)
Change the elements of the array by adding x to each element- Parameters:
x
-
-
-