From 020b2bbcbb27407b91e0524843e3fffa1d35dbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Petrovick=C3=BD?= Date: Tue, 7 Jun 2022 14:39:26 +0200 Subject: [PATCH] PLANNER-2738 Make FlightAssignment comparator consistent with equals (#2019) --- .../examples/flightcrewscheduling/domain/Flight.java | 8 ++++---- .../flightcrewscheduling/domain/FlightAssignment.java | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/Flight.java b/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/Flight.java index 23cdff3c061..89de59e9201 100644 --- a/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/Flight.java +++ b/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/Flight.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * Copyright 2022 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,11 +26,11 @@ public class Flight extends AbstractPersistable implements Comparable { - private static final Comparator COMPARATOR = Comparator.comparing(Flight::getDepartureUTCDate) + private static final Comparator COMPARATOR = Comparator.comparing(Flight::getDepartureUTCDateTime) .thenComparing(Flight::getDepartureAirport) - .thenComparing(Flight::getDepartureUTCDateTime) + .thenComparing(Flight::getArrivalUTCDateTime) .thenComparing(Flight::getArrivalAirport) - .thenComparing(Flight::getArrivalUTCDateTime); + .thenComparing(Flight::getFlightNumber); private String flightNumber; private Airport departureAirport; diff --git a/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/FlightAssignment.java b/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/FlightAssignment.java index 2a80574fa44..a065cfc349f 100644 --- a/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/FlightAssignment.java +++ b/optaplanner-examples/src/main/java/org/optaplanner/examples/flightcrewscheduling/domain/FlightAssignment.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Red Hat, Inc. and/or its affiliates. + * Copyright 2022 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,8 @@ @PlanningEntity public class FlightAssignment extends AbstractPersistable implements Comparable { - private static final Comparator PILLAR_SEQUENCE_COMPARATOR = Comparator - .comparing((FlightAssignment a) -> a.getFlight().getDepartureUTCDateTime()) - .thenComparing(a -> a.getFlight().getArrivalUTCDateTime()) + // Needs to be kept consistent with equals on account of Employee's flightAssignmentSet, which is a SortedSet. + private static final Comparator COMPARATOR = Comparator.comparing(FlightAssignment::getFlight) .thenComparing(FlightAssignment::getIndexInFlight); private Flight flight; @@ -87,6 +86,6 @@ public void setEmployee(Employee employee) { @Override public int compareTo(FlightAssignment o) { - return PILLAR_SEQUENCE_COMPARATOR.compare(this, o); + return COMPARATOR.compare(this, o); } }