コード例 #1
0
ファイル: BaseChronology.java プロジェクト: syntelos/gap-data
 /**
  * Validates whether the fields stored in a partial instant are valid.
  *
  * <p>This implementation uses {@link DateTimeField#getMinimumValue(ReadablePartial, int[])} and
  * {@link DateTimeField#getMaximumValue(ReadablePartial, int[])}.
  *
  * @param partial the partial instant to validate
  * @param values the values to validate, not null
  * @throws IllegalArgumentException if the instant is invalid
  */
 public void validate(ReadablePartial partial, int[] values) {
   // check values in standard range, catching really stupid cases like -1
   // this means that the second check will not hit trouble
   int size = partial.size();
   for (int i = 0; i < size; i++) {
     int value = values[i];
     DateTimeField field = partial.getField(i);
     if (value < field.getMinimumValue()) {
       throw new IllegalFieldValueException(
           field.getType(), new Integer(value), new Integer(field.getMinimumValue()), null);
     }
     if (value > field.getMaximumValue()) {
       throw new IllegalFieldValueException(
           field.getType(), new Integer(value), null, new Integer(field.getMaximumValue()));
     }
   }
   // check values in specific range, catching really odd cases like 30th Feb
   for (int i = 0; i < size; i++) {
     int value = values[i];
     DateTimeField field = partial.getField(i);
     if (value < field.getMinimumValue(partial, values)) {
       throw new IllegalFieldValueException(
           field.getType(),
           new Integer(value),
           new Integer(field.getMinimumValue(partial, values)),
           null);
     }
     if (value > field.getMaximumValue(partial, values)) {
       throw new IllegalFieldValueException(
           field.getType(),
           new Integer(value),
           null,
           new Integer(field.getMaximumValue(partial, values)));
     }
   }
 }
 public int getMinimumValue(ReadablePartial instant, int[] values) {
   return iField.getMinimumValue(instant, values);
 }
 public int getMinimumValue(ReadablePartial instant) {
   return iField.getMinimumValue(instant);
 }
 public int getMinimumValue(long instant) {
   long localInstant = iZone.convertUTCToLocal(instant);
   return iField.getMinimumValue(localInstant);
 }
 public int getMinimumValue() {
   return iField.getMinimumValue();
 }
コード例 #6
0
 /**
  * Constructor.
  *
  * @param field the base field
  * @param type the field type this field will actually use
  * @throws IllegalArgumentException if wrapped field's minimum value is not zero
  */
 public ZeroIsMaxDateTimeField(DateTimeField field, DateTimeFieldType type) {
   super(field, type);
   if (field.getMinimumValue() != 0) {
     throw new IllegalArgumentException("Wrapped field's minumum value must be zero");
   }
 }
コード例 #7
0
 /** Tests the dayOfMonth DateTimeField */
 @Test
 public void testDayOfMonthField() {
   DateTimeField dayOfMonthField = CHRON_NOLEAP.dayOfMonth();
   assertEquals(1, dayOfMonthField.getMinimumValue());
   assertEquals(31, dayOfMonthField.getMaximumValue());
 }