com.vaadin.server
Class SizeWithUnit

java.lang.Object
  extended by com.vaadin.server.SizeWithUnit
All Implemented Interfaces:
java.io.Serializable

public class SizeWithUnit
extends java.lang.Object
implements java.io.Serializable

A class for representing a value-unit pair. Also contains utility methods for parsing such pairs from a string.

Since:
7.4
Author:
Vaadin Ltd
See Also:
Serialized Form

Constructor Summary
SizeWithUnit(float size, Sizeable.Unit unit)
          Constructs a new SizeWithUnit object representing the pair (size, unit).
 
Method Summary
 float getSize()
          Returns the numeric value stored in this object.
 Sizeable.Unit getUnit()
          Returns the unit stored in this object.
static SizeWithUnit parseStringSize(java.lang.String s)
          Returns an object whose numeric value and unit are taken from the string s.
static SizeWithUnit parseStringSize(java.lang.String s, Sizeable.Unit defaultUnit)
          Returns an object whose numeric value and unit are taken from the string s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SizeWithUnit

public SizeWithUnit(float size,
                    Sizeable.Unit unit)
Constructs a new SizeWithUnit object representing the pair (size, unit).

Parameters:
size - a numeric value
unit - a unit
Method Detail

getSize

public float getSize()
Returns the numeric value stored in this object.

Returns:
the value of this (value, unit) pair

getUnit

public Sizeable.Unit getUnit()
Returns the unit stored in this object.

Returns:
the unit of this (value, unit) pair

parseStringSize

public static SizeWithUnit parseStringSize(java.lang.String s,
                                           Sizeable.Unit defaultUnit)
Returns an object whose numeric value and unit are taken from the string s. If s does not specify a unit and defaultUnit is not null, defaultUnit is used as the unit. If defaultUnit is null and s is a nonempty string representing a unitless number, an exception is thrown. Null or empty string will produce {-1,Unit#PIXELS}.

Parameters:
s - the string to be parsed
defaultUnit - The unit to be used if s does not contain any unit. Use null for no default unit.
Returns:
an object containing the parsed value and unit

parseStringSize

public static SizeWithUnit parseStringSize(java.lang.String s)
Returns an object whose numeric value and unit are taken from the string s. Null or empty string will produce {-1,Unit#PIXELS}. An exception is thrown if s specifies a number without a unit.

Parameters:
s - the string to be parsed
Returns:
an object containing the parsed value and unit


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.