org.opentcs.util.Comparators Maven / Gradle / Ivy
/**
* Copyright (c) The openTCS Authors.
*
* This program is free software and subject to the MIT license. (For details,
* see the licensing information (LICENSE.txt) you should have received with
* this copy of the software.)
*/
package org.opentcs.util;
import java.util.Comparator;
import org.opentcs.data.TCSObject;
import org.opentcs.data.TCSObjectReference;
import org.opentcs.data.order.TransportOrder;
import org.opentcs.data.peripherals.PeripheralJob;
/**
* Some commonly used comparator implementations.
*/
public final class Comparators {
/**
* Prevents undesired instantiation.
*/
private Comparators() {
}
/**
* Returns a comparator for sorting TCSObject
s lexicographically by their names.
*
* @return A comparator for sorting TCSObject
s lexicographically by their names.
*/
public static Comparator> objectsByName() {
return Comparator.comparing(TCSObject::getName);
}
/**
* Returns a comparator for sorting TCSObjectReference
s lexicographically by their
* names.
*
* @return A comparator for sorting TCSObjectReference
s lexicographically by their
* names.
*/
public static Comparator> referencesByName() {
return Comparator.comparing(TCSObjectReference::getName);
}
/**
* A comparator for sorting transport orders by their deadlines, with the most urgent ones coming
* first.
* Transport orders are sorted by their deadlines first; if two orders have exactly the same
* deadline, they are sorted by their (unique) creation times, with the older one coming first.
*
* @return A comparator for sorting transport orders by their deadlines.
*/
public static Comparator ordersByDeadline() {
return Comparator.comparing(TransportOrder::getDeadline).thenComparing(ordersByAge());
}
/**
* A comparator for sorting transport orders by their age, with the oldest ones coming first.
*
* @return A comparator for sorting transport orders by their age.
*/
public static Comparator ordersByAge() {
return Comparator.comparing(TransportOrder::getCreationTime).thenComparing(objectsByName());
}
/**
* A comparator for sorting peripheral jobs by their age, with the oldest ones coming first.
*
* @return A comparator for sorting peripheral jobs by their age.
*/
public static Comparator jobsByAge() {
return Comparator.comparing(PeripheralJob::getCreationTime).thenComparing(objectsByName());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy