From 67c84f2fb8cabf6148d3223cf9cb57c958a3bc72 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Mon, 12 Aug 2013 13:43:13 -0500 Subject: [PATCH] Issue #2245 make DataTimeCompatible Java 6 compatible. Former-commit-id: e32655d3daef131c451d972c7b2747b01e49d840 --- .../uf/common/time/DataTimeComparator.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/DataTimeComparator.java b/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/DataTimeComparator.java index b4f167de46..bfd3fa53da 100644 --- a/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/DataTimeComparator.java +++ b/edexOsgi/com.raytheon.uf.common.time/src/com/raytheon/uf/common/time/DataTimeComparator.java @@ -104,12 +104,12 @@ public class DataTimeComparator implements Comparator { private int compareNoMatch(SortKey sortKey, DataTime time1, DataTime time2) { switch (sortKey) { case INITIAL_TIME: - return Long.compare(time1.getRefTime().getTime(), time2 + return longCompare(time1.getRefTime().getTime(), time2 .getRefTime().getTime()); case FORECAST_TIME: - return Integer.compare(time1.getFcstTime(), time2.getFcstTime()); + return integerCompare(time1.getFcstTime(), time2.getFcstTime()); case VALID_TIME: - return Long.compare(time1.getValidTime().getTimeInMillis(), time2 + return longCompare(time1.getValidTime().getTimeInMillis(), time2 .getValidTime().getTimeInMillis()); default: throw new IllegalArgumentException(String.valueOf(sortKey) @@ -120,11 +120,11 @@ public class DataTimeComparator implements Comparator { private int compareMatch(SortKey sortKey, DataTime time1, DataTime time2) { switch (sortKey) { case INITIAL_TIME: - return Long.compare(time1.getMatchRef(), time2.getMatchRef()); + return longCompare(time1.getMatchRef(), time2.getMatchRef()); case FORECAST_TIME: - return Long.compare(time1.getMatchFcst(), time2.getMatchFcst()); + return longCompare(time1.getMatchFcst(), time2.getMatchFcst()); case VALID_TIME: - return Long.compare(time1.getMatchValid(), time2.getMatchValid()); + return longCompare(time1.getMatchValid(), time2.getMatchValid()); default: throw new IllegalArgumentException(String.valueOf(sortKey) + " is not a recognized SortKey."); @@ -155,11 +155,26 @@ public class DataTimeComparator implements Comparator { return 1; } - int result = Long.compare(p1.getDuration(), p2.getDuration()); + int result = longCompare(p1.getDuration(), p2.getDuration()); if (result != 0) { return result; } - return Long.compare(p1.getStart().getTime(), p2.getStart().getTime()); + return longCompare(p1.getStart().getTime(), p2.getStart().getTime()); } + /** + * For compatibility with Java 6 use this instead of Integer.compare. + */ + private int integerCompare(int x, int y) { + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + + /** + * For compatibility with Java 6 use this instead of Long.compare. + */ + private int longCompare(long x, long y) { + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + + }