/* * <p>Turns {@link BigDecimal} to a string representation.</p> * * <p>Due to a behavior change in the {@link BigDecimal#toString()} * method in JDK1.5, this had to be implemented here.</p> * * @param bd <code>BigDecimal</code> to format as a <code>String</code> * * @return <code>String</code> representation of <code>BigDecimal</code> */ private String toString(java.math.BigDecimal bd) { String intString = bd.unscaledValue().toString(); int scale = bd.scale(); if (scale == 0) { return(intString); } /* Insert decimal point */ java.lang.StringBuffer buf; int insertionPoint = intString.length() - scale; if (insertionPoint == 0) { /* Point goes right before intVal */ return("0." + intString); } else if (insertionPoint > 0) { /* Point goes inside intVal */ buf = new java.lang.StringBuffer(intString); buf.insert(insertionPoint, '.'); } else { /* We must insert zeros between point and intVal */ buf = new java.lang.StringBuffer(3 - insertionPoint + intString.length()); buf.append("0."); for (int i = 0; i < -insertionPoint; i++) { buf.append('0'); } buf.append(intString); } return(buf.toString()); }
/** * <p>Set time as one unit, including the optional infinite precision * fractional seconds.</p> * * @param hour value constraints are summarized in * <a href="#datetimefield-hour">hour field of date/time field mapping table</a>. * @param minute value constraints are summarized in * <a href="#datetimefield-minute">minute field of date/time field mapping table</a>. * @param second value constraints are summarized in * <a href="#datetimefield-second">second field of date/time field mapping table</a>. * @param fractional value of <code>null</code> indicates this optional * field is not set. * * @throws IllegalArgumentException if any parameter is * outside value constraints for the field as specified in * <a href="#datetimefieldmapping">date/time field mapping table</a>. */ public virtual void setTime( int hour, int minute, int second, java.math.BigDecimal fractional) { setHour(hour); setMinute(minute); setSecond(second); setFractionalSecond(fractional); }
/** * <p>Return millisecond precision of {@link #getFractionalSecond()}.</p> * * <p>This method represents a convenience accessor to infinite * precision fractional second value returned by * {@link #getFractionalSecond()}. The returned value is the rounded * down to milliseconds value of * {@link #getFractionalSecond()}. When {@link #getFractionalSecond()} * returns <code>null</code>, this method must return * {@link DatatypeConstants#FIELD_UNDEFINED}.</p> * * <p>Value constraints for this value are summarized in * <a href="#datetimefield-second">second field of date/time field mapping table</a>.</p> * * @return Millisecond of this <code>XMLGregorianCalendar</code>. * * @see #getFractionalSecond() * @see #setTime(int, int, int) */ public virtual int getMillisecond() { java.math.BigDecimal fractionalSeconds = getFractionalSecond(); // is field undefined? if (fractionalSeconds == null) { return(DatatypeConstants.FIELD_UNDEFINED); } return(getFractionalSecond().movePointRight(3).intValue()); }
/* * Returns a hash code consistent with the definition of the equals method. * * @see Object#hashCode() */ // default method not twice declared //public abstract int GetHashCode(); /* * <p>Returns a <code>String</code> representation of this <code>Duration</code> <code>Object</code>.</p> * * <p>The result is formatted according to the XML Schema 1.0 spec and can be always parsed back later into the * equivalent <code>Duration</code> <code>Object</code> by {@link DatatypeFactory#newDuration(String lexicalRepresentation)}.</p> * * <p>Formally, the following holds for any <code>Duration</code> * <code>Object</code> x:</p> * <pre> * new Duration(x.toString()).equals(x) * </pre> * * @return A non-<code>null</code> valid <code>String</code> representation of this <code>Duration</code>. */ public override String ToString() { java.lang.StringBuffer buf = new java.lang.StringBuffer(); if (getSign() < 0) { buf.append('-'); } buf.append('P'); java.math.BigInteger years = (java.math.BigInteger)getField(DatatypeConstants.YEARS); if (years != null) { buf.append(years + "Y"); } java.math.BigInteger months = (java.math.BigInteger)getField(DatatypeConstants.MONTHS); if (months != null) { buf.append(months + "M"); } java.math.BigInteger days = (java.math.BigInteger)getField(DatatypeConstants.DAYS); if (days != null) { buf.append(days + "D"); } java.math.BigInteger hours = (java.math.BigInteger)getField(DatatypeConstants.HOURS); java.math.BigInteger minutes = (java.math.BigInteger)getField(DatatypeConstants.MINUTES); java.math.BigDecimal seconds = (java.math.BigDecimal)getField(DatatypeConstants.SECONDS); if (hours != null || minutes != null || seconds != null) { buf.append('T'); if (hours != null) { buf.append(hours + "H"); } if (minutes != null) { buf.append(minutes + "M"); } if (seconds != null) { buf.append(toString(seconds) + "S"); } } return(buf.toString()); }
/** * <p>Set fractional seconds.</p> * * <p>Unset this field by invoking the setter with a parameter value of <code>null</code>.</p> * * @param fractional value constraints summarized in * <a href="#datetimefield-fractional">fractional field of date/time field mapping table</a>. * * @throws IllegalArgumentException if <code>fractional</code> parameter is outside value constraints for the field as specified * in <a href="#datetimefieldmapping">date/time field mapping table</a>. */ public abstract void setFractionalSecond(java.math.BigDecimal fractional);
public void setBigDecimal(int parameterIndex, java.math.BigDecimal inputValue) //throws SQLException { setString(parameterIndex, inputValue.toString()); }
/* * Computes a new duration whose value is <code>factor</code> times * longer than the value of this duration. * * <p/> * For example, * <pre> * "P1M" (1 month) * "12" = "P12M" (12 months) * "PT1M" (1 min) * "0.3" = "PT18S" (18 seconds) * "P1M" (1 month) * "1.5" = IllegalStateException * </pre> * * <p/> * Since the <code>Duration</code> class is immutable, this method * doesn't change the value of this object. It simply computes * a new Duration object and returns it. * * <p> * The operation will be performed field by field with the precision * of {@link BigDecimal}. Since all the fields except seconds are * restricted to hold integers, * any fraction produced by the computation will be * carried down toward the next lower unit. For example, * if you multiply "P1D" (1 day) with "0.5", then it will be 0.5 day, * which will be carried down to "PT12H" (12 hours). * When fractions of month cannot be meaningfully carried down * to days, or year to months, this will cause an * {@link IllegalStateException} to be thrown. * For example if you multiple one month by 0.5.</p> * * <p/> * To avoid {@link IllegalStateException}, use * the {@link #normalizeWith(Calendar)} method to remove the years * and months fields. * * @param factor to multiply by * * @return * returns a non-null valid <code>Duration</code> object * * @throws IllegalStateException if operation produces fraction in * the months field. * * @throws NullPointerException if the <code>factor</code> parameter is * <code>null</code>. * */ public abstract Duration multiply(java.math.BigDecimal factor);