Пример #1
0
 public NaturalField(@NotNull NumberFieldInfo<Type> fieldInfo) {
   super(fieldInfo.getWidth());
   fieldUpdater = (value) -> {};
   type = fieldInfo.getType();
   @Nullable Class<?> fieldType = getClass();
   if (fieldType == null) {
     throw new ZeusRuntimeException("NaturalField: illegal field type");
   }
   numberMatcher = FieldUtils.getNumberMatcher(fieldType);
   zeroEqualMatcher = FieldUtils.getZeroEqualMatcher(fieldType);
   setListener();
 }
 public long set(long instant, int value) {
   int max = getMaximumValue();
   FieldUtils.verifyValueBounds(this, value, 1, max);
   if (value == max) {
     value = 0;
   }
   return getWrappedField().set(instant, value);
 }
Пример #3
0
 @NotNull
 private ChangeListener<String> prepareAddListener() {
   @NotNull Function<String, ?> typeCaster = FieldUtils.getTypeCaster(type);
   return (observableValue, oldValue, newValue) -> {
     if (isCorrect(newValue)) {
       if (isZeroEqual(newValue)) {
         newValue = "0";
       }
       Type fieldValue = convertFieldValue(newValue, typeCaster);
       fieldUpdater.accept(fieldValue);
     } else {
       setText(oldValue);
     }
   };
 }
Пример #4
0
 public int getValue(long duration, long instant) {
   return FieldUtils.safeToInt(duration);
 }
Пример #5
0
 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
   return FieldUtils.safeSubtract(minuendInstant, subtrahendInstant);
 }
Пример #6
0
 public int getDifference(long minuendInstant, long subtrahendInstant) {
   return FieldUtils.safeToInt(FieldUtils.safeSubtract(minuendInstant, subtrahendInstant));
 }
Пример #7
0
 public long add(long instant, long value) {
   return FieldUtils.safeAdd(instant, value);
 }
Пример #8
0
 /**
  * Set the specified amount of offset units to the specified time instant.
  *
  * @param instant the time instant in millis to update.
  * @param value value of units to set.
  * @return the updated time instant.
  * @throws IllegalArgumentException if value is too large or too small.
  */
 public long set(long instant, int value) {
   FieldUtils.verifyValueBounds(this, value, iMin, iMax);
   return super.set(instant, value - iOffset);
 }
Пример #9
0
 /**
  * Add to the offset component of the specified time instant, wrapping around within that
  * component if necessary.
  *
  * @param instant the time instant in millis to update.
  * @param amount the amount of units to add (can be negative).
  * @return the updated time instant.
  */
 public long addWrapField(long instant, int amount) {
   return set(instant, FieldUtils.getWrappedValue(get(instant), amount, iMin, iMax));
 }
Пример #10
0
 /**
  * Add the specified amount of offset units to the specified time instant. The amount added may be
  * negative.
  *
  * @param instant the time instant in millis to update.
  * @param amount the amount of units to add (can be negative).
  * @return the updated time instant.
  */
 public long add(long instant, long amount) {
   instant = super.add(instant, amount);
   FieldUtils.verifyValueBounds(this, get(instant), iMin, iMax);
   return instant;
 }
 public long add(long instant, long value) {
   long addition = FieldUtils.safeMultiply(value, iUnitMillis);
   return FieldUtils.safeAdd(instant, addition);
 }
 public long add(long instant, int value) {
   long addition = value * iUnitMillis; // safe
   return FieldUtils.safeAdd(instant, addition);
 }
 /**
  * Get the millisecond duration of this field from its value.
  *
  * @param value the value of the field, which may be negative
  * @param instant ignored
  * @return the milliseconds that the field represents, which may be negative
  */
 public long getMillis(long value, long instant) {
   return FieldUtils.safeMultiply(value, iUnitMillis);
 }
 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
   long difference = FieldUtils.safeSubtract(minuendInstant, subtrahendInstant);
   return difference / iUnitMillis;
 }
Пример #15
0
 public long add(long instant, long value) {
   long scaled = FieldUtils.safeMultiply(value, iScalar);
   return getWrappedField().add(instant, scaled);
 }
Пример #16
0
 public long getMillis(long value, long instant) {
   long scaled = FieldUtils.safeMultiply(value, iScalar);
   return getWrappedField().getMillis(scaled, instant);
 }