/** * <p>Parse the given string and return a time duration * which represents this string. * @param str the string to parse * @return a TimeDuration instance which represent the string * @throws ParseException thrown when the string is not valid */ public static Duration parseDuration(String str) throws ParseException { Duration result = new Duration(); return parseDurationInternal(str, result); }
/** * Returns true if the present instance of TimeDuration is greater than the parameter * <p> * Note This definition does not follow the XML SCHEMA RECOMMENDATION 05022001 the following total * order relation is used : <tt>givent t1,t2 timeDuration types * t1>t2 iff t1.toLong()>t2.toLong()</tt> * * @param duration the time duration to compare with the present instance * @return true if the present instance is the greatest, false if not */ public boolean isGreater(Duration duration) { boolean result = false; // to be optimized ?? result = this.toLong() > duration.toLong(); return result; } // isGreater
/** * {@inheritDoc} * Override the java.lang.equals method * @see #equal */ public boolean equals(Object object) { if (object instanceof Duration) { return equal((Duration) object); } return false; }
/** * Returns true if the instance of TimeDuration has the same fields * of the parameter * @param duration the time duration to compare * @return true if equal, false if not */ public boolean equal(Duration duration) { boolean result = false; if (duration == null) { return result; } result = (_year == duration.getYear()); result = result && (_month == duration.getMonth()); result = result && (_day == duration.getDay()); result = result && (_hour == duration.getHour()); result = result && (_minute == duration.getMinute()); result = result && (_second == duration.getSeconds()); result = result && (_millisecond == duration.getMilli()); result = result && (this.isNegative() == duration.isNegative()); return result; } //equals
/** * Sets the value of the field associated with this descriptor. * @param target the object in which to set the value * @param value the value of the field */ public void setValue(Object target, Object value) throws java.lang.IllegalStateException { if (! (target instanceof Duration)) { String err = "DurationDescriptor#setValue: expected Duration, received instead: " + target.getClass(); throw new IllegalStateException(err); } Duration time = (Duration) target; if (value == null) { String err = "DurationDescriptor#setValue: null value"; throw new IllegalStateException(err); } //-- update current instance of time with new time try { Duration temp = Duration.parseDuration(value.toString()) ; time.setYear(temp.getYear()); time.setMonth(temp.getMonth()); time.setDay(temp.getDay()); time.setHour(temp.getHour()); time.setMinute(temp.getMinute()); time.setSeconds(temp.getSeconds()); time.setMilli(temp.getMilli()); } catch (java.text.ParseException ex) { throw new IllegalStateException(); } } //-- setValue
result = new Duration(); result.setNegative(); if (idx >= chars.length) { throw new ParseException("'-' is wrongly placed",0); result.setYear((short)number); hasNumber = false; } else { result.setMinute((short)number); hasNumber = false; } else { result.setMonth((short)number); hasNumber = false; } else { result.setDay((short)number); hasNumber = false; } else { result.setHour((short)number); hasNumber = false; } else { result.setSeconds((short)number); hasNumber = false; } else {
/** * Normalizes a date/time datatype as defined in W3C XML Schema Recommendation document: if a * timeZone is present but it is not Z then we convert the date/time datatype to Z using the * addition operation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes"> Adding Duration to * dateTimes (W3C XML Schema, part 2 appendix E).</a> * * @see #addDuration */ public void normalize() { if (!isUTC() || (_zoneHour == 0 && _zoneMinute == 0)) { return; } Duration temp = new Duration(); temp.setHour(_zoneHour); temp.setMinute(_zoneMinute); if (!isZoneNegative()) { temp.setNegative(); } this.addDuration(temp); // reset the zone this.setZone((short) 0, (short) 0); this.setZoneNegative(false); }
if (_fixed != null && !duration.equal(_fixed)) { String err = "Duration " + duration + " is not equal to the fixed value: " + _fixed; throw new ValidationException(err); if (isThereMinInclusive && _minInclusive.isGreater(duration)) { String err = "Duration " + duration + " is less than the minimum allowed value: " + _minInclusive; && (_minExclusive.isGreater(duration) || duration.equals(_minExclusive))) { String err = "Duration " + duration + " is less than or equal to the minimum exclusive value: " + _minExclusive; if (isThereMaxInclusive && duration.isGreater(_maxInclusive)) { String err = "Duration " + duration + " is greater than the maximum allowed value " + _maxInclusive; && ((duration.isGreater(_maxExclusive)) || duration.equals(_maxExclusive))) { String err = "Duration " + duration + " is greater than or equal to the maximum exclusive value: " + _maxExclusive; super.validate(duration.toString(), context);
/** * Creates a new instance of the object described by this field. * * @param parent The object for which the field is created * @return A new instance of the field's value * @throws IllegalStateException This field is a simple type and * cannot be instantiated */ public Object newInstance(Object parent) throws IllegalStateException { return new Duration(); } //-- newInstance
Duration temp = Duration.parseDuration(value.toString()); time.setYear(temp.getYear()); time.setMonth(temp.getMonth()); time.setDay(temp.getDay()); time.setHour(temp.getHour()); time.setMinute(temp.getMinute()); time.setSeconds(temp.getSeconds()); time.setMilli(temp.getMilli()); } catch (java.text.ParseException ex) { throw new IllegalStateException();
/** * Returns true if the instance of TimeDuration has the same fields of the parameter * * @param duration the time duration to compare * @return true if equal, false if not */ public boolean equal(Duration duration) { boolean result = false; if (duration == null) { return result; } result = (_year == duration.getYear()); result = result && (_month == duration.getMonth()); result = result && (_day == duration.getDay()); result = result && (_hour == duration.getHour()); result = result && (_minute == duration.getMinute()); result = result && (_second == duration.getSeconds()); result = result && (_millisecond == duration.getMilli()); result = result && (this.isNegative() == duration.isNegative()); return result; } // equals
result = new Duration(); result.setNegative(); if (idx >= chars.length) { throw new ParseException("'-' is wrongly placed", 0); result.setYear((short) number); hasNumber = false; } else { result.setMinute((short) number); hasNumber = false; } else { result.setMonth((short) number); hasNumber = false; } else { result.setDay((short) number); hasNumber = false; } else { result.setHour((short) number); hasNumber = false; } else { result.setSeconds((short) number); hasNumber = false; } else {
/** * Normalizes a date/time datatype as defined in W3C XML Schema * Recommendation document: if a timeZone is present but it is not Z then we * convert the date/time datatype to Z using the addition operation defined * in <a * href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes"> * Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E).</a> * * @see #addDuration */ public void normalize() { if (!isUTC() || (_zoneHour == 0 && _zoneMinute == 0)) { return; } Duration temp = new Duration(); temp.setHour(_zoneHour); temp.setMinute(_zoneMinute); if (isZoneNegative()) { temp.setNegative(); } this.addDuration(temp); //reset the zone this.setZone((short)0, (short)0); this.setZoneNegative(false); }
if (_fixed != null && !duration.equal(_fixed)) { String err = "Duration " + duration + " is not equal to the fixed value: " + _fixed; throw new ValidationException(err); if (isThereMinInclusive && _minInclusive.isGreater(duration)) { String err = "Duration " + duration + " is less than the minimum allowed value: " + _minInclusive; if (isThereMinExclusive && (_minExclusive.isGreater(duration) || duration.equals(_minExclusive))) { String err = "Duration " + duration + " is less than or equal to the minimum exclusive value: " + _minExclusive; if (isThereMaxInclusive && duration.isGreater(_maxInclusive)) { String err = "Duration " + duration + " is greater than the maximum allowed value " + _maxInclusive; if (isThereMaxExclusive && ((duration.isGreater(_maxExclusive)) || duration.equals(_maxExclusive))) { String err = "Duration " + duration + " is greater than or equal to the maximum exclusive value: " + _maxExclusive; super.validate(duration.toString(), context);
/** * Creates a new instance of the object described by this field. * * @param parent The object for which the field is created * @return A new instance of the field's value * @throws IllegalStateException This field is a simple type and cannot be instantiated */ public Object newInstance(Object parent) throws IllegalStateException { return new Duration(); } // -- newInstance
int temp = 0; int carry = 0; int sign = (duration.isNegative()) ? -1 : 1; temp = _month + sign * duration.getMonth(); carry = fQuotient(temp - 1, 12); this.setMonth((short) (modulo(temp - 1, 12) + 1)); temp = _century * 100 + _year + sign * duration.getYear() + carry; this.setCentury((short) (temp / 100)); this.setYear((short) (temp % 100)); temp = _millsecond + sign * (int)duration.getMilli(); carry = fQuotient(temp, 1000); this.setMilliSecond((short)modulo(temp, 1000)); temp = _second + sign * duration.getSeconds() + carry; carry = fQuotient(temp, 60); this.setSecond((short)modulo(temp , 60)); temp = _minute + sign * duration.getMinute() + carry; carry = fQuotient(temp, 60); this.setMinute((short)modulo(temp , 60)); temp = _hour + sign*duration.getHour() + carry; carry = fQuotient(temp, 24); this.setHour((short)modulo(temp , 24)); tempDay += sign * duration.getDay() + carry;
/** * <p> * Parse the given string and return a time duration which represents this string. * * @param str the string to parse * @return a TimeDuration instance which represent the string * @throws ParseException thrown when the string is not valid */ public static Duration parseDuration(String str) throws ParseException { Duration result = new Duration(); return parseDurationInternal(str, result); }
/** * Returns true if the present instance of TimeDuration is greater than the * parameter * <p> * Note This definition does not follow the XML SCHEMA RECOMMENDATION * 05022001 the following total order relation is used : * <tt>givent t1,t2 timeDuration types * t1>t2 iff t1.toLong()>t2.toLong()</tt> * * @param duration * the time duration to compare with the present instance * @return true if the present instance is the greatest, false if not */ public boolean isGreater(Duration duration) { boolean result = false; // to be optimized ?? result = this.toLong() > duration.toLong(); return result; } //isGreater
/** * {@inheritDoc} */ public Object convert(final Object object) { return new org.exolab.castor.types.Duration(((Long) object).longValue()); }