75 * This class captures that valid range.
76 * <p>
77 * It is important to be aware of the limitations of this class.
78 * Only the minimum and maximum values are provided.
79 * It is possible for there to be invalid values within the outer range.
80 * For example, a weird field may have valid values of 1, 2, 4, 6, 7, thus
81 * have a range of '1 - 7', despite that fact that values 3 and 5 are invalid.
82 * <p>
83 * Instances of this class are not tied to a specific field.
84 *
85 * @implSpec
86 * This class is immutable and thread-safe.
87 *
88 * @since 1.8
89 */
90 public final class ValueRange implements Serializable {
91
92 /**
93 * Serialization version.
94 */
95 private static final long serialVersionUID = -7317881728594519368L;
96
97 /**
98 * The smallest minimum value.
99 */
100 private final long minSmallest;
101 /**
102 * The largest minimum value.
103 */
104 private final long minLargest;
105 /**
106 * The smallest maximum value.
107 */
108 private final long maxSmallest;
109 /**
110 * The largest maximum value.
111 */
112 private final long maxLargest;
113
114 /**
335 private String genInvalidFieldMessage(TemporalField field, long value) {
336 if (field != null) {
337 return "Invalid value for " + field + " (valid values " + this + "): " + value;
338 } else {
339 return "Invalid value (valid values " + this + "): " + value;
340 }
341 }
342
343 //-----------------------------------------------------------------------
344 /**
345 * Restore the state of an ValueRange from the stream.
346 * Check that the values are valid.
347 *
348 * @param s the stream to read
349 * @throws InvalidObjectException if
350 * the smallest minimum is greater than the smallest maximum,
351 * or the smallest maximum is greater than the largest maximum
352 * or the largest minimum is greater than the largest maximum
353 * @throws ClassNotFoundException if a class cannot be resolved
354 */
355 private void readObject(ObjectInputStream s)
356 throws IOException, ClassNotFoundException, InvalidObjectException
357 {
358 s.defaultReadObject();
359 if (minSmallest > minLargest) {
360 throw new InvalidObjectException("Smallest minimum value must be less than largest minimum value");
361 }
362 if (maxSmallest > maxLargest) {
363 throw new InvalidObjectException("Smallest maximum value must be less than largest maximum value");
364 }
365 if (minLargest > maxLargest) {
366 throw new InvalidObjectException("Minimum value must be less than maximum value");
367 }
368 }
369
370 //-----------------------------------------------------------------------
371 /**
372 * Checks if this range is equal to another range.
373 * <p>
374 * The comparison is based on the four values, minimum, largest minimum,
|
75 * This class captures that valid range.
76 * <p>
77 * It is important to be aware of the limitations of this class.
78 * Only the minimum and maximum values are provided.
79 * It is possible for there to be invalid values within the outer range.
80 * For example, a weird field may have valid values of 1, 2, 4, 6, 7, thus
81 * have a range of '1 - 7', despite that fact that values 3 and 5 are invalid.
82 * <p>
83 * Instances of this class are not tied to a specific field.
84 *
85 * @implSpec
86 * This class is immutable and thread-safe.
87 *
88 * @since 1.8
89 */
90 public final class ValueRange implements Serializable {
91
92 /**
93 * Serialization version.
94 */
95 @java.io.Serial
96 private static final long serialVersionUID = -7317881728594519368L;
97
98 /**
99 * The smallest minimum value.
100 */
101 private final long minSmallest;
102 /**
103 * The largest minimum value.
104 */
105 private final long minLargest;
106 /**
107 * The smallest maximum value.
108 */
109 private final long maxSmallest;
110 /**
111 * The largest maximum value.
112 */
113 private final long maxLargest;
114
115 /**
336 private String genInvalidFieldMessage(TemporalField field, long value) {
337 if (field != null) {
338 return "Invalid value for " + field + " (valid values " + this + "): " + value;
339 } else {
340 return "Invalid value (valid values " + this + "): " + value;
341 }
342 }
343
344 //-----------------------------------------------------------------------
345 /**
346 * Restore the state of an ValueRange from the stream.
347 * Check that the values are valid.
348 *
349 * @param s the stream to read
350 * @throws InvalidObjectException if
351 * the smallest minimum is greater than the smallest maximum,
352 * or the smallest maximum is greater than the largest maximum
353 * or the largest minimum is greater than the largest maximum
354 * @throws ClassNotFoundException if a class cannot be resolved
355 */
356 @java.io.Serial
357 private void readObject(ObjectInputStream s)
358 throws IOException, ClassNotFoundException, InvalidObjectException
359 {
360 s.defaultReadObject();
361 if (minSmallest > minLargest) {
362 throw new InvalidObjectException("Smallest minimum value must be less than largest minimum value");
363 }
364 if (maxSmallest > maxLargest) {
365 throw new InvalidObjectException("Smallest maximum value must be less than largest maximum value");
366 }
367 if (minLargest > maxLargest) {
368 throw new InvalidObjectException("Minimum value must be less than maximum value");
369 }
370 }
371
372 //-----------------------------------------------------------------------
373 /**
374 * Checks if this range is equal to another range.
375 * <p>
376 * The comparison is based on the four values, minimum, largest minimum,
|