
org.opentripplanner.routing.util.DiffEntry Maven / Gradle / Ivy
The newest version!
package org.opentripplanner.routing.util;
public record DiffEntry(T left, T right) {
/**
* Return the left instance if it exist, if not return the right instance. If both exist(left
* equals right) then left is returned.
*/
public T element() {
return rightOnly() ? right : left;
}
/* The element exist in the left collection, not in the right. */
public boolean leftOnly() {
return right == null;
}
/* The element exist in the right collection, not in the left. */
public boolean rightOnly() {
return left == null;
}
/* The element exist in both collections. Element left equals the right instance. */
public boolean isEqual() {
return left != null && right != null;
}
/**
* Return a status message based on the element existence: - exist in left and right collection -
* exist left only - or, exist right only
*/
public String status(String equal, String left, String right) {
return leftOnly() ? left : (rightOnly() ? right : equal);
}
@Override
public String toString() {
if (isEqual()) return "(eq: " + element() + ")";
if (leftOnly()) return "(left: " + left + ")";
return "(right: " + right + ")";
}
static DiffEntry ofLeft(T left) {
return new DiffEntry(left, null);
}
static DiffEntry ofRight(T right) {
return new DiffEntry(null, right);
}
static DiffEntry ofEqual(T left, T right) {
return new DiffEntry(left, right);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy