/** * Constructs an instance of <code>ConstantSize</code> from the given * encoded size and unit description. * * @param encodedValueAndUnit * the size's value and unit as string * @param horizontal * true for horizontal, false for vertical * @return a constant size for the given encoding and unit description * @throws IllegalArgumentException * if the unit requires integer but the value is not an integer */ static ConstantSize valueOf(String encodedValueAndUnit, boolean horizontal) { String split[] = ConstantSize.splitValueAndUnit(encodedValueAndUnit); String encodedValue = split[0]; String encodedUnit = split[1]; Unit unit = Unit.valueOf(encodedUnit, horizontal); double value = Double.parseDouble(encodedValue); if (unit.requiresIntegers) { if (value != (int) value) throw new IllegalArgumentException(unit.toString() + " value " + encodedValue + " must be an integer."); } return new ConstantSize(value, unit); }
/** * Creates and returns a ConstantSize from the given encoded size * and unit description. * * @param encodedValueAndUnit the size's value and unit as string, * trimmed and in lower case * @param horizontal true for horizontal, false for vertical * @return a constant size for the given encoding and unit description * * @throws IllegalArgumentException if the unit requires integer * but the value is not an integer */ static ConstantSize valueOf(String encodedValueAndUnit, boolean horizontal) { String[] split = ConstantSize.splitValueAndUnit(encodedValueAndUnit); String encodedValue = split[0]; String encodedUnit = split[1]; Unit unit = Unit.valueOf(encodedUnit, horizontal); double value = Double.parseDouble(encodedValue); if (unit.requiresIntegers) { if (value != (int) value) throw new IllegalArgumentException(unit.toString() + " value " + encodedValue + " must be an integer."); } return new ConstantSize(value, unit); }
/** * Creates and returns a ConstantSize from the given encoded size * and unit description. * * @param encodedValueAndUnit the size's value and unit as string, * trimmed and in lower case * @param horizontal true for horizontal, false for vertical * @return a constant size for the given encoding and unit description * * @throws IllegalArgumentException if the unit requires integer * but the value is not an integer */ static ConstantSize valueOf(String encodedValueAndUnit, boolean horizontal) { String[] split = ConstantSize.splitValueAndUnit(encodedValueAndUnit); String encodedValue = split[0]; String encodedUnit = split[1]; Unit unit = Unit.valueOf(encodedUnit, horizontal); double value = Double.parseDouble(encodedValue); if (unit.requiresIntegers) { checkArgument(value == (int) value, "%s value %s must be an integer.", unit, encodedValue); } return new ConstantSize(value, unit); }