Java Code Examples for javax.xml.datatype.DatatypeConstants#Field

The following examples show how to use javax.xml.datatype.DatatypeConstants#Field . 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: DurationImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Gets the value of the field as a {@link BigDecimal}.</p>
 *
 * <p>If the field is unset, return 0.</p>
 *
 * @param f Field to get value for.
 *
 * @return  non-null valid {@link BigDecimal}.
 */
private BigDecimal getFieldAsBigDecimal(DatatypeConstants.Field f) {
    if (f == DatatypeConstants.SECONDS) {
        if (seconds != null) {
            return seconds;
        } else {
            return ZERO;
        }
    } else {
        BigInteger bi = (BigInteger) getField(f);
        if (bi == null) {
            return ZERO;
        } else {
            return new BigDecimal(bi);
        }
    }
}
 
Example 2
Source File: DurationImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Gets the value of the field as a {@link BigDecimal}.</p>
 *
 * <p>If the field is unset, return 0.</p>
 *
 * @param f Field to get value for.
 *
 * @return  non-null valid {@link BigDecimal}.
 */
private BigDecimal getFieldAsBigDecimal(DatatypeConstants.Field f) {
    if (f == DatatypeConstants.SECONDS) {
        if (seconds != null) {
            return seconds;
        } else {
            return ZERO;
        }
    } else {
        BigInteger bi = (BigInteger) getField(f);
        if (bi == null) {
            return ZERO;
        } else {
            return new BigDecimal(bi);
        }
    }
}
 
Example 3
Source File: DurationImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Gets the value of the field as a {@link BigDecimal}.</p>
 *
 * <p>If the field is unset, return 0.</p>
 *
 * @param f Field to get value for.
 *
 * @return  non-null valid {@link BigDecimal}.
 */
private BigDecimal getFieldAsBigDecimal(DatatypeConstants.Field f) {
    if (f == DatatypeConstants.SECONDS) {
        if (seconds != null) {
            return seconds;
        } else {
            return ZERO;
        }
    } else {
        BigInteger bi = (BigInteger) getField(f);
        if (bi == null) {
            return ZERO;
        } else {
            return new BigDecimal(bi);
        }
    }
}
 
Example 4
Source File: DurationImpl.java    From hottub 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 5
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 6
Source File: DurationImpl.java    From TencentKona-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(BigDecimal 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-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 8
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 9
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 10
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 11
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 12
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 13
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 14
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(BigDecimal n, DatatypeConstants.Field f) {
    if (n != null && n.signum() < 0) {

        throw new IllegalArgumentException(
            DatatypeMessageFormatter.formatMessage(null, "NegativeField", new Object[]{f.toString()})
        );
    }
}
 
Example 15
Source File: DurationImpl.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Return the requested field value as an int.</p>
 *
 * <p>If field is not set, i.e. == null, 0 is returned.</p>
 *
 * @param field To get value for.
 *
 * @return int value of field or 0 if field is not set.
 */
private int getInt(DatatypeConstants.Field field) {
    Number n = getField(field);
    if (n == null) {
        return 0;
    } else {
        return n.intValue();
    }
}
 
Example 16
Source File: DurationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Return the requested field value as an int.</p>
 *
 * <p>If field is not set, i.e. == null, 0 is returned.</p>
 *
 * @param field To get value for.
 *
 * @return int value of field or 0 if field is not set.
 */
private int getInt(DatatypeConstants.Field field) {
    Number n = getField(field);
    if (n == null) {
        return 0;
    } else {
        return n.intValue();
    }
}
 
Example 17
Source File: DurationImpl.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Return the requested field value as an int.</p>
 *
 * <p>If field is not set, i.e. == null, 0 is returned.</p>
 *
 * @param field To get value for.
 *
 * @return int value of field or 0 if field is not set.
 */
private int getInt(DatatypeConstants.Field field) {
    Number n = getField(field);
    if (n == null) {
        return 0;
    } else {
        return n.intValue();
    }
}
 
Example 18
Source File: DurationImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Partial order relation comparison with this <code>Duration</code> instance.</p>
 *
 * <p>Comparison result must be in accordance with
 * <a href="http://www.w3.org/TR/xmlschema-2/#duration-order">W3C XML Schema 1.0 Part 2, Section 3.2.7.6.2,
 * <i>Order relation on duration</i></a>.</p>
 *
 * <p>Return:</p>
 * <ul>
 *   <li>{@link DatatypeConstants#LESSER} if this <code>Duration</code> is shorter than <code>duration</code> parameter</li>
 *   <li>{@link DatatypeConstants#EQUAL} if this <code>Duration</code> is equal to <code>duration</code> parameter</li>
 *   <li>{@link DatatypeConstants#GREATER} if this <code>Duration</code> is longer than <code>duration</code> parameter</li>
 *   <li>{@link DatatypeConstants#INDETERMINATE} if a conclusive partial order relation cannot be determined</li>
 * </ul>
 *
 * @param duration to compare
 *
 * @return the relationship between <code>this</code> <code>Duration</code>and <code>duration</code> parameter as
 *   {@link DatatypeConstants#LESSER}, {@link DatatypeConstants#EQUAL}, {@link DatatypeConstants#GREATER}
 *   or {@link DatatypeConstants#INDETERMINATE}.
 *
 * @throws UnsupportedOperationException If the underlying implementation
 *   cannot reasonably process the request, e.g. W3C XML Schema allows for
 *   arbitrarily large/small/precise values, the request may be beyond the
 *   implementations capability.
 * @throws NullPointerException if <code>duration</code> is <code>null</code>.
 *
 * @see #isShorterThan(Duration)
 * @see #isLongerThan(Duration)
 */
public int compare(Duration rhs) {
    /** check if any field in the Durations is too large for the operation
     * that uses XMLGregorianCalendar for comparison
    */
    for (DatatypeConstants.Field field : FIELDS) {
        checkMaxValue(getField(field), field);
        checkMaxValue(rhs.getField(field), field);
    }

    return compareDates(this, rhs);
}
 
Example 19
Source File: DurationImpl.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Return the requested field value as an int.</p>
 *
 * <p>If field is not set, i.e. == null, 0 is returned.</p>
 *
 * @param field To get value for.
 *
 * @return int value of field or 0 if field is not set.
 */
private int getInt(DatatypeConstants.Field field) {
    Number n = getField(field);
    if (n == null) {
        return 0;
    } else {
        return n.intValue();
    }
}
 
Example 20
Source File: DurationImpl.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Return the requested field value as an int.</p>
 *
 * <p>If field is not set, i.e. == null, 0 is returned.</p>
 *
 * @param field To get value for.
 *
 * @return int value of field or 0 if field is not set.
 */
private int getInt(DatatypeConstants.Field field) {
    Number n = getField(field);
    if (n == null) {
        return 0;
    } else {
        return n.intValue();
    }
}