Class DimensionValue
- java.lang.Object
-
- org.eclipse.birt.report.model.api.metadata.DimensionValue
-
public class DimensionValue extends java.lang.ObjectRepresentation of a dimension property value. A dimension has two parts: the measure and the optional units. If the units areDEFAULT_UNIT, then the units are assumed to be those set on the design as a whole.The following units are supported:
- in (inch)
- cm (centimeter)
- mm (millimeter)
- pt (point)
- pc (pica)
- px (pixel)
- em (the height of the element's font)
- ex (x-height)
- % (percentage)
- See Also:
DimensionUtil
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.PatterncommaSeparatorPatternCompiled pattern for CSS absolute pattern: "000.000,000.000"static java.lang.StringDEFAULT_UNITDefault unit for the dimension.static java.util.regex.PatterndotSeparatorPatternCompiled pattern for CSS absolute pattern: "000,000.000,000"protected doublemeasureThe numeric measure part of the dimension.protected java.lang.StringunitsThe units part of the dimension.
-
Constructor Summary
Constructors Constructor Description DimensionValue(double theMeasure, java.lang.String theUnits)Constructs a DimensionValue given its measure and unit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Compares this dimension value to the given object.doublegetMeasure()Returns the measure portion of the dimension.java.lang.StringgetUnits()Returns the units portion of the dimension.inthashCode()Returns a hash code for thisDimensionValueobject.static intindexOfUnitLetter(java.lang.String value)Finds index of the first unit character( pt, %, pc...static DimensionValueparse(java.lang.String value)Deprecated.replaced byStringUtil.parse(String)static DimensionValueparseInput(java.lang.String value)Deprecated.java.lang.StringtoDisplayString()Returns the dimension value in localized format.java.lang.StringtoString()Converts the dimension value to a locale-independent string.
-
-
-
Field Detail
-
measure
protected final double measure
The numeric measure part of the dimension.
-
units
protected final java.lang.String units
The units part of the dimension.
-
DEFAULT_UNIT
public static final java.lang.String DEFAULT_UNIT
Default unit for the dimension.- See Also:
- Constant Field Values
-
dotSeparatorPattern
public static final java.util.regex.Pattern dotSeparatorPattern
Compiled pattern for CSS absolute pattern: "000,000.000,000"
-
commaSeparatorPattern
public static final java.util.regex.Pattern commaSeparatorPattern
Compiled pattern for CSS absolute pattern: "000.000,000.000"
-
-
Constructor Detail
-
DimensionValue
public DimensionValue(double theMeasure, java.lang.String theUnits)Constructs a DimensionValue given its measure and unit.- Parameters:
theMeasure- numeric measuretheUnits- units part for the dimension.- Throws:
java.lang.IllegalArgumentException- if the unit is not supported.
-
-
Method Detail
-
getMeasure
public double getMeasure()
Returns the measure portion of the dimension.- Returns:
- the measure
-
getUnits
public java.lang.String getUnits()
Returns the units portion of the dimension.- Returns:
- the units.
-
parse
@Deprecated public static DimensionValue parse(java.lang.String value) throws PropertyValueException
Deprecated.replaced byStringUtil.parse(String)Parses a dimension string in locale-independent way. The input string must match the following:- null
- [1-9][0-9]*[.[0-9]*[ ]*[in|cm|mm|pt|pc|em|ex|px|%]]
- Parameters:
value- the dimension string to parse- Returns:
- a dimension object representing the dimension string.
- Throws:
PropertyValueException- if the string is not valid
-
parseInput
@Deprecated public static DimensionValue parseInput(java.lang.String value) throws PropertyValueException
Deprecated.Parses a dimension string in locale-dependent way. The input can be in localized value. The measure part use the decimal separator from the locale. e,g. "123,456.78" for English ; "123.456,78" for German.The string must match the following:
- null
- [1-9][0-9]*[.[0-9]*[ ]*[u]], u is the one of the allowed units
- Parameters:
value- the string to parse- Returns:
- a dimension object
- Throws:
PropertyValueException- if the string is not valid
-
toString
public java.lang.String toString()
Converts the dimension value to a locale-independent string. The string will be converted into a format like "#.###", there is no group separator and remains at most 3 digits after the decimal separator. e.g: "12,000,000.12345cm" will be converted into "12000000.123"- Overrides:
toStringin classjava.lang.Object- Returns:
- The string presentation of this dimension value.
-
toDisplayString
public java.lang.String toDisplayString()
Returns the dimension value in localized format.- Returns:
- localized format for this instance.
-
indexOfUnitLetter
public static int indexOfUnitLetter(java.lang.String value)
Finds index of the first unit character( pt, %, pc... ) in the String.- Parameters:
value- an input string- Returns:
- index of the first letter. Return -1 if no letter found in the String value.
-
equals
public boolean equals(java.lang.Object obj)
Compares this dimension value to the given object. The result istrueif and only if the argument is not null and is a dimension value object with the same measure and the same type of unit. The two dimension values with different units are not equal, although they can be converted to same measure- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare this dimension value against.- Returns:
trueif this dimension value is equal to the given one;falseotherwise.
-
hashCode
public int hashCode()
Returns a hash code for thisDimensionValueobject. The result is computed with the exclusive OR of the two halves of thelonginteger bit representation of the measure, and the hash code of unit string. The measure bit representation is exactly produced by the method Double.doubleToLongBits(double), of the primitivedoublevalue represented by the measure of thisDimensionValueobject. That is, the hash code is the value of the expression:
whereint result = 17 + 37 * (int) (m ˆ (m >>> 32)); result = 37 * result + getUnits().toLowerCase().hashCode();
mis defined by:long m = Double.doubleToLongBits(this.getMeasure());
- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this object.
-
-