/** * Convenience method to construct an {@link XdmDuration} value. * * @param serializedString * A {@link String} representation of the duration (ie P2Y3M141DT12H46M12.34S). * @return An instance of {@link XdmDuration}. */ public static XdmDuration newDuration(String serializedString) { return new Duration(serializedString); }
/** * Construct a duration object initialized from the given string in the format of a serialized * xs:duration item. Examples: P2Y3M141DT12H46M12.34S, -P92M, -P32M2DT0.2S. * * @param duration * An xs:duration value as defined by <a * href="http://www.w3.org/TR/xmlschema-2/#duration>XML Schema Part 2: Datatypes</a> * @throws IllegalArgumentException * If the given string is not a valid duration value. */ public Duration(String duration) { parseDuration(duration); }
private void parseDuration(String dur) { Matcher matcher = durPattern.matcher(dur); if (!matcher.matches()) { throw new IllegalArgumentException("Not a valid duration: " + dur); } negative = "-".equals(matcher.group(SIGN)); years = intValue(matcher.group(YEARS)); months = intValue(matcher.group(MONTHS)); days = intValue(matcher.group(DAYS)); hours = intValue(matcher.group(HOURS)); minutes = intValue(matcher.group(MINUTES)); seconds = bigDecimalValue(matcher.group(SECONDS)); }
@Override public int hashCode() { return toString().hashCode(); }
public AbstractDurationItem(ItemType type, String value) { super(type, value); this.value = new Duration(value); }