Package ca.cgjennings.apps.arkham
Class Length
- java.lang.Object
-
- ca.cgjennings.apps.arkham.Length
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Length rhs)
Compares this length with the specified length.static double
convert(double measurement, int sourceUnit, int destUnit)
Returns the a measurement in terms of a different unit.boolean
equals(java.lang.Object obj)
Returnstrue
if and only if the compared object is a length of equal size.double
get(int unit)
Returns the value of this length measurement in the requested unit.static int
getDefaultUnit()
Returns the default unit to use when displaying lengths to the user.double
getPoints()
Returns this length in points.int
hashCode()
void
set(double measurement, int unit)
Sets this length to the distance specified by themeasurement
andunit
.static void
setDefaultUnit(int unit)
Sets the default unit to use when displaying lengths to the user.void
setPoints(double points)
Sets the value of this length measurement in points.java.lang.String
toString()
-
-
-
Field Detail
-
CM
public static final int CM
Centimetres- See Also:
- Constant Field Values
-
IN
public static final int IN
Inches- See Also:
- Constant Field Values
-
PT
public static final int PT
Points- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Length
public Length()
Creates a new length representing a distance of zero.
-
Length
public Length(double measurement, int unit)
Creates a new length equivalent to the distance specified by themeasurement
andunit
.- Parameters:
measurement
- the magnitude of the distanceunit
- the unit in which the measurement is expressed
-
-
Method Detail
-
set
public void set(double measurement, int unit)
Sets this length to the distance specified by themeasurement
andunit
.- Parameters:
measurement
- the magnitude of the distanceunit
- the unit in which the measurement is expressed
-
get
public double get(int unit)
Returns the value of this length measurement in the requested unit.- Parameters:
unit
- the desired unit, such asCM
,IN
, orPT
- Returns:
- this object's length measurement expressed in the specified unit
-
setPoints
public void setPoints(double points)
Sets the value of this length measurement in points.- Parameters:
points
- the length to set, in points
-
getPoints
public double getPoints()
Returns this length in points.- Returns:
- the distance represented by this length, in points
-
compareTo
public int compareTo(Length rhs)
Compares this length with the specified length. Returns a negative integer, zero, or a positive integer as this length is less than, equal to, or greater than the specified length.- Specified by:
compareTo
in interfacejava.lang.Comparable<Length>
- Parameters:
rhs
- the length to be compared with this length- Returns:
- an integer whose sign is consistent with the sign of
this.get(PT) - rhs.get(PT)
-
equals
public boolean equals(java.lang.Object obj)
Returnstrue
if and only if the compared object is a length of equal size.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare this to- Returns:
true
ifobj
is aLength
that represents the same distance
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
convert
public static double convert(double measurement, int sourceUnit, int destUnit)
Returns the a measurement in terms of a different unit.- Parameters:
measurement
- the measurement to convertsourceUnit
- the unit used for the source measurementdestUnit
- the unit used for the destination measurement- Returns:
- the measurement in the source unit converted to the destination unit
-
getDefaultUnit
public static int getDefaultUnit()
Returns the default unit to use when displaying lengths to the user. If no default unit is set, then the default unit will beCM
unless the default locale has a country value of "US", in which case the default unit will beIN
.- Returns:
- the default unit for presenting length measurements to the user
-
setDefaultUnit
public static void setDefaultUnit(int unit)
Sets the default unit to use when displaying lengths to the user.- Parameters:
unit
- the unit to set- Throws:
java.lang.IllegalArgumentException
- if the unit is not one of the legal values
-
-