/** * Returns a string representation of this size object. * * <strong>Note:</strong> This string representation may change * at any time. It is intended for debugging purposes. For parsing, * use {@link #encode()} instead. * * @return a string representation of the constant size */ @Override public String toString() { return value == intValue() ? Integer.toString(intValue()) + unit.abbreviation() : Double.toString(value) + unit.abbreviation(); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Returns a string representation of this size object. * * <strong>Note:</strong> This string representation may change * at any time. It is intended for debugging purposes. For parsing, * use {@link #encode()} instead. * * @return a string representation of the constant size */ public String toString() { return (value == intValue()) ? Integer.toString(intValue()) + unit.abbreviation() : Double.toString(value) + unit.abbreviation(); }
/** * Returns a string representation of this size object. * * <strong>Note:</strong> The string representation may change at any time. * It is strongly recommended to not use this string for parsing purposes. * * @return a string representation of the constant size */ public String toString() { return (value == intValue()) ? Integer.toString(intValue()) + unit.abbreviation() : Double.toString(value) + unit.abbreviation(); }
/** * Returns a parseable string representation of this constant size. * * @return a String that can be parsed by the Forms parser * * @since 1.2 */ @Override public String encode() { return value == intValue() ? Integer.toString(intValue()) + unit.encode() : Double.toString(value) + unit.encode(); }