List of usage examples for org.joda.time Duration compareTo
public int compareTo(ReadableDuration other)
From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java
License:LGPL
/** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. * //from w w w. ja va 2s .co m * @param o * the Object to be compared. * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. * @throws ClassCastException * if the specified object's type prevents it from being * compared to this Object. */ public int compareTo(DvOrdered o) { final DvDuration d = (DvDuration) o; /* * if (period.getYears() > d.period.getYears()) { return 1; } else if * (period.getYears() < d.period.getYears()) { return -1; } if * (period.getMonths() > d.period.getMonths()) { return 1; } else if * (period.getMonths() < d.period.getMonths()) { return -1; } if * (period.getWeeks() > d.period.getWeeks()) { return 1; } else if * (period.getWeeks() < d.period.getWeeks()) { return -1; } if * (period.getDays() > d.period.getDays()) { return 1; } else if * (period.getDays() < d.period.getDays()) { return -1; } * * if (period.getHours() > d.period.getHours()) { return 1; } else if * (period.getHours() < d.period.getHours()) { return -1; } * * if (period.getMinutes() > d.period.getMinutes()) { return 1; } else * if (period.getMinutes() < d.period.getMinutes()) { return -1; } * * if (period.getSeconds() > d.period.getSeconds()) { return 1; } else * if (period.getSeconds() < d.period.getSeconds()) { return -1; } * * if (period.getMillis() > d.period.getMillis()) { return 1; } else if * (period.getMillis() < d.period.getMillis()) { return -1; } */ DateTime dt = new DateTime(0); Duration duration = period.toDurationFrom(dt); Duration otherD = d.period.toDurationFrom(dt); return duration.compareTo(otherD); // return 0; }
From source file:propel.core.utils.StringUtils.java
License:Open Source License
/** * Parses a TimeSpan from a string. TimeSpans are .NET structs and do not have an equivalent in Java. They express time durations in * ticks, which are units 1000 times smaller than milliseconds. * /*www . j av a 2 s . c o m*/ * @throws NullPointerException An argument is null. * @throws NumberFormatException Parsed value is outside of configured range, or not of correct type. */ @Validate public static Duration parseTimeSpan(@NotNull final String value, @NotNull final Duration minValue, @NotNull final Duration maxValue) { Duration result; try { result = new Duration(Long.parseLong(value) / 1000); } catch (Throwable e) { throw new NumberFormatException("The value '" + value + "' could not be parsed: " + e.getMessage()); } // sanity check if (result.compareTo(minValue) < 0) throw new NumberFormatException( "Value (" + result + ") was less than allowed minimum (" + minValue + ")."); if (result.compareTo(maxValue) > 0) throw new NumberFormatException( "Value (" + result + ") was more than allowed maximum (" + maxValue + ")."); return result; }
From source file:propel.core.validation.propertyMetadata.DurationPropertyMetadata.java
License:Open Source License
protected void checkBounds(Duration value) throws ValidationException { // check conditions if (value.compareTo(getMaxValue()) > 0) throw new ValidationException( String.format(BoundedValueTypePropertyMetadata.SHOULD_NOT_BE_GREATER_THAN, getName()) + getMaxValue().getStandardSeconds() + " secs."); if (value.compareTo(getMinValue()) < 0) throw new ValidationException( String.format(BoundedValueTypePropertyMetadata.SHOULD_NOT_BE_LESS_THAN, getName()) + getMinValue().getStandardSeconds() + " secs."); }