Class ValueRangeCache<Value_>

java.lang.Object
ai.timefold.solver.core.impl.domain.valuerange.ValueRangeCache<Value_>
Type Parameters:
Value_ - the type of the cached values
All Implemented Interfaces:
Iterable<Value_>

@NullMarked public final class ValueRangeCache<Value_> extends Object implements Iterable<Value_>
Instances are usually created using one of the static of(...) factory methods, which control how the underlying collection is initialized. The collection preserves the original insertion order and enables efficient indexed and random access.

When values are added via add(Object), the set is consulted first and the value is only appended to the list if it was not already present in the set.

As a result, the cache never contains duplicate elements according to their equals/hashCode contract.

  • Method Details

    • of

      public static <Value_> ValueRangeCache<Value_> of(int size)
    • of

      public static <Value_> ValueRangeCache<Value_> of(Collection<Value_> collection)
    • of

      public static <Value_> ValueRangeCache<Value_> of(List<Value_> valuesWithFastRandomAccess, Set<Value_> valuesWithFastLookup)
    • add

      public void add(@Nullable Value_ value)
    • get

      public Value_ get(int index)
    • contains

      public boolean contains(@Nullable Value_ value)
    • getSize

      public long getSize()
    • iterator

      public Iterator<Value_> iterator()
      Iterates in original order of the values as provided, terminates when the last value is reached.
      Specified by:
      iterator in interface Iterable<Value_>
    • iterator

      public Iterator<Value_> iterator(Random workingRandom)
      Iterates in random order, does not terminate.
    • sort

      Creates a copy of the cache and apply a sorting operation.
      Parameters:
      sorter - never null, the sorter