Class HxCollection

java.lang.Object
com.hexaly.optimizer.HxCollection
All Implemented Interfaces:
Iterable<Long>

public class HxCollection extends Object implements Iterable<Long>
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 Type
    Method
    Description
    void
    add(long val)
    Adds the given value to this collection.
    void
    addAll(long[] values)
    Adds the given values to this collection.
    void
    Removes all values of this collection.
    boolean
    contains(long value)
    Returns true if the collection contains the given value, false otherwise.
    void
    copyTo(long[] values)
    Copy all the values of the collection to the given array.
    int
    Returns the number of values in the collection.
    boolean
     
    long
    get(int position)
    Gets the value at the given position.
    int
     
    Returns an iterator for the content of this collection.
    Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }"

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait

    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 state HxState.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 state HxState.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 state HxState.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

      public String toString()
      Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }"
      Overrides:
      toString in class Object
      Returns:
      String representation.
    • hashCode

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

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

      public Iterator<Long> iterator()
      Returns an iterator for the content of this collection.
      Specified by:
      iterator in interface Iterable<Long>
      Returns:
      Read-only iterator for the content of this collection.