Merge "Issue #1286 Fix bugs found during 1286 testing" into 13.2.1_delivery

Former-commit-id: e2516f60d0748830d5849f42819e2dcc66b67bb6
This commit is contained in:
Richard Peter 2013-01-15 15:37:42 -06:00 committed by Gerrit Code Review
commit c8d963d541
43 changed files with 2932 additions and 171 deletions

View file

@ -100,6 +100,8 @@ import com.raytheon.viz.ui.presenter.components.WidgetConf;
* Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion.
* Jan 04, 2012 1420 mpduff Add Latency to PriorityComp.
* Jan 11, 2013 1453 djohnson Sets cycle times on construction.
* Jan 14, 2013 1286 djohnson Check that message to display is not null or empty, and
* only send notification of subscription creation on OK status.
* </pre>
*
* @author mpduff
@ -557,17 +559,21 @@ public class CreateSubscriptionDlgPresenter {
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
subscriptionNotificationService
.sendCreatedSubscriptionNotification(
subscription, username);
final IStatus status = event.getResult();
if (status.getMessage() != null) {
final boolean subscriptionCreated = status.isOK();
if (subscriptionCreated) {
sendSubscriptionNotification(subscription,
username);
}
if (!Strings.isNullOrEmpty(status.getMessage())) {
guiThreadTaskExecutor.runAsync(new Runnable() {
@Override
public void run() {
if (!view.isDisposed()) {
if (status.isOK()) {
if (subscriptionCreated) {
view.displayPopup(
CREATED_TITLE,
status.getMessage());

View file

@ -19,8 +19,12 @@
**/
package com.raytheon.uf.viz.datadelivery.subscription.xml;
import java.util.Collections;
import java.util.Map;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.google.common.collect.Maps;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
@ -35,7 +39,8 @@ import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 1420 mpduff Initial creation.
* Jan 07, 2013 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Add static versions of the conversion methods.
*
* </pre>
*
@ -44,32 +49,61 @@ import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
*/
public class OperatorAdapter extends XmlAdapter<String, Operator<?>> {
@Override
public Operator<?> unmarshal(String v) throws Exception {
for (OperatorTypes ot : OperatorTypes.values()) {
if (ot.toString().equals(v)) {
return ot;
}
}
for (NameOperationItems noi : NameOperationItems.values()) {
if (noi.toString().equals(v)) {
return noi;
}
private static final Map<String, Operator<?>> OPERATOR_MAP;
static {
Map<String, Operator<?>> map = Maps.newHashMap();
for (Operator<?> operator : NameOperationItems.values()) {
map.put(toString(operator), operator);
}
for (TypeOperationItems toi : TypeOperationItems.values()) {
if (toi.toString().equals(v)) {
return toi;
}
for (Operator<?> operator : OperatorTypes.values()) {
map.put(toString(operator), operator);
}
return null;
for (Operator<?> operator : TypeOperationItems.values()) {
map.put(toString(operator), operator);
}
OPERATOR_MAP = Collections.unmodifiableMap(map);
}
/**
*
* {@inheritDoc}
*/
@Override
public Operator<?> unmarshal(String v) throws Exception {
return fromString(v);
}
/**
*
* {@inheritDoc}
*/
@Override
public String marshal(Operator<?> v) throws Exception {
return v.toString();
return toString(v);
}
/**
* Retrieve an {@link Operator} from its {@link String} representation.
*
* @param asString
* the string representation
* @return
*/
public static Operator<?> fromString(String asString) {
return OPERATOR_MAP.get(asString);
}
/**
* Retrieve the {@link String} representation of an {@link Operator}
* instance.
*
* @param operator
* the operator
* @return the {@link String} representation
*/
public static String toString(Operator<?> operator) {
return operator.toString();
}
}

View file

@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
@ -44,6 +44,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Correct string conversion of units and use {@link Operator}.
*
* </pre>
*
@ -68,7 +69,7 @@ public abstract class RuleXML {
/** Rule operator */
@XmlElement
protected String ruleOperator;
protected Operator ruleOperator;
/** Rule value */
@XmlElement
@ -121,7 +122,7 @@ public abstract class RuleXML {
*
* @return the ruleOperator
*/
public String getRuleOperator() {
public Operator getRuleOperator() {
return ruleOperator;
}
@ -131,7 +132,7 @@ public abstract class RuleXML {
* @param ruleOperator
* The operator value of the rule
*/
public void setRuleOperator(String ruleOperator) {
public void setRuleOperator(Operator ruleOperator) {
this.ruleOperator = ruleOperator;
}
@ -192,38 +193,29 @@ public abstract class RuleXML {
unit = getRuleUnit();
}
OperatorAdapter oa = new OperatorAdapter();
Operator oper = null;
try {
oper = oa.unmarshal(ruleOperator);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
return false;
}
// If Data Name
if (OpsNetFieldNames.NAME.toString().equals(ruleField)) {
String dsName = sub.getDataSetName();
return oper.evaluate(dsName, ruleValue);
return ruleOperator.evaluate(dsName, ruleValue);
}
// If Data Type
if (OpsNetFieldNames.TYPE.toString().equals(ruleField)) {
String dsType = sub.getDataSetType().toString();
return oper.evaluate(ruleValue, dsType);
return ruleOperator.evaluate(ruleValue, dsType);
}
// If Data Size
if (OpsNetFieldNames.SIZE.toString().equals(ruleField)) {
long dsSizeKb = sub.getDataSetSize(); // Size in KB
long ruleValueInt = Integer.parseInt(ruleValue);
DataSizeUnit dsUnit = DataSizeUnit.valueOf(unit);
DataSizeUnit dsUnit = DataSizeUnit.fromString(ruleUnit);
ruleValueInt = dsUnit.toKB(ruleValueInt);
return oper.evaluate(Long.valueOf(dsSizeKb),
return ruleOperator.evaluate(Long.valueOf(dsSizeKb),
Long.valueOf(ruleValueInt));
}
@ -231,7 +223,7 @@ public abstract class RuleXML {
if (OpsNetFieldNames.FREQUENCY.toString().equals(ruleField)) {
// Calculate frequency
int ruleValueInt = Integer.parseInt(this.ruleValue);
if (unit.equalsIgnoreCase("Mins")) {
if (FreqUnitOptions.MIN.getOperation().equalsIgnoreCase(unit)) {
ruleValueInt /= 60;
}
int freq = 0;
@ -246,7 +238,8 @@ public abstract class RuleXML {
freq = val - tmp;
}
if (oper.evaluate(Long.valueOf(freq), Long.valueOf(ruleValueInt))) {
if (ruleOperator.evaluate(Long.valueOf(freq),
Long.valueOf(ruleValueInt))) {
return true;
}
}

View file

@ -38,6 +38,7 @@ import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.datadelivery.subscription.xml.LatencyRuleXML;
import com.raytheon.uf.viz.datadelivery.subscription.xml.OperatorAdapter;
import com.raytheon.uf.viz.datadelivery.subscription.xml.PriorityRuleXML;
import com.raytheon.uf.viz.datadelivery.subscription.xml.RuleXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
@ -65,6 +66,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Dec 18, 2012 1417 bgonzale Changed value initialization in handleSave().
* Jan 04, 2013 1420 mpduff Remove code to apply rules changes to existing subscription,
* rules are only for future subscriptions.
* Jan 14, 2013 1286 djohnson Rule operators are now used as objects.
*
* </pre>
*
@ -528,8 +530,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
updateSelectionFields(field);
String operator = ruleXml.getRuleOperator();
operationCombo.select(operationCombo.indexOf(operator));
operationCombo.select(operationCombo.indexOf(OperatorAdapter
.toString(ruleXml.getRuleOperator())));
String value = ruleXml.getRuleValue();
if (!value.isEmpty()) {
@ -646,8 +648,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
boolean valid = false;
String fieldName = fieldCombo.getItem(fieldCombo.getSelectionIndex());
String operator = operationCombo.getItem(operationCombo
.getSelectionIndex());
Operator operator = OperatorAdapter.fromString(operationCombo
.getItem(operationCombo.getSelectionIndex()));
if (create) {
valid = DataDeliveryGUIUtils.hasText(ruleNameText);

View file

@ -19,6 +19,10 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.viz.datadelivery.subscription.xml.OperatorAdapter;
/**
* Operator interface.
*
@ -28,14 +32,15 @@ package com.raytheon.uf.viz.datadelivery.system;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 mpduff Initial creation
* Jan 07, 2013 mpduff Initial creation
* Jan 14, 2013 djohnson Specify JAXB adapter on the interface.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
@XmlJavaTypeAdapter(value = OperatorAdapter.class)
public interface Operator<T> {
/**
* Evaluate whether the operator would return true when comparing operandOne

View file

@ -52,6 +52,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Sep 17, 2012 730 jpiatt Initial creation.
* Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
* Jan 04, 2012 1420 mpduff Add delete rule function.
* Jan 14, 2013 1286 djohnson Rule list is single item selectable.
*
* </pre>
*
@ -134,7 +135,7 @@ public class SystemLatencyTab {
gd.heightHint = 200;
latencyList = new List(latencyComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL);
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
latencyList.setLayoutData(gd);
latencyList.addSelectionListener(new SelectionAdapter() {
@Override

View file

@ -60,6 +60,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Nov 20, 2012 1286 djohnson Add showYesNoMessage.
* Dec 20, 2012 1413 bgonzale Added PendingSubColumnNames.valueOfColumnName(String).
* Jan 10, 2013 1420 mdpuff Added getMaxLatency().
* Jan 14, 2013 1286 djohnson Fix IndexOutOfBounds exception from getMaxLatency.
* </pre>
*
* @author mpduff
@ -554,9 +555,11 @@ public class DataDeliveryUtils {
Collections.sort(cycles);
int max = TimeUtil.HOURS_PER_DAY * TimeUtil.MINUTES_PER_HOUR;
for (int i = 0; i < cycles.size(); i++) {
if (i + 1 <= cycles.size()) {
int tempMax = cycles.get(i + 1) - cycles.get(i);
final int size = cycles.size();
for (int i = 0; i < size; i++) {
final int nextIndex = i + 1;
if (nextIndex < size) {
int tempMax = cycles.get(nextIndex) - cycles.get(i);
if (tempMax > max) {
max = tempMax;
}

View file

@ -1,5 +1,9 @@
package com.raytheon.uf.viz.datadelivery.utils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType;
@ -13,7 +17,8 @@ import javax.xml.bind.annotation.XmlType;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 08, 2013 1420 mpduff Initial creation.
* Jan 08, 2013 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Add lookup map via string version.
*
* </pre>
*
@ -201,4 +206,23 @@ public enum DataSizeUnit {
* @return converted value
*/
public abstract long convert(long l, DataSizeUnit ds);
private static final Map<String, DataSizeUnit> LOOKUP_MAP;
static {
Map<String, DataSizeUnit> map = new HashMap<String, DataSizeUnit>();
for (DataSizeUnit unit : DataSizeUnit.values()) {
map.put(unit.getUnit(), unit);
}
LOOKUP_MAP = Collections.unmodifiableMap(map);
}
/**
* Retrieve the {@link DataSizeUnit} for its string representation.
*
* @param asString
* @return
*/
public static DataSizeUnit fromString(String asString) {
return LOOKUP_MAP.get(asString);
}
}

View file

@ -3,11 +3,8 @@ package com.raytheon.uf.common.datadelivery.registry;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@ -22,6 +19,8 @@ import com.raytheon.uf.common.registry.annotations.SlotAttribute;
import com.raytheon.uf.common.serialization.ISerializableObject;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
*
@ -62,8 +61,9 @@ public class Provider implements ISerializableObject {
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 16, 2012 dhladky Initial creation
* Feb 16, 2012 dhladky Initial creation
* Nov 19, 2012 1166 djohnson Clean up JAXB representation of registry objects.
* Jan 14, 2013 1286 djohnson Extracted {@link IDuration}.
*
* </pre>
*
@ -167,16 +167,9 @@ public class Provider implements ISerializableObject {
@SlotAttribute
private ServiceType serviceType;
// NOTE: The @XmlElement is on the getter because JAXB must call the setter
// for this value
@XmlElement
@DynamicSerializeElement
private String postedFileDelay;
@Transient
private int postedFileDelayValue = 0;
@Transient
private TimeUnit postedFileDelayUnits = TimeUnit.HOURS;
private IDuration postedFileDelay = Durations.ZERO;
/**
* The amount of time that should elapse between HTTP requests while
@ -225,29 +218,10 @@ public class Provider implements ISerializableObject {
/**
* @return the postedFileDelay
*/
@XmlElement(name = "postedFileDelay")
public String getPostedFileDelay() {
public IDuration getPostedFileDelay() {
return postedFileDelay;
}
/**
* Return the {@link TimeUnit} for the posted file delay.
*
* @return the {@link TimeUnit}
*/
public TimeUnit getPostedFileDelayUnits() {
return postedFileDelayUnits;
}
/**
* Return the value of the posted file delay.
*
* @return the value
*/
public int getPostedFileDelayValue() {
return postedFileDelayValue;
}
public List<Projection> getProjection() {
return projection;
}
@ -321,25 +295,10 @@ public class Provider implements ISerializableObject {
* if the string value cannot be parsed into a value and/or
* units
*/
public void setPostedFileDelay(String postedFileDelay) {
public void setPostedFileDelay(IDuration postedFileDelay) {
checkNotNull(postedFileDelay, "postedFileDelay cannot be null!");
this.postedFileDelay = postedFileDelay;
Matcher matcher = POSTED_FILE_DELAY_PATTERN.matcher(postedFileDelay);
if (matcher.matches()) {
postedFileDelayValue = Integer.parseInt(matcher.group(1));
String units = matcher.group(2);
postedFileDelayUnits = TimeUnit.valueOf(units);
if (postedFileDelayUnits == null) {
throw new IllegalArgumentException(units
+ " cannot be parsed into a valid units instance!");
}
} else {
throw new IllegalArgumentException(postedFileDelay
+ " cannot be parsed into a valid value and units!");
}
}
public void setProjection(List<Projection> projection) {

View file

@ -18,5 +18,7 @@ Import-Package: javax.persistence,
Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization
Export-Package: com.raytheon.uf.common.time,
com.raytheon.uf.common.time.adapter,
com.raytheon.uf.common.time.domain,
com.raytheon.uf.common.time.domain.api,
com.raytheon.uf.common.time.msgs,
com.raytheon.uf.common.time.util

View file

@ -0,0 +1,165 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* Implementation of {@link IDuration}. Intentionally package-private as it is
* an implementation detail, and not part of the public API. All access should
* be constrained through {@link Durations}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 10, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = IDurationTypeAdapter.class)
@DynamicSerializeTypeAdapter(factory = IDurationTypeAdapter.class)
class Duration implements IDuration {
private final long valueAsNanoseconds;
/**
* Constructor.
*
* @param value
* the unit value
* @param unit
* the unit
*/
Duration(long value, TimeUnit unit) {
this.valueAsNanoseconds = unit.toNanos(value);
}
/**
* {@inheritDoc}
*/
@Override
public long getNanos() {
return convert(TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getMicros() {
return convert(TimeUnit.MICROSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getMillis() {
return convert(TimeUnit.MILLISECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getSeconds() {
return convert(TimeUnit.SECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getMinutes() {
return convert(TimeUnit.MINUTES);
}
/**
* {@inheritDoc}
*/
@Override
public long getHours() {
return convert(TimeUnit.HOURS);
}
/**
* {@inheritDoc}
*/
@Override
public long getDays() {
return convert(TimeUnit.DAYS);
}
private long convert(TimeUnit targetUnit) {
return targetUnit.convert(valueAsNanoseconds, TimeUnit.NANOSECONDS);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof IDuration) {
IDuration other = (IDuration) obj;
return other.getNanos() == this.getNanos();
}
return super.equals(obj);
}
@Override
public int hashCode() {
return (int) this.getNanos();
}
/**
* {@inheritDoc}
*/
@Override
public Duration plus(IDuration anotherDuration) {
return new Duration(getNanos() + anotherDuration.getNanos(),
TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public Duration minus(IDuration anotherDuration) {
return new Duration(getNanos() - anotherDuration.getNanos(),
TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Durations.toString(this);
}
}

View file

@ -0,0 +1,140 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Retrieve {@link IDuration}s.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public final class Durations {
private static final Pattern DURATION_PATTERN = Pattern
.compile("\\s*(\\d+)\\s+([^\\s]+)\\s*");
public static final IDuration ZERO = Durations
.of(0L, TimeUnit.MILLISECONDS);
/**
* Retrieve a {@link IDuration} of the specified value and unit.
*
* @param value
* @param unit
* @return the duration
*/
public static IDuration of(long value, TimeUnit unit) {
return new Duration(value, unit);
}
/**
* Retrieve the duration between two {@link TimePoint}s.
*
* @param start
* the starting time point
* @param end
* the ending time point
* @return the duration between the two points
*/
public static IDuration between(ITimePoint start, ITimePoint end) {
final long millis = end.asMilliseconds() - start.asMilliseconds();
return of(millis, TimeUnit.MILLISECONDS);
}
/**
* Parse a string representation of a {@link Duration}.
*
* @param asString
* the string representation of the duration
*
* @return the duration
* @throws IllegalArgumentException
* if the argument cannot be parsed into a duration
*/
public static IDuration fromString(String asString) {
final Matcher m = DURATION_PATTERN.matcher(asString);
if (m.matches()) {
return of(Long.parseLong(m.group(1)), TimeUnit.valueOf(m.group(2)));
}
throw new IllegalArgumentException("The argument [" + asString
+ "] does not match a duration!");
}
/**
* Convert the {@link IDuration} to a string representation. This method
* figures out the "optimal" unit to display the time in, e.g. 120 minutes
* would display as "2 HOURS", but 128 minutes will be displayed as "128
* MINUTES".
*
* @param duration
* the duration instance
* @return the string representation
*/
public static String toString(IDuration duration) {
TimeUnit timeUnitForDisplay = TimeUnit.DAYS;
final TimeUnit[] values = TimeUnit.values();
final long nanos = duration.getNanos();
for (int unitIdx = 1; unitIdx < values.length; unitIdx++) {
final TimeUnit timeUnitToTry = values[unitIdx];
// If we would lose precision, then use the time unit before this
// one
final long valueInNewTimeUnit = timeUnitToTry.convert(nanos,
TimeUnit.NANOSECONDS);
final boolean wouldLosePrecision = timeUnitToTry
.toNanos(valueInNewTimeUnit) != nanos;
if (wouldLosePrecision) {
timeUnitForDisplay = values[unitIdx - 1];
break;
}
}
// Now construct and return the pretty version of the String
final long convertedValue = timeUnitForDisplay.convert(nanos,
TimeUnit.NANOSECONDS);
return convertedValue + " " + timeUnitForDisplay.toString();
}
/**
* Disabled constructor.
*/
private Durations() {
}
}

View file

@ -0,0 +1,86 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* {@link ISerializationTypeAdapter} for {@link IDuration} instances.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class IDurationTypeAdapter extends XmlAdapter<String, IDuration>
implements
ISerializationTypeAdapter<IDuration> {
/**
* {@inheritDoc}
*/
@Override
public void serialize(ISerializationContext serializer, IDuration object)
throws SerializationException {
serializer.writeI64(object.getNanos());
}
/**
* {@inheritDoc}
*/
@Override
public IDuration deserialize(IDeserializationContext deserializer)
throws SerializationException {
return Durations.of(deserializer.readI64(), TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public IDuration unmarshal(String v) throws Exception {
return Durations.fromString(v);
}
/**
* {@inheritDoc}
*/
@Override
public String marshal(IDuration v) throws Exception {
return Durations.toString(v);
}
}

View file

@ -0,0 +1,93 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* {@link ISerializationTypeAdapter} for {@link ITimePoint} instances.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class ITimeIntervalTypeAdapter extends
XmlAdapter<TimeIntervalJaxbable, ITimeInterval> implements
ISerializationTypeAdapter<ITimeInterval> {
/**
* {@inheritDoc}
*/
@Override
public void serialize(ISerializationContext serializer, ITimeInterval object)
throws SerializationException {
serializer.writeObject(object.getStart());
serializer.writeObject(object.getEnd());
}
/**
* {@inheritDoc}
*/
@Override
public ITimeInterval deserialize(IDeserializationContext deserializer)
throws SerializationException {
ITimePoint start = (ITimePoint) deserializer.readObject();
ITimePoint end = (ITimePoint) deserializer.readObject();
return TimeIntervals.fromTimePoints(start, end);
}
/**
* {@inheritDoc}
*/
@Override
public ITimeInterval unmarshal(TimeIntervalJaxbable v)
throws Exception {
return TimeIntervals.fromTimePoints(TimePoints.fromDate(v.getStart()),
TimePoints.fromDate(v.getEnd()));
}
/**
* {@inheritDoc}
*/
@Override
public TimeIntervalJaxbable marshal(ITimeInterval v) throws Exception {
TimeIntervalJaxbable jaxbable = new TimeIntervalJaxbable();
jaxbable.setStart(v.getStart().asDate());
jaxbable.setEnd(v.getEnd().asDate());
return jaxbable;
}
}

View file

@ -0,0 +1,83 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* {@link ISerializationTypeAdapter} for {@link ITimePoint} instances.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class ITimePointTypeAdapter extends XmlAdapter<Date, ITimePoint>
implements ISerializationTypeAdapter<ITimePoint> {
/**
* {@inheritDoc}
*/
@Override
public void serialize(ISerializationContext serializer, ITimePoint object)
throws SerializationException {
serializer.writeI64(object.asMilliseconds());
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint deserialize(IDeserializationContext deserializer)
throws SerializationException {
return TimePoints.fromMillis(deserializer.readI64());
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint unmarshal(Date v) throws Exception {
return TimePoints.fromDate(v);
}
/**
* {@inheritDoc}
*/
@Override
public Date marshal(ITimePoint v) throws Exception {
return v.asDate();
}
}

View file

@ -0,0 +1,136 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Implementation of {@link ITimeInterval}. Intentionally package-private as it
* is an implementation detail, and not part of the public API. All access
* should be constrained through {@link TimeIntervals}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimeIntervalTypeAdapter.class)
@DynamicSerializeTypeAdapter(factory = ITimeIntervalTypeAdapter.class)
class TimeInterval implements ITimeInterval {
private final ITimePoint intervalStart;
private final ITimePoint intervalEnd;
/**
* Constructor.
*
* @param intervalStart
* the start of the interval
* @param intervalEnd
* the end of the interval
*/
TimeInterval(ITimePoint intervalStart, ITimePoint intervalEnd) {
this.intervalStart = intervalStart;
this.intervalEnd = intervalEnd;
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint getStart() {
return intervalStart;
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint getEnd() {
return intervalEnd;
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsTimePoint(ITimePoint timePoint) {
final boolean intervalStartSameOrBefore = intervalStart
.isBefore(timePoint) || intervalStart.isSame(timePoint);
final boolean intervalEndSameOrAfter = intervalEnd.isAfter(timePoint)
|| intervalEnd.isSame(timePoint);
return intervalStartSameOrBefore && intervalEndSameOrAfter;
}
/**
* {@inheritDoc}
*/
@Override
public IDuration getDuration() {
return Durations.between(intervalStart, intervalEnd);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof ITimeInterval) {
ITimeInterval other = (ITimeInterval) obj;
return this.getStart().equals(other.getStart())
&& this.getEnd().equals(other.getEnd());
}
return super.equals(obj);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getStart().hashCode() + getEnd().hashCode();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("start [").append(getStart()).append("]");
sb.append(" end [").append(getEnd()).append("]");
sb.append(" duration [").append(getDuration()).append("]");
return sb.toString();
}
}

View file

@ -0,0 +1,91 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
/**
* Representation of a {@link ITimeInterval} for the purpose of JAXB. This class
* should only be used for converting to and from JAXB in
* {@link ITimeIntervalTypeAdapter}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(propOrder = { "start", "end" })
public class TimeIntervalJaxbable {
@XmlElement(required = true)
private Date start;
@XmlElement(required = true)
private Date end;
/**
* @return the start
*/
public Date getStart() {
return start;
}
/**
* @param start
* the start to set
*/
public void setStart(Date start) {
this.start = start;
}
/**
* @return the end
*/
public Date getEnd() {
return end;
}
/**
* @param end
* the end to set
*/
public void setEnd(Date end) {
this.end = end;
}
}

View file

@ -0,0 +1,69 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Utility class to work with {@link ITimeInterval}s
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public final class TimeIntervals {
/**
* Construct a {@link ITimeInterval} from two {@link ITimePoint}s.
*
* @param start
* the start of the time interval
* @param end
* the end of the time interval
* @return the interval
*/
public static ITimeInterval fromTimePoints(ITimePoint start, ITimePoint end) {
if (end.isBefore(start)) {
throw new IllegalArgumentException(
"The end time point cannot be before the start time point:\n[end = "
+ end + "] [start = " + start + "]");
}
return new TimeInterval(start, end);
}
/**
* No construction.
*/
private TimeIntervals() {
}
}

View file

@ -0,0 +1,148 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.time.util.TimeUtil;
/**
* Implementation of {@link ITimePoint}. Intentionally package-private as it is
* an implementation detail, and not part of the public API. All access should
* be constrained through {@link TimePoints}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimePointTypeAdapter.class)
@DynamicSerializeTypeAdapter(factory = ITimePointTypeAdapter.class)
class TimePoint implements ITimePoint {
private final long milliseconds;
/**
* Construct a {@link TimePoint} for the specified milliseconds.
*
* @param milliseconds
*/
TimePoint(long milliseconds) {
this.milliseconds = milliseconds;
}
/**
* Deep-copy another {@link ITimePoint}.
*
* @param toCopy
*/
TimePoint(ITimePoint toCopy) {
this(toCopy.asMilliseconds());
}
/**
* {@inheritDoc}
*/
@Override
public Date asDate() {
return new Date(milliseconds);
}
/**
* {@inheritDoc}
*/
@Override
public long asMilliseconds() {
return milliseconds;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAfter(ITimePoint anotherTimePoint) {
return this.asMilliseconds() > anotherTimePoint.asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isBefore(ITimePoint anotherTimePoint) {
return this.asMilliseconds() < anotherTimePoint.asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSame(ITimePoint anotherPoint) {
return this.asMilliseconds() == anotherPoint.asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isWithin(ITimeInterval interval) {
return interval.containsTimePoint(this);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof ITimePoint) {
ITimePoint other = (ITimePoint) obj;
return this.isSame(other);
}
return super.equals(obj);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return (int) asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return TimeUtil.formatDate(asDate());
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.time.util.TimeUtil;
/**
* Utility class to work with {@link ITimePoint}s.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public final class TimePoints {
/**
* Return the {@link ITimePoint} instance for the specified milliseconds.
*
* @return the milliseconds as an {@link ITimePoint}
*/
public static ITimePoint fromMillis(long milliseconds) {
return new TimePoint(milliseconds);
}
/**
* Return the {@link ITimePoint} instance for the specified {@link Date}.
*
* @return the date as an {@link ITimePoint}
*/
public static ITimePoint fromDate(Date date) {
return new TimePoint(date.getTime());
}
/**
* Return the {@link ITimePoint} instance of the current time.
*
* @return now, as an {@link ITimePoint}
*/
public static ITimePoint now() {
return fromDate(TimeUtil.newImmutableDate());
}
private TimePoints() {
}
}

View file

@ -0,0 +1,138 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain.api;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.datatype.Duration;
import com.raytheon.uf.common.time.domain.IDurationTypeAdapter;
/**
* Interface for a duration.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = IDurationTypeAdapter.class)
public interface IDuration {
/**
* Retrieve the number of nanoseconds represented by the duration.
* Conversions from finer to coarser granularities truncate, so lose
* precision. For example converting <tt>999</tt> milliseconds to seconds
* results in <tt>0</tt>.
*
* @return the number of nanoseconds, or 0 if the converted value is less
* than 1 of the new unit
*/
long getNanos();
/**
* Retrieve the number of microseconds represented by the duration.
* Conversions from finer to coarser granularities truncate, so lose
* precision. For example converting <tt>999</tt> milliseconds to seconds
* results in <tt>0</tt>.
*
* @return the number of microseconds, or 0 if the converted value is less
* than 1 of the new unit
*/
long getMicros();
/**
* Retrieve the number of milliseconds represented by the duration.
* Conversions from finer to coarser granularities truncate, so lose
* precision. For example converting <tt>999</tt> milliseconds to seconds
* results in <tt>0</tt>.
*
* @return the number of milliseconds, or 0 if the converted value is less
* than 1 of the new unit
*/
long getMillis();
/**
* Retrieve the number of seconds represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of seconds, or 0 if the converted value is less than 1
* of the new unit
*/
long getSeconds();
/**
* Retrieve the number of minutes represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of minutes, or 0 if the converted value is less than 1
* of the new unit
*/
long getMinutes();
/**
* Retrieve the number of hours represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of hours, or 0 if the converted value is less than 1
* of the new unit
*/
long getHours();
/**
* Retrieve the number of hours represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of days, or 0 if the converted value is less than 1 of
* the new unit
*/
long getDays();
/**
* Add another {@link Duration} to this one.
*
* @param anotherDuration
* @return the duration of the sum
*/
IDuration plus(IDuration anotherDuration);
/**
* Subtract another {@link Duration} from this one.
*
* @param anotherDuration
* @return the duration of the difference
*/
IDuration minus(IDuration anotherDuration);
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain.api;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.time.domain.ITimeIntervalTypeAdapter;
/**
* Represents a specific interval in time.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimeIntervalTypeAdapter.class)
public interface ITimeInterval {
/**
* Return the start {@link ITimePoint} of the {@link ITimeInterval}.
*
* @return the time point the interval started
*/
ITimePoint getStart();
/**
* Return the end {@link ITimePoint} of the {@link ITimeInterval}.
*
* @return the time point the interval ended
*/
ITimePoint getEnd();
/**
* Check whether an {@link ITimePoint} falls within the
* {@link ITimeInterval}.
*
* @param timePoint
* the time point
* @return true if the interval contains the point
*/
boolean containsTimePoint(ITimePoint timePoint);
/**
* Retrieve the duration of the {@link ITimeInterval}.
*
* @return the duration
*/
IDuration getDuration();
}

View file

@ -0,0 +1,98 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain.api;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.time.domain.ITimePointTypeAdapter;
/**
* Represents an instance in time.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimePointTypeAdapter.class)
public interface ITimePoint {
/**
* Return the {@link ITimePoint} as a {@link Date}.
*
* @return the {@link ITimePoint} as a {@link Date}
*/
Date asDate();
/**
* Return the {@link ITimePoint} as the milliseconds which would be returned
* by {@link Date}.
*
* @return the milliseconds
*/
long asMilliseconds();
/**
* Check whether this {@link ITimePoint} is before another one.
*
* @param anotherPoint
* the other {@link ITimePoint}
* @return true if this point in time is before the other one
*/
boolean isBefore(ITimePoint anotherPoint);
/**
* Check whether this {@link ITimePoint} is after another one.
*
* @param anotherPoint
* the other {@link ITimePoint}
* @return true if this point in time is after the other one
*/
boolean isAfter(ITimePoint anotherPoint);
/**
* Check whether this {@link ITimePoint} is the same as another one.
*
* @param anotherPoint
* the other {@link ITimePoint}
* @return true if this point in time is the same as the other one
*/
boolean isSame(ITimePoint anotherPoint);
/**
* Check whether this {@link ITimePoint} falls within the specified
* {@link ITimeInterval}.
*
* @param interval
* the {@link ITimeInterval}
* @return true if this point in time is within the time interval
*/
boolean isWithin(ITimeInterval interval);
}

View file

@ -1,5 +1,8 @@
package com.raytheon.uf.common.time.util;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
*
@ -13,19 +16,19 @@ package com.raytheon.uf.common.time.util;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 16, 2012 0743 djohnson Initial creation
* Jan 14, 2013 1286 djohnson Use time domain API.
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
// @NotThreadSafe
abstract class AbstractTimer implements ITimer {
private long start;
private ITimePoint start;
private long stop;
private ITimePoint stop;
private long elapsedTime;
private IDuration elapsedTime = Durations.ZERO;
/**
* {@inheritDoc}
@ -33,8 +36,8 @@ abstract class AbstractTimer implements ITimer {
@Override
public void start() {
if (isTimerStopped()) {
elapsedTime += (stop - start);
stop = 0;
elapsedTime = elapsedTime.plus(Durations.between(start, stop));
stop = null;
} else if (isTimerStarted()) {
throw new IllegalStateException(
"A timer that is running must be stopped before start() is called again!");
@ -62,8 +65,21 @@ abstract class AbstractTimer implements ITimer {
*/
@Override
public long getElapsedTime() {
long currentOrStopTime = (isTimerRunning()) ? getCurrentTime() : stop;
return (currentOrStopTime - start) + elapsedTime;
return getElapsed().getMillis();
}
/**
* {@inheritDoc}
*/
@Override
public IDuration getElapsed() {
ITimePoint currentOrStopTime = (isTimerRunning()) ? getCurrentTime()
: stop;
if (currentOrStopTime == null && start == null) {
return Durations.ZERO;
}
IDuration currentRun = Durations.between(start, currentOrStopTime);
return currentRun.plus(elapsedTime);
}
/**
@ -71,12 +87,12 @@ abstract class AbstractTimer implements ITimer {
*/
@Override
public void reset() {
start = 0;
stop = 0;
elapsedTime = 0;
start = null;
stop = null;
elapsedTime = Durations.ZERO;
}
protected abstract long getCurrentTime();
protected abstract ITimePoint getCurrentTime();
/**
* Check whether the timer is actively running.
@ -93,7 +109,7 @@ abstract class AbstractTimer implements ITimer {
* @return true if the timer was started
*/
private boolean isTimerStarted() {
return start > 0;
return start != null;
}
/**
@ -102,6 +118,6 @@ abstract class AbstractTimer implements ITimer {
* @return true if the timer is stopped
*/
private boolean isTimerStopped() {
return stop > 0;
return stop != null;
}
}

View file

@ -1,5 +1,7 @@
package com.raytheon.uf.common.time.util;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
*
* Defines a timer that can be started and stopped.
@ -11,6 +13,7 @@ package com.raytheon.uf.common.time.util;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 16, 2012 0743 djohnson Initial creation
* Jan 11, 2013 djohnson Use {@link IDuration}.
*
* </pre>
*
@ -43,6 +46,13 @@ public interface ITimer {
*/
long getElapsedTime();
/**
* Get the elapsed time
*
* @return the elapsed time
*/
IDuration getElapsed();
/**
* Reset the timer.
*/

View file

@ -28,6 +28,8 @@ import java.util.TimeZone;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.common.time.domain.TimePoints;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Utilities for time, some extracted from Util.
@ -63,9 +65,11 @@ public class TimeUtil {
*
*/
private static class NullClock extends AbstractTimer {
private static final ITimePoint CONSTANT_TIME = TimePoints
.fromMillis(1L);
@Override
protected long getCurrentTime() {
return 1;
protected ITimePoint getCurrentTime() {
return CONSTANT_TIME;
}
}

View file

@ -1,5 +1,8 @@
package com.raytheon.uf.common.time.util;
import com.raytheon.uf.common.time.domain.TimePoints;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
*
@ -27,7 +30,7 @@ class TimerImpl extends AbstractTimer {
* {@inheritDoc}
*/
@Override
protected long getCurrentTime() {
return TimeUtil.currentTimeMillis();
protected ITimePoint getCurrentTime() {
return TimePoints.fromMillis(TimeUtil.currentTimeMillis());
}
}

View file

@ -8,7 +8,6 @@ import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.google.common.annotations.VisibleForTesting;
import com.raytheon.uf.common.datadelivery.registry.Collection;
@ -278,9 +277,8 @@ public class MainSequenceCrawler extends Crawler {
if (!coll.isIgnore()) {
List<Date> datesToCrawl = new ArrayList<Date>();
Date date = TimeUtil.newImmutableDate();
long postedFileDelayMilliseconds = TimeUnit.MILLISECONDS
.convert(provider.getPostedFileDelayValue(),
provider.getPostedFileDelayUnits());
long postedFileDelayMilliseconds = provider
.getPostedFileDelay().getMillis();
if (postedFileDelayMilliseconds > 0) {
// Check whether the posted file delay would place us in

View file

@ -31,6 +31,8 @@ import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfig;
import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfigFixture;
@ -53,30 +55,13 @@ import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfigFixture
public class ProviderTest {
@Test
public void testSetPostedFileDelayAllowsSpacesSurrounding() {
Provider provider = new Provider();
provider.setPostedFileDelay(" 2 MICROSECONDS ");
assertEquals(2, provider.getPostedFileDelayValue());
assertEquals(TimeUnit.MICROSECONDS, provider.getPostedFileDelayUnits());
}
@Test
public void testSetPostedFileDelayCanParseText() {
Provider provider = new Provider();
provider.setPostedFileDelay("5 HOURS");
assertEquals(5, provider.getPostedFileDelayValue());
assertEquals(TimeUnit.HOURS, provider.getPostedFileDelayUnits());
}
@Test
public void testSetPostedFileDelayIsCalledOnJaxbUnmarshall()
throws JAXBException {
HarvesterConfig config = HarvesterConfigFixture.INSTANCE.get();
Provider provider = config.getProvider();
provider.setPostedFileDelay("3 DAYS");
final IDuration originalDuration = Durations.of(3, TimeUnit.DAYS);
provider.setPostedFileDelay(originalDuration);
Writer writer = new StringWriter();
JAXBContext ctx = JAXBContext.newInstance(HarvesterConfig.class);
@ -85,19 +70,6 @@ public class ProviderTest {
HarvesterConfig restored = (HarvesterConfig) ctx.createUnmarshaller()
.unmarshal(new StringReader(writer.toString()));
Provider restoredProvider = restored.getProvider();
assertEquals(3, restoredProvider.getPostedFileDelayValue());
assertEquals(TimeUnit.DAYS, restoredProvider.getPostedFileDelayUnits());
}
@Test(expected = IllegalArgumentException.class)
public void testSetPostedFileDelayThrowsExceptionOnInvalidUnits() {
Provider provider = new Provider();
provider.setPostedFileDelay("5 HOUR");
}
@Test(expected = IllegalArgumentException.class)
public void testSetPostedFileDelayThrowsExceptionOnValueLessThanZero() {
Provider provider = new Provider();
provider.setPostedFileDelay("-1 DAYS");
assertEquals(originalDuration, restoredProvider.getPostedFileDelay());
}
}

View file

@ -0,0 +1,302 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformFromThrift;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformToThrift;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.util.TestUtil;
/**
* Test {@link Duration}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 10, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class DurationTest {
private static final long TWO_DAYS_IN_NANOS = TimeUnit.DAYS.toNanos(2);
private static final long TWO_DAYS_IN_MICROS = TimeUnit.DAYS.toMicros(2);
private static final long TWO_DAYS_IN_MILLIS = TimeUnit.DAYS.toMillis(2);
private static final long TWO_DAYS_IN_SECONDS = TimeUnit.DAYS.toSeconds(2);
private static final long TWO_DAYS_IN_MINUTES = TimeUnit.DAYS.toMinutes(2);
private static final long TWO_DAYS_IN_HOURS = TimeUnit.DAYS.toHours(2);
private static final long TWO_DAYS_IN_DAYS = TimeUnit.DAYS.toDays(2);
@Test
public void testNanosecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_NANOS,
TimeUnit.NANOSECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testNanosecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.NANOSECONDS);
assertThat(startValue, is(equalTo(duration.getNanos())));
assertThat(0L, is(equalTo(duration.getMicros())));
assertThat(0L, is(equalTo(duration.getMillis())));
assertThat(0L, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testMicrosecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_MICROS,
TimeUnit.MICROSECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testMicrosecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.MICROSECONDS);
assertThat(startValue, is(equalTo(duration.getMicros())));
assertThat(0L, is(equalTo(duration.getMillis())));
assertThat(0L, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testMillisecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_MILLIS,
TimeUnit.MILLISECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testMillisecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.MILLISECONDS);
assertThat(startValue, is(equalTo(duration.getMillis())));
assertThat(0L, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testSecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_SECONDS, TimeUnit.SECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testSecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.SECONDS);
assertThat(startValue, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testMinutesConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_MINUTES, TimeUnit.MINUTES);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testMinutesConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.MINUTES);
assertThat(startValue, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testHoursConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_HOURS, TimeUnit.HOURS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testHoursConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.HOURS);
assertThat(startValue, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testDaysConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_DAYS, TimeUnit.DAYS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testAddDurationReturnsCorrectAmount() {
IDuration dur1 = new Duration(2, TimeUnit.HOURS);
IDuration dur2 = new Duration(2, TimeUnit.DAYS);
assertThat(new Duration(50, TimeUnit.HOURS),
is(equalTo(dur1.plus(dur2))));
}
@Test
public void testSubtractDurationReturnsCorrectAmount() {
IDuration dur1 = new Duration(2, TimeUnit.DAYS);
IDuration dur2 = new Duration(2, TimeUnit.HOURS);
assertThat(new Duration(46, TimeUnit.HOURS),
is(equalTo(dur1.minus(dur2))));
}
@Test
public void testConversionToAndFromDynamicSerialize()
throws SerializationException {
IDuration original = new Duration(2, TimeUnit.DAYS);
UsesDuration usesDuration = new UsesDuration();
usesDuration.setDuration(original);
IDuration restored = transformFromThrift(UsesDuration.class,
transformToThrift(usesDuration)).getDuration();
assertThat(restored, is(equalTo(original)));
}
@Test
public void testConversionToAndFromJaxb() throws SerializationException,
JAXBException {
IDuration original = new Duration(2, TimeUnit.DAYS);
UsesDuration usesDuration = new UsesDuration();
usesDuration.setDuration(original);
JAXBManager manager = new JAXBManager(UsesDuration.class);
final String xml = manager.marshalToXml(usesDuration);
IDuration restored = ((UsesDuration) manager.unmarshalFromXml(xml))
.getDuration();
assertThat(restored, is(equalTo(original)));
}
@Test
public void testEqualsAndHashcodeContract() {
IDuration objectUnderTest = Durations.of(TWO_DAYS_IN_DAYS,
TimeUnit.DAYS);
List<IDuration> equalObjects = Arrays.asList(
Durations.of(TWO_DAYS_IN_HOURS, TimeUnit.HOURS),
Durations.of(TWO_DAYS_IN_MINUTES, TimeUnit.MINUTES),
Durations.of(TWO_DAYS_IN_SECONDS, TimeUnit.SECONDS));
List<IDuration> unequalObjects = Arrays.asList(
Durations.of(TWO_DAYS_IN_HOURS + 1, TimeUnit.HOURS),
Durations.of(TWO_DAYS_IN_MINUTES + 1, TimeUnit.MINUTES),
Durations.of(TWO_DAYS_IN_SECONDS + 1, TimeUnit.SECONDS));
TestUtil.assertEqualsAndHashcodeContract(objectUnderTest, equalObjects,
unequalObjects);
}
}

View file

@ -0,0 +1,94 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* Test {@link Durations}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class DurationsTest {
@Test
public void testParseFromString() {
IDuration duration = Durations.fromString("3 SECONDS");
assertThat(duration, is(equalTo(Durations.of(3, TimeUnit.SECONDS))));
}
@Test(expected = IllegalArgumentException.class)
public void testUnparseableStringThrowsException() {
Durations.fromString("unparseable");
}
@Test
public void testToStringWritesOutLargestUnitNotLosingPrecision() {
final String original = "3 SECONDS";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
@Test
public void testToStringForSmallestUnit() {
final String original = "1 NANOSECONDS";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
@Test
public void testToStringForLargestUnit() {
final String original = "7 DAYS";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
@Test
public void test128MinutesDoesNotUseHours() {
final String original = "128 MINUTES";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
}

View file

@ -0,0 +1,157 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformFromThrift;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformToThrift;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.util.TestUtil;
/**
* Test {@link TimeInterval}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimeIntervalTest {
private final ITimePoint intervalStart = TimePoints.fromMillis(100L);
private final ITimePoint intervalEnd = TimePoints.fromMillis(500L);
private final ITimeInterval interval = new TimeInterval(intervalStart,
intervalEnd);
@Test
public void testConversionToAndFromDynamicSerialize()
throws SerializationException {
UsesTimeInterval usesTimeInterval = new UsesTimeInterval();
usesTimeInterval.setTimeInterval(interval);
ITimeInterval restored = transformFromThrift(UsesTimeInterval.class,
transformToThrift(usesTimeInterval)).getTimeInterval();
assertThat(restored, is(equalTo(interval)));
}
@Test
public void testConversionToAndFromJaxb() throws SerializationException,
JAXBException {
UsesTimeInterval usesTimeInterval = new UsesTimeInterval();
usesTimeInterval.setTimeInterval(interval);
JAXBManager manager = new JAXBManager(UsesTimeInterval.class);
final String xml = manager.marshalToXml(usesTimeInterval);
ITimeInterval restored = ((UsesTimeInterval) manager
.unmarshalFromXml(xml)).getTimeInterval();
assertThat(restored, is(equalTo(interval)));
}
@Test
public void testGetStartReturnsCorrectTimePoint() {
assertThat(interval.getStart(), is(equalTo(intervalStart)));
}
@Test
public void testGetEndReturnsCorrectTimePoint() {
assertThat(interval.getEnd(), is(equalTo(intervalEnd)));
}
@Test
public void testContainsTimePointReturnsTrueForMidPointWithinInterval() {
final ITimePoint withinInterval = TimePoints.fromMillis((intervalStart
.asMilliseconds() + intervalEnd.asMilliseconds()) / 2);
assertTrue(
"The interval should have returned true for a time point contained in it!",
interval.containsTimePoint(withinInterval));
}
@Test
public void testContainsTimePointReturnsTrueForIntervalStart() {
assertTrue(
"The interval should have returned true for a time point contained in it!",
interval.containsTimePoint(intervalStart));
}
@Test
public void testContainsTimePointReturnsTrueForIntervalEnd() {
assertTrue(
"The interval should have returned true for a time point contained in it!",
interval.containsTimePoint(intervalEnd));
}
@Test
public void testGetDurationReturnsCorrectAmount() {
assertThat(interval.getDuration(), is(equalTo(Durations.of(
intervalEnd.asMilliseconds() - intervalStart.asMilliseconds(),
TimeUnit.MILLISECONDS))));
}
@Test
public void testEqualsAndHashcodeContract() {
ITimeInterval sameInterval = new TimeInterval(
TimePoints.fromMillis(intervalStart.asMilliseconds()),
TimePoints.fromMillis(intervalEnd.asMilliseconds()));
List<ITimeInterval> equalObjects = Arrays
.<ITimeInterval> asList(sameInterval);
ITimeInterval startOneMillisecondEarlier = new TimeInterval(
TimePoints.fromMillis(intervalStart.asMilliseconds() - 1L),
TimePoints.fromMillis(intervalEnd.asMilliseconds()));
ITimeInterval endOneMillisecondLater = new TimeInterval(
TimePoints.fromMillis(intervalStart.asMilliseconds()),
TimePoints.fromMillis(intervalEnd.asMilliseconds() + 1L));
List<ITimeInterval> unequalObjects = Arrays.<ITimeInterval> asList(
startOneMillisecondEarlier, endOneMillisecondLater);
TestUtil.assertEqualsAndHashcodeContract(interval, equalObjects,
unequalObjects);
}
}

View file

@ -0,0 +1,48 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import org.junit.Test;
/**
* Test {@link TimeIntervals}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimeIntervalsTest {
@Test(expected = IllegalArgumentException.class)
public void testEndCantBeBeforeStart() {
TimeIntervals.fromTimePoints(TimePoints.fromMillis(20L),
TimePoints.fromMillis(10L));
}
}

View file

@ -0,0 +1,202 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformFromThrift;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformToThrift;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.util.TestUtil;
/**
* Test {@link TimePoint}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimePointTest {
private final ITimePoint earlierPoint = new TimePoint(1L);
private final ITimePoint laterPoint = new TimePoint(2L);
private final ITimePoint sameAsEarlierPoint = new TimePoint(earlierPoint);
@Test
public void testConversionToAndFromDynamicSerialize()
throws SerializationException {
UsesTimePoint usesTimePoint = new UsesTimePoint();
usesTimePoint.setTimePoint(laterPoint);
ITimePoint restored = transformFromThrift(UsesTimePoint.class,
transformToThrift(usesTimePoint)).getTimePoint();
assertThat(restored, is(equalTo(laterPoint)));
}
@Test
public void testConversionToAndFromJaxb() throws SerializationException,
JAXBException {
UsesTimePoint usesTimePoint = new UsesTimePoint();
usesTimePoint.setTimePoint(laterPoint);
JAXBManager manager = new JAXBManager(UsesTimePoint.class);
final String xml = manager.marshalToXml(usesTimePoint);
ITimePoint restored = ((UsesTimePoint) manager.unmarshalFromXml(xml))
.getTimePoint();
assertThat(restored, is(equalTo(laterPoint)));
}
@Test
public void testAsDateReturnsSameInstance() {
Date date = new Date();
TimePoint timePoint = new TimePoint(date.getTime());
assertThat(timePoint.asDate(), is(equalTo(date)));
}
@Test
public void testAsMillisecondsReturnsOriginalValue() {
final long originalMillis = TimeUtil.currentTimeMillis();
TimePoint timePoint = new TimePoint(originalMillis);
assertThat(timePoint.asMilliseconds(), is(equalTo(originalMillis)));
}
@Test
public void testIsAfterReturnsTrueWhenLater() {
assertTrue("The later point should have been recognized as later!",
laterPoint.isAfter(earlierPoint));
}
@Test
public void testIsAfterReturnsFalseWhenEarlier() {
assertFalse(
"The earlier point should have been recognized as not later!",
earlierPoint.isAfter(laterPoint));
}
@Test
public void testIsAfterReturnsFalseWhenSameTime() {
assertFalse(
"The earlier point should have been recognized as not later!",
sameAsEarlierPoint.isAfter(laterPoint));
}
@Test
public void testIsBeforeReturnsTrueWhenEarlier() {
assertTrue("The earlier point should have been recognized as earlier!",
earlierPoint.isBefore(laterPoint));
}
@Test
public void testIsBeforeReturnsFalseWhenLater() {
assertFalse(
"The later point should have been recognized as not earlier!",
laterPoint.isBefore(earlierPoint));
}
@Test
public void testIsBeforeReturnsFalseWhenSameTime() {
assertFalse(
"The same time point should have been recognized as not earlier!",
sameAsEarlierPoint.isBefore(earlierPoint));
}
@Test
public void testIsSameReturnsFalseWhenEarlier() {
assertFalse("The earlier point should not have been the same!",
earlierPoint.isSame(laterPoint));
}
@Test
public void testIsSameReturnsFalseWhenLater() {
assertFalse("The later point should not have been the same!",
laterPoint.isSame(earlierPoint));
}
@Test
public void testIsSameReturnsTrueWhenSameTime() {
assertTrue(
"The same time point should have been recognized as the same time!",
sameAsEarlierPoint.isSame(earlierPoint));
}
@Test
public void testIsWithinReturnsTrueForTimeIntervalThatContainsIt() {
ITimeInterval interval = TimeIntervals.fromTimePoints(earlierPoint,
laterPoint);
assertTrue(
"The time point should have returned true for being within the interval",
earlierPoint.isWithin(interval));
}
@Test
public void testIsWithinReturnsFalseForTimeIntervalThatDoesntContainIt() {
ITimeInterval interval = TimeIntervals.fromTimePoints(earlierPoint,
laterPoint);
assertFalse(
"The time point should have returned false for being within the interval",
new TimePoint(earlierPoint.asMilliseconds() - 1L)
.isWithin(interval));
}
@Test
public void testEqualsAndHashcodeContract() {
List<ITimePoint> equalObjects = Arrays.asList(sameAsEarlierPoint);
List<ITimePoint> unequalObjects = Arrays.asList(laterPoint,
TimePoints.now());
TestUtil.assertEqualsAndHashcodeContract(earlierPoint, equalObjects,
unequalObjects);
}
}

View file

@ -0,0 +1,70 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.time.util.TimeUtilTest;
/**
* Test {@link TimePoints}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimePointsTest {
@Before
public void setUp() {
TimeUtilTest.freezeTime();
}
@After
public void tearDown() {
TimeUtilTest.resumeTime();
}
@Test
public void testNowReturnsCurrentTime() {
long expectedTime = TimeUtil.currentTimeMillis();
assertThat(TimePoints.now(),
is(equalTo(TimePoints.fromMillis(expectedTime))));
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Ignore;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* Uses an {@link IDuration}. Used by {@link DurationTest} to verify Jaxb
* interoperability.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class UsesDuration {
@DynamicSerializeElement
@XmlElement
private IDuration duration;
/**
* @return the duration
*/
public IDuration getDuration() {
return duration;
}
/**
* @param duration
* the duration to set
*/
public void setDuration(IDuration duration) {
this.duration = duration;
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Ignore;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
/**
* Uses an {@link ITimeInterval}. Used by {@link TimeIntervalTest} to verify
* Jaxb interoperability.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class UsesTimeInterval {
@DynamicSerializeElement
@XmlElement
private ITimeInterval timeInterval;
/**
* @return the timeInterval
*/
public ITimeInterval getTimeInterval() {
return timeInterval;
}
/**
* @param timeInterval
* the timeInterval to set
*/
public void setTimeInterval(ITimeInterval timeInterval) {
this.timeInterval = timeInterval;
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Ignore;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Uses an {@link ITimePoint}. Used by {@link TimePointTest} to verify Jaxb
* interoperability.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class UsesTimePoint {
@DynamicSerializeElement
@XmlElement
private ITimePoint timePoint;
/**
* @return the timePoint
*/
public ITimePoint getTimePoint() {
return timePoint;
}
/**
* @param timePoint
* the timePoint to set
*/
public void setTimePoint(ITimePoint timePoint) {
this.timePoint = timePoint;
}
}

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.edex.datadelivery.harvester;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
@ -30,6 +31,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.time.util.TimeUtilTest;
import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfig;
@ -105,7 +107,8 @@ public class CrawlerTest {
TimeUtilTest.freezeTime(time);
HarvesterConfig harvesterConfig = HarvesterConfigFixture.INSTANCE.get();
harvesterConfig.getProvider().setPostedFileDelay("3 DAYS");
harvesterConfig.getProvider().setPostedFileDelay(
Durations.of(3, TimeUnit.DAYS));
MainSequenceCrawler crawler = new MainSequenceCrawler(harvesterConfig,
mockCommunicationStrategy);
List<ModelCrawlConfiguration> modelCrawlConfigs = crawler
@ -129,7 +132,7 @@ public class CrawlerTest {
TimeUtilTest.freezeTime(time);
HarvesterConfig harvesterConfig = HarvesterConfigFixture.INSTANCE.get();
harvesterConfig.getProvider().setPostedFileDelay("2 MILLISECONDS");
harvesterConfig.getProvider().setPostedFileDelay(Durations.of(2, TimeUnit.MILLISECONDS));
MainSequenceCrawler crawler = new MainSequenceCrawler(harvesterConfig,
mockCommunicationStrategy);
List<ModelCrawlConfiguration> modelCrawlConfigs = crawler

View file

@ -0,0 +1,85 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.datadelivery.subscription.xml;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.datadelivery.registry.SubscriptionFixture;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
/**
* Test {@link LatencyRulesXML}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class LatencyRuleXMLTest {
/**
* Rule data size units were being written out as "Byte" but expected to be
* BYTE when running matches.
*
* @throws JAXBException
*/
@Test
public void testDataSizeUnitCanBeUsedInMatches() throws JAXBException {
LatencyRuleXML ruleXml = new LatencyRuleXML();
ruleXml.setLatency(10);
ruleXml.setRuleField(OpsNetFieldNames.SIZE.toString());
ruleXml.setRuleName("ruleName");
ruleXml.setRuleOperator(OperatorTypes.GREATER_THAN);
ruleXml.setRuleUnit(DataSizeUnit.BYTE.getUnit());
ruleXml.setRuleValue("10");
ruleXml.matches(SubscriptionFixture.INSTANCE.get(),
CollectionUtil.asSet(1, 2));
}
@Test
public void testFrequencyUnitCanBeUsedInMatches() throws JAXBException {
LatencyRuleXML ruleXml = new LatencyRuleXML();
ruleXml.setLatency(10);
ruleXml.setRuleField(OpsNetFieldNames.FREQUENCY.toString());
ruleXml.setRuleName("ruleName");
ruleXml.setRuleOperator(OperatorTypes.GREATER_THAN);
ruleXml.setRuleUnit(FreqUnitOptions.MIN.getOperation());
ruleXml.setRuleValue("10");
ruleXml.matches(SubscriptionFixture.INSTANCE.get(),
CollectionUtil.asSet(1, 2));
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.datadelivery.subscription.xml;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
/**
* Test {@link OperatorAdapter}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class OperatorAdapterTest {
@Test
public void testMarshalUnmarshalOperatorNameOperationItems() {
verifyOperatorsUnmarshalAsSameOperator(NameOperationItems.values());
}
@Test
public void testMarshalUnmarshalOperatorOperatorTypes() {
verifyOperatorsUnmarshalAsSameOperator(OperatorTypes.values());
}
@Test
public void testMarshalUnmarshalOperatorTypeOperationItems() {
verifyOperatorsUnmarshalAsSameOperator(TypeOperationItems.values());
}
private void verifyOperatorsUnmarshalAsSameOperator(Operator... operators) {
for (Operator operator : operators) {
assertThat(operator,
is(sameInstance(OperatorAdapter.fromString(OperatorAdapter
.toString(operator)))));
}
}
}

View file

@ -31,6 +31,7 @@ import org.junit.Test;
import com.raytheon.uf.common.datadelivery.registry.DataType;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
@ -46,7 +47,8 @@ import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 3, 2013 1420 mpduff Initial creation.
* Jan 03, 2013 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Use the rule operator as an {@link Operator}.
*
* </pre>
*
@ -70,7 +72,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("GFS");
rule.setRuleField(OpsNetFieldNames.NAME.getFieldName());
rule.setRuleOperator(NameOperationItems.LIKE.getOperation());
rule.setRuleOperator(NameOperationItems.LIKE);
assertTrue("Matches Data Set Name failed", rule.matches(sub, null));
}
@ -80,7 +82,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("GFS2");
rule.setRuleField(OpsNetFieldNames.NAME.getFieldName());
rule.setRuleOperator(NameOperationItems.LIKE.getOperation());
rule.setRuleOperator(NameOperationItems.LIKE);
assertFalse("Matches Data Set Name false positive",
rule.matches(sub, null));
@ -91,7 +93,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("GRID,OBS");
rule.setRuleField(OpsNetFieldNames.TYPE.getFieldName());
rule.setRuleOperator(TypeOperationItems.IN.getOperation());
rule.setRuleOperator(TypeOperationItems.IN);
assertTrue("Matches Data Type In Failed", rule.matches(sub, null));
}
@ -101,7 +103,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("FAKE");
rule.setRuleField(OpsNetFieldNames.TYPE.getFieldName());
rule.setRuleOperator(TypeOperationItems.NOT_IN.getOperation());
rule.setRuleOperator(TypeOperationItems.NOT_IN);
assertTrue("Matches Data Type Not In Failed", rule.matches(sub, null));
}
@ -111,7 +113,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(100));
rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(DataSizeUnit.KB.getUnit());
assertTrue("Matches Dataset Size Equals Failed",
@ -123,7 +125,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(100));
rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(DataSizeUnit.MB.getUnit());
sub.setDataSetSize(1024 * 100);
@ -136,7 +138,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(100));
rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(DataSizeUnit.GB.getUnit());
sub.setDataSetSize(100 * 1024 * 1024);
@ -151,7 +153,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(60));
rule.setRuleField(OpsNetFieldNames.FREQUENCY.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(FreqUnitOptions.MIN.getOperation());
Set<Integer> cycles = new TreeSet<Integer>();
@ -167,7 +169,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(1));
rule.setRuleField("Dataset Frequency");
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(FreqUnitOptions.HOURS.getOperation());
Set<Integer> cycles = new TreeSet<Integer>();

View file

@ -0,0 +1,69 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.datadelivery.utils;
import static com.google.common.collect.Lists.newArrayList;
import java.util.List;
import org.junit.Test;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.SubscriptionFixture;
import com.raytheon.uf.common.datadelivery.registry.Time;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class DataDeliveryUtilsTest {
/**
* The method was throwing {@link IndexOutOfBoundsException}, this will
* prevent that regression.
*/
@Test
public void testMaxLatencyDoesntOverrunListIndex() {
List<Integer> cycleTimes = newArrayList();
cycleTimes.add(0);
cycleTimes.add(1);
cycleTimes.add(2);
Subscription subscription = SubscriptionFixture.INSTANCE.get();
Time subTime = subscription.getTime();
subTime.setCycleTimes(cycleTimes);
DataDeliveryUtils.getMaxLatency(subscription);
}
}