Skip to content

Commit

Permalink
PLANNER-2738 Make FlightAssignment comparator consistent with equals (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo authored Jun 7, 2022
1 parent 710c8e4 commit 020b2bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -26,11 +26,11 @@

public class Flight extends AbstractPersistable implements Comparable<Flight> {

private static final Comparator<Flight> COMPARATOR = Comparator.comparing(Flight::getDepartureUTCDate)
private static final Comparator<Flight> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,9 +25,8 @@
@PlanningEntity
public class FlightAssignment extends AbstractPersistable implements Comparable<FlightAssignment> {

private static final Comparator<FlightAssignment> 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<FlightAssignment> COMPARATOR = Comparator.comparing(FlightAssignment::getFlight)
.thenComparing(FlightAssignment::getIndexInFlight);

private Flight flight;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 020b2bb

Please sign in to comment.