Package com.hexaly.optimizer
Class HxCollection
java.lang.Object
com.hexaly.optimizer.HxCollection
Value type for collection expressions (lists or sets). Such value is obtained
with
HxExpression.getCollectionValue() or HxSolution.getCollectionValue(HxExpression).
It represents a reference to the value of a variable and the value of this variable
is modified when the HxCollection object is modified.- Since:
- 5.5
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long val) Adds the given value to this collection.voidaddAll(long[] values) Adds the given values to this collection.voidclear()Removes all values of this collection.booleancontains(long value) Returns true if the collection contains the given value, false otherwise.voidcopyTo(long[] values) Copy all the values of the collection to the given array.intcount()Returns the number of values in the collection.booleanlongget(int position) Gets the value at the given position.inthashCode()iterator()Returns an iterator for the content of this collection.toString()Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }"Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
add
public void add(long val) Adds the given value to this collection. Only allowed in stateHxState.Stopped. This function will fail if the given value is outside the range of the list/set or if this value is already included in this list/set (keep in mind that a list or a set cannot contain twice the same value).- Parameters:
val- The value to be added.
-
addAll
public void addAll(long[] values) Adds the given values to this collection. Only allowed in stateHxState.Stopped. This function will fail if any given value is outside the range of the list/set or is already included in this list/set (keep in mind that a list or a set cannot contain twice the same value).- Parameters:
values- An array of values to be added.
-
clear
public void clear()Removes all values of this collection. Only allowed in stateHxState.Stopped. -
count
public int count()Returns the number of values in the collection. Values in collections are indexed from 0 to count()-1.- Returns:
- Number of values in the collection.
-
get
public long get(int position) Gets the value at the given position.- Parameters:
position- The considered position (must be non negative and strictly smaller than the number of values in the collection).- Returns:
- The value at the given position.
-
contains
public boolean contains(long value) Returns true if the collection contains the given value, false otherwise.- Parameters:
value- Element whose presence in this collection is to be tested.- Returns:
- True if the collection contains the value
-
copyTo
public void copyTo(long[] values) Copy all the values of the collection to the given array.
The length of the array can be different from the number of elements in the collection. In that case, only the elements that fit in the array are copied.
This method is recommended if you need to access all the values of the collection, instead of the roughly equivalent, but less performant, following code:
for(int i = 0; i < Math.min(values.length, collection.count()); ++i) { values[i] = collection.get(i); }- Parameters:
values- array that will receive the values of the collection.
-
toString
Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }" -
hashCode
public int hashCode() -
equals
-
iterator
Returns an iterator for the content of this collection.
-