Package com.hexaly.optimizer
Class HxCollection
- java.lang.Object
-
- com.hexaly.optimizer.HxCollection
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Long>
public class HxCollection extends java.lang.Object implements java.lang.Iterable<java.lang.Long>Value type for collection expressions (lists or sets). Such value is obtained withHxExpression.getCollectionValue()orHxSolution.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:
HxModel,HxExpression
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long val)Adds the given value 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.booleanequals(java.lang.Object obj)longget(int position)Gets the value at the given position.inthashCode()booleanisUndefined()Returns true if the collection is undefined.java.util.Iterator<java.lang.Long>iterator()Returns an iterator for the content of this collection.java.lang.StringtoString()Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }"
-
-
-
Method Detail
-
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 of the range of the list or if this value is already included in this list (keep in mind that a list cannot contain twice the same value).- Parameters:
val- The value 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
-
isUndefined
public boolean isUndefined()
Returns true if the collection is undefined. A collection can be undefined if it is the result of any ill-defined operation (at with out of bounds index or operations on undefined values for instance).- Returns:
- True if the collection is undefined.
-
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
public java.lang.String toString()
Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }"- Overrides:
toStringin classjava.lang.Object- Returns:
- String representation.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
iterator
public java.util.Iterator<java.lang.Long> iterator()
Returns an iterator for the content of this collection.- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Long>- Returns:
- Read-only iterator for the content of this collection.
-
-