Issue #2468 compare DataTime without Calendar.
Change-Id: I94f5258d04a53ba77c0e0d7af8637d96dd1ecb59 Former-commit-id:88d9dd4a9d
[formerly c988286b20545bbe7e7dab3d717ebd7f78968048] Former-commit-id:27758e3e7f
This commit is contained in:
parent
7defe1efea
commit
7901fd821e
2 changed files with 42 additions and 25 deletions
|
@ -27,7 +27,7 @@ import java.util.Calendar;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.TimeZone;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -58,14 +58,16 @@ import com.raytheon.uf.common.time.util.TimeUtil;
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* SOFTWARE HISTORY
|
* SOFTWARE HISTORY
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ -------- ----------- --------------------------
|
||||||
* Jim Ramer Original Code
|
* Jim Ramer Original Code
|
||||||
* Jun 18, 2007 chammack Partial port to Java
|
* Jun 18, 2007 chammack Partial port to Java
|
||||||
* Apr 12, 2013 1857 bgonzale Added Index annotations to getter
|
* Apr 12, 2013 1857 bgonzale Added Index annotations to getter
|
||||||
* methods.
|
* methods.
|
||||||
* Mar 02, 2013 1970 bgonzale Removed Index annotations.
|
* Mar 02, 2013 1970 bgonzale Removed Index annotations.
|
||||||
* Aug 08, 2013 2245 bsteffen Make all DataTime comparisons consistent.
|
* Aug 08, 2013 2245 bsteffen Make all DataTime comparisons consistent.
|
||||||
|
* Oct 14, 2013 2468 bsteffen Add getValidTimeAsDate() for comparison
|
||||||
|
* performance.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -126,6 +128,19 @@ public class DataTime implements Comparable<DataTime>, Serializable,
|
||||||
private static final Comparator<DataTime> DEFAULT_COMPARATOR = new DataTimeComparator(
|
private static final Comparator<DataTime> DEFAULT_COMPARATOR = new DataTimeComparator(
|
||||||
SortKey.VALID_TIME, SortKey.FORECAST_TIME, false);
|
SortKey.VALID_TIME, SortKey.FORECAST_TIME, false);
|
||||||
|
|
||||||
|
/** Data format flag */
|
||||||
|
private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SimpleDateFormat initialValue() {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(
|
||||||
|
"EEE HH:mm'Z' dd-MMM-yy");
|
||||||
|
sdf.setTimeZone(TimeUtil.GMT_TIME_ZONE);
|
||||||
|
return sdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/** The reference time */
|
/** The reference time */
|
||||||
@Column(name = "refTime")
|
@Column(name = "refTime")
|
||||||
@DynamicSerializeElement
|
@DynamicSerializeElement
|
||||||
|
@ -152,10 +167,6 @@ public class DataTime implements Comparable<DataTime>, Serializable,
|
||||||
NO_VALID_PERIOD, FCST_USED, PERIOD_USED
|
NO_VALID_PERIOD, FCST_USED, PERIOD_USED
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data format flag */
|
|
||||||
private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
|
|
||||||
"EEE HH:mm'Z' dd-MMM-yy");
|
|
||||||
|
|
||||||
/** The set of flags set on the time */
|
/** The set of flags set on the time */
|
||||||
@Column
|
@Column
|
||||||
@Type(type = "com.raytheon.edex.db.mapping.DataTimeFlagType")
|
@Type(type = "com.raytheon.edex.db.mapping.DataTimeFlagType")
|
||||||
|
@ -344,7 +355,7 @@ public class DataTime implements Comparable<DataTime>, Serializable,
|
||||||
* @return the refTime
|
* @return the refTime
|
||||||
*/
|
*/
|
||||||
public Calendar getRefTimeAsCalendar() {
|
public Calendar getRefTimeAsCalendar() {
|
||||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
Calendar cal = new GregorianCalendar(TimeUtil.GMT_TIME_ZONE);
|
||||||
cal.setTime(this.refTime);
|
cal.setTime(this.refTime);
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
@ -368,12 +379,18 @@ public class DataTime implements Comparable<DataTime>, Serializable,
|
||||||
* @return the valid time
|
* @return the valid time
|
||||||
*/
|
*/
|
||||||
public Calendar getValidTime() {
|
public Calendar getValidTime() {
|
||||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
Calendar cal = new GregorianCalendar(TimeUtil.GMT_TIME_ZONE);
|
||||||
cal.setTimeInMillis(refTime.getTime() + (1000 * ((long) fcstTime)));
|
cal.setTime(getValidTimeAsDate());
|
||||||
|
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the valid time
|
||||||
|
*/
|
||||||
|
public Date getValidTimeAsDate() {
|
||||||
|
return new Date(refTime.getTime() + (1000 * ((long) fcstTime)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a time matching forecast time in seconds
|
* @return a time matching forecast time in seconds
|
||||||
*/
|
*/
|
||||||
|
@ -496,7 +513,7 @@ public class DataTime implements Comparable<DataTime>, Serializable,
|
||||||
if (fcstTime > 0 || utilityFlags.contains(FLAG.FCST_USED)) {
|
if (fcstTime > 0 || utilityFlags.contains(FLAG.FCST_USED)) {
|
||||||
|
|
||||||
long fcstTimeInSec = fcstTime;
|
long fcstTimeInSec = fcstTime;
|
||||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
Calendar cal = new GregorianCalendar(TimeUtil.GMT_TIME_ZONE);
|
||||||
cal.setTime(this.refTime);
|
cal.setTime(this.refTime);
|
||||||
String day = nf.format(cal.get(Calendar.DAY_OF_MONTH));
|
String day = nf.format(cal.get(Calendar.DAY_OF_MONTH));
|
||||||
String hour = nf.format(cal.get(Calendar.HOUR_OF_DAY));
|
String hour = nf.format(cal.get(Calendar.HOUR_OF_DAY));
|
||||||
|
@ -539,8 +556,7 @@ public class DataTime implements Comparable<DataTime>, Serializable,
|
||||||
legendBuffer.append("Incl ");
|
legendBuffer.append("Incl ");
|
||||||
}
|
}
|
||||||
|
|
||||||
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
|
legendBuffer.append(DATE_FORMAT.get().format(validTime));
|
||||||
legendBuffer.append(DATE_FORMAT.format(validTime));
|
|
||||||
|
|
||||||
this.legend = legendBuffer.toString();
|
this.legend = legendBuffer.toString();
|
||||||
return this.legend;
|
return this.legend;
|
||||||
|
|
|
@ -30,9 +30,10 @@ import java.util.Comparator;
|
||||||
*
|
*
|
||||||
* SOFTWARE HISTORY
|
* SOFTWARE HISTORY
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------- -------- ----------- --------------------------
|
||||||
* Aug 8, 2013 2245 bsteffen Initial creation
|
* Aug 08, 2013 2245 bsteffen Initial creation
|
||||||
|
* Oct 14, 2013 2468 bsteffen Use Date for validTime comparisons.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -109,8 +110,8 @@ public class DataTimeComparator implements Comparator<DataTime> {
|
||||||
case FORECAST_TIME:
|
case FORECAST_TIME:
|
||||||
return integerCompare(time1.getFcstTime(), time2.getFcstTime());
|
return integerCompare(time1.getFcstTime(), time2.getFcstTime());
|
||||||
case VALID_TIME:
|
case VALID_TIME:
|
||||||
return longCompare(time1.getValidTime().getTimeInMillis(), time2
|
return longCompare(time1.getValidTimeAsDate().getTime(), time2
|
||||||
.getValidTime().getTimeInMillis());
|
.getValidTimeAsDate().getTime());
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException(String.valueOf(sortKey)
|
throw new IllegalArgumentException(String.valueOf(sortKey)
|
||||||
+ " is not a recognized SortKey.");
|
+ " is not a recognized SortKey.");
|
||||||
|
|
Loading…
Add table
Reference in a new issue