Package localsolver

Class LSCollection

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Long>

    public class LSCollection
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.Long>
    Value type for collection expressions (lists or sets). Such value is obtained with LSExpression.getCollectionValue() or LSSolution.getCollectionValue(LSExpression). It represents a reference to the value of a variable and the value of this variable is modified when the LSCollection object is modified.
    Since:
    5.5
    See Also:
    LSModel, LSExpression
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long val)
      Adds the given value to this collection.
      void clear()
      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 count()
      Returns the number of values in the collection.
      boolean equals​(java.lang.Object obj)  
      long get​(int position)
      Gets the value at the given position.
      int hashCode()  
      java.util.Iterator<java.lang.Long> iterator()
      Returns an iterator for the content of this collection.
      java.lang.String toString()
      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 Detail

      • add

        public void add​(long val)
        Adds the given value to this collection. Only allowed in state LSState.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 state LSState.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 java.lang.String toString()
        Returns a string representation of the values in the collection in the format "{ val0, val1, ..., valN }"
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation.
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • iterator

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