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

ConstraintStreams: Add collector for toList()

    XMLWordPrintable

Details

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

    Description

      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)
      

      Attachments

        Issue Links

          Activity

            People

              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

              Dates

                Created:
                Updated:
                Resolved: