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); }
@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); } }; }
public int getValue(long duration, long instant) { return FieldUtils.safeToInt(duration); }
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { return FieldUtils.safeSubtract(minuendInstant, subtrahendInstant); }
public int getDifference(long minuendInstant, long subtrahendInstant) { return FieldUtils.safeToInt(FieldUtils.safeSubtract(minuendInstant, subtrahendInstant)); }
public long add(long instant, long value) { return FieldUtils.safeAdd(instant, value); }
/** * 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); }
/** * 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)); }
/** * 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; }
public long add(long instant, long value) { long scaled = FieldUtils.safeMultiply(value, iScalar); return getWrappedField().add(instant, scaled); }
public long getMillis(long value, long instant) { long scaled = FieldUtils.safeMultiply(value, iScalar); return getWrappedField().getMillis(scaled, instant); }