Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-1613

ConstraintStreams: Add collector for toList()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 7.34.0.Final
    • None
    • optaplanner-core
    • None

      This might work:

      public final class ConstraintCollectors {
      
          public static <A> UniConstraintCollector<A, ?, List<A>> toList() {
              return new DefaultUniConstraintCollector<>(
                      () -> new ArrayList<A>(),
                      (resultContainer, a) -> {
                          resultContainer.add(a);
                          return (() -> resultContainer.remove(a));
                      },
                      resultContainer -> resultContainer);
          }
      

      I doubt if the order of the list is stable... but it should be... even incrementally.
      Maybe we should just do a Set instead? But then we'll need to keep track of the number of additions per element.

      PS: we'll also want

       public static <A, Property_> UniConstraintCollector<A, ?, List<Property_>> toList(Function<A,Property_> groupValueMapping)
      

              lpetrovi@redhat.com Lukáš Petrovický (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: