com.sun.org.apache.xerces.internal.util.DatatypeMessageFormatter Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.util.DatatypeMessageFormatter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMLGregorianCalendarImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional.toString()}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example #2
Source File: DurationImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #3
Source File: DurationImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #4
Source File: DurationImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #5
Source File: DurationImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #6
Source File: DurationImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #7
Source File: DurationImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #8
Source File: XMLGregorianCalendarImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example #9
Source File: DurationImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #10
Source File: DurationImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #11
Source File: DurationImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #12
Source File: DurationImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #13
Source File: XMLGregorianCalendarImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example #14
Source File: XMLGregorianCalendarImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Private constructor allowing for complete value spaces allowed by
 * W3C XML Schema 1.0 recommendation for xsd:dateTime and related
 * builtin datatypes. Note that <code>year</code> parameter supports
 * arbitrarily large numbers and fractionalSecond has infinite
 * precision.</p>
 *
 * @param year of <code>XMLGregorianCalendar</code> to be created.
 * @param month of <code>XMLGregorianCalendar</code> to be created.
 * @param day of <code>XMLGregorianCalendar</code> to be created.
 * @param hour of <code>XMLGregorianCalendar</code> to be created.
 * @param minute of <code>XMLGregorianCalendar</code> to be created.
 * @param second of <code>XMLGregorianCalendar</code> to be created.
 * @param fractionalSecond of <code>XMLGregorianCalendar</code> to be created.
 * @param timezone of <code>XMLGregorianCalendar</code> to be created.
 *
 */
protected XMLGregorianCalendarImpl(
    BigInteger year,
    int month,
    int day,
    int hour,
    int minute,
    int second,
    BigDecimal fractionalSecond,
    int timezone) {

    setYear(year);
    setMonth(month);
    setDay(day);
    setTime(hour, minute, second, fractionalSecond);
    setTimezone(timezone);

    // check for validity
    if (!isValid()) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null,
                "InvalidXGCValue-fractional",
                new Object[] { year, month, day,
                hour, minute, second,
                fractionalSecond, timezone})
                    );
    }

    save();
}
 
Example #15
Source File: DurationImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #16
Source File: DurationImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #17
Source File: DurationImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #18
Source File: DurationImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #19
Source File: DurationImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #20
Source File: DurationImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #21
Source File: DurationImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #22
Source File: DurationImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #23
Source File: DurationImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #24
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional.toString()}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example #25
Source File: DurationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #26
Source File: DurationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigInteger n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {
        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #27
Source File: DurationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Makes sure that the given number is non-negative. If it is not,
 * throw {@link IllegalArgumentException}.</p>
 *
 * @param n Number to test.
 * @param f Field to test.
 */
protected static void testNonNegative(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example #28
Source File: DurationImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Constructs a new Duration object by specifying each field individually.</p>
 *
 * <p>All the parameters are optional as long as at least one field is present.
 * If specified, parameters have to be zero or positive.</p>
 *
 * @param isPositive Set to <code>false</code> to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this <code>Duration</code>
 * @param months of this <code>Duration</code>
 * @param days of this <code>Duration</code>
 * @param hours of this <code>Duration</code>
 * @param minutes of this <code>Duration</code>
 * @param seconds of this <code>Duration</code>
 *
 * @throws IllegalArgumentException
 *    If years, months, days, hours, minutes and
 *    seconds parameters are all <code>null</code>. Or if any
 *    of those parameters are negative.
 */
protected DurationImpl(
    boolean isPositive,
    BigInteger years,
    BigInteger months,
    BigInteger days,
    BigInteger hours,
    BigInteger minutes,
    BigDecimal seconds) {

    this.years = years;
    this.months = months;
    this.days = days;
    this.hours = hours;
    this.minutes = minutes;
    this.seconds = seconds;

    this.signum = calcSignum(isPositive);

    // sanity check
    if (years == null
        && months == null
        && days == null
        && hours == null
        && minutes == null
        && seconds == null) {
        throw new IllegalArgumentException(
        //"all the fields are null"
        DatatypeMessageFormatter.formatMessage(null, "AllFieldsNull", null)
        );
    }
    testNonNegative(years, DatatypeConstants.YEARS);
    testNonNegative(months, DatatypeConstants.MONTHS);
    testNonNegative(days, DatatypeConstants.DAYS);
    testNonNegative(hours, DatatypeConstants.HOURS);
    testNonNegative(minutes, DatatypeConstants.MINUTES);
    testNonNegative(seconds, DatatypeConstants.SECONDS);
}
 
Example #29
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional}));
        }
    }
    this.fractionalSecond = fractional;
}
 
Example #30
Source File: XMLGregorianCalendarImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void setFractionalSecond(BigDecimal fractional) {
    if (fractional != null) {
        if ((fractional.compareTo(DECIMAL_ZERO) < 0) ||
                (fractional.compareTo(DECIMAL_ONE) > 0)) {
            throw new IllegalArgumentException(DatatypeMessageFormatter.formatMessage(null,
                    "InvalidFractional", new Object[]{fractional}));
        }
    }
    this.fractionalSecond = fractional;
}