/** * Checks if this value describes a pixel value. * * @return true if the given string value ends with PIXEL * and false otherwise */ public boolean isPixel() { return hasValue() && !isPercent(); }
/** * Get the value as int. * * @param range the size that percent values are calculated from. * @return the resulting value rounded to the nearest integer. */ public int getValueAsInt(final float range) { if (isPercent()) { return Math.round((range / MAX_PERCENT) * value); } else if (isPixel()) { return Math.round (value); } else { return -1; } }
/** * Get the value as a float. WARNING: DO NOT CAST THE RETURN VALUE TO AN INTEGER - use {@link #getValueAsInt(float)} * or you will have off-by-one errors! * * @param range the size that percent values are calculated from. * @return the resulting value as a float. */ public float getValue(final float range) { if (isPercent()) { return (range / MAX_PERCENT) * value; } else if (isPixel()) { return value; } else { return -1; } }