< prev index next >

## src/java.base/share/classes/java/time/temporal/ValueRange.java

Print this page

    337         if (isValidIntValue(value) == false) {
    338             throw new DateTimeException(genInvalidFieldMessage(field, value));
    339         }
    340         return (int) value;
    341     }
    342
    343     private String genInvalidFieldMessage(TemporalField field, long value) {
    344         if (field != null) {
    345             return "Invalid value for " + field + " (valid values " + this + "): " + value;
    346         } else {
    347             return "Invalid value (valid values " + this + "): " + value;
    348         }
    349     }
    350
    351     //-----------------------------------------------------------------------
    352     /**
    353      * Restore the state of an ValueRange from the stream.
    354      * Check that the values are valid.
    355      *
    356      * @param s the stream to read

    357      * @throws InvalidObjectException if
    358      *     the smallest minimum is greater than the smallest maximum,
    359      *  or the smallest maximum is greater than the largest maximum
    360      *  or the largest minimum is greater than the largest maximum
    361      * @throws ClassNotFoundException if a class cannot be resolved
    362      */
    363     @java.io.Serial
    364     private void readObject(ObjectInputStream s)
    365          throws IOException, ClassNotFoundException, InvalidObjectException
    366     {
    367         s.defaultReadObject();
    368         if (minSmallest > minLargest) {
    369             throw new InvalidObjectException("Smallest minimum value must be less than largest minimum value");
    370         }
    371         if (maxSmallest > maxLargest) {
    372             throw new InvalidObjectException("Smallest maximum value must be less than largest maximum value");
    373         }
    374         if (minLargest > maxLargest) {
    375             throw new InvalidObjectException("Minimum value must be less than maximum value");
    376         }
    337         if (isValidIntValue(value) == false) {
    338             throw new DateTimeException(genInvalidFieldMessage(field, value));
    339         }
    340         return (int) value;
    341     }
    342
    343     private String genInvalidFieldMessage(TemporalField field, long value) {
    344         if (field != null) {
    345             return "Invalid value for " + field + " (valid values " + this + "): " + value;
    346         } else {
    347             return "Invalid value (valid values " + this + "): " + value;
    348         }
    349     }
    350
    351     //-----------------------------------------------------------------------
    352     /**
    353      * Restore the state of an ValueRange from the stream.
    354      * Check that the values are valid.
    355      *
    356      * @param s the stream to read
    357      * @throws IOException if an I/O error occurs
    358      * @throws InvalidObjectException if
    359      *     the smallest minimum is greater than the smallest maximum,
    360      *  or the smallest maximum is greater than the largest maximum
    361      *  or the largest minimum is greater than the largest maximum
    362      * @throws ClassNotFoundException if a class cannot be resolved
    363      */
    364     @java.io.Serial
    365     private void readObject(ObjectInputStream s)
    366          throws IOException, ClassNotFoundException, InvalidObjectException
    367     {
    368         s.defaultReadObject();
    369         if (minSmallest > minLargest) {
    370             throw new InvalidObjectException("Smallest minimum value must be less than largest minimum value");
    371         }
    372         if (maxSmallest > maxLargest) {
    373             throw new InvalidObjectException("Smallest maximum value must be less than largest maximum value");
    374         }
    375         if (minLargest > maxLargest) {
    376             throw new InvalidObjectException("Minimum value must be less than maximum value");
    377         }

< prev index next >