test/java/time/test/java/time/temporal/MockFieldValue.java

Print this page




  73     private final long value;
  74 
  75     public MockFieldValue(TemporalField field, long value) {
  76         this.field = field;
  77         this.value = value;
  78     }
  79 
  80     @Override
  81     public boolean isSupported(TemporalField field) {
  82         return field != null && field.equals(this.field);
  83     }
  84 
  85     @Override
  86     public ValueRange range(TemporalField field) {
  87         if (field instanceof ChronoField) {
  88             if (isSupported(field)) {
  89                 return field.range();
  90             }
  91             throw new DateTimeException("Unsupported field: " + field.getName());
  92         }
  93         return field.doRange(this);
  94     }
  95 
  96     @Override
  97     public long getLong(TemporalField field) {
  98         if (this.field.equals(field)) {
  99             return value;
 100         }
 101         throw new DateTimeException("Unsupported field: " + field);
 102     }
 103 
 104 }


  73     private final long value;
  74 
  75     public MockFieldValue(TemporalField field, long value) {
  76         this.field = field;
  77         this.value = value;
  78     }
  79 
  80     @Override
  81     public boolean isSupported(TemporalField field) {
  82         return field != null && field.equals(this.field);
  83     }
  84 
  85     @Override
  86     public ValueRange range(TemporalField field) {
  87         if (field instanceof ChronoField) {
  88             if (isSupported(field)) {
  89                 return field.range();
  90             }
  91             throw new DateTimeException("Unsupported field: " + field.getName());
  92         }
  93         return field.rangeRefinedBy(this);
  94     }
  95 
  96     @Override
  97     public long getLong(TemporalField field) {
  98         if (this.field.equals(field)) {
  99             return value;
 100         }
 101         throw new DateTimeException("Unsupported field: " + field);
 102     }
 103 
 104 }