/** * Create a new instance of the size value that only contains a type. This only works for types that allow to be * used without value. * * @param type the type * @throws java.lang.IllegalArgumentException in case the type requires a value * @see SizeValueType#getValueRequirement() */ public SizeValue(@Nonnull final SizeValueType type) { if (type.getValueRequirement() == SizeValueType.ValueRequirement.Required) { throw new IllegalArgumentException("Size value type " + type.name() + " requires a value!"); } this.type = type; value = 0.0f; hasValue = false; hasCalculatedValue = false; }
/** * Create a new instance of the size value that contains a value and a type. This only works for types that allow a * fixed set value. * * @param value the value * @param type the type * @throws java.lang.IllegalArgumentException in case the type forbids the usage of a value or only accepts a * calculated value * @see SizeValueType#getValueRequirement() */ public SizeValue(final int value, @Nonnull final SizeValueType type) { switch (type.getValueRequirement()) { case Forbidden: throw new IllegalArgumentException("Size value type " + type.name() + " does not allow a value."); case CalculatedOnly: throw new IllegalArgumentException("Size value type " + type.name() + " does only allow calculated values"); } this.type = type; this.value = value; hasValue = true; hasCalculatedValue = false; }
/** * Create a new instance of a size value that contains a computed value and a type. This only works for values that * do not require a fixed value and allow a computed value. * * @param type the type * @param calculatedValue the computed value * @throws java.lang.IllegalArgumentException in case the type forbids the usage of values or requires a fixed set * value * * @see SizeValueType#getValueRequirement() */ public SizeValue(@Nonnull final SizeValueType type, final int calculatedValue) { switch (type.getValueRequirement()) { case Forbidden: throw new IllegalArgumentException("Size value type " + type.name() + " does not allow a value."); case Required: throw new IllegalArgumentException("Size value type " + type.name() + " requires a value!"); } this.type = type; this.value = calculatedValue; hasValue = false; hasCalculatedValue = true; }
switch (type.getValueRequirement()) { case CalculatedOnly: throw new IllegalArgumentException("Setting the value by string is not allowed for types that only allow " + if (type.getValueRequirement() == SizeValueType.ValueRequirement.Required) { throw new IllegalArgumentException("Size value type " + type.name() + " requires a value!");