|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.lib.properties.Weight
All game objects have a weight that's used for various things. To make display and conversions simpler, we encapsulate weight in a Bean property that provides various utilities, getters and setters for dealing with different units.
Field Summary | |
static double |
GM_PER_LB
|
static double |
GM_PER_OZ
|
static int |
GRAMS
|
static double |
KG_PER_LB
|
static double |
KG_PER_OZ
|
static int |
KILOS
|
static double |
LB_PER_GM
|
static double |
LB_PER_KG
|
static double |
LB_PER_OZ
|
static int |
OUNCES
|
static double |
OZ_PER_GM
|
static double |
OZ_PER_KG
|
static double |
OZ_PER_LB
|
static int |
POUNDS
|
Constructor Summary | |
Weight()
Constructs a new Weight with a value of 0. |
|
Weight(long grams)
Constructs a new Weight with the specified value in grams. |
|
Weight(java.lang.String value)
Constructs a new Weight with the specified value (as a string). |
|
Weight(Weight w)
Constructs a new Weight copied from the passed Weight. |
Method Summary | |
boolean |
equals(java.lang.Object obj)
Returns true if the passed weight equals this weight. |
static java.lang.String |
formatAsGrams(long grams)
Formats the specified gram-weight. |
static java.lang.String |
formatAsKilos(long grams)
Formats the specified gram-weight as a number of kilograms (kg). |
static java.lang.String |
formatAsOunces(long grams)
Formats the specified gram-weight as a number of ounces. |
static java.lang.String |
formatAsPounds(long grams)
Formats the specified gram-weight as a number of pounds. |
long |
getValue()
Returns the value of this weight in grams, the default weight-measurement unit in the game. |
long |
getWeightInGrams()
Returns the weight in grams; same as getValue(). |
double |
getWeightInKilos()
Returns the value of the weight in kg. |
double |
getWeightInOunces()
Returns the weight of the object, in ounces. |
double |
getWeightInPounds()
Returns the value of this Weight in lbs. |
static double |
gramsToKilos(long grams)
Converts the specified gram-value to kilograms. |
static double |
gramsToOunces(long grams)
Converts the specified gram-value to ounces. |
static double |
gramsToPounds(long grams)
Converts the specified gram-value to pounds. |
int |
hashCode()
Overridden hashcode method, required since we overrode equals(). |
static long |
kilosToGrams(double kg)
Rounds the passed kg weight to a whole number of grams. |
static double |
kilosToOunces(double kg)
Converts the passed kg weight to ounces. |
static double |
kilosToPounds(double kg)
Converts the passed kg to pounds. |
static void |
main(java.lang.String[] args)
Tests the conversion and formatting utilities. |
static long |
ouncesToGrams(double oz)
Rounds the specified oz-value to the nearest whole number of grams. |
static double |
ouncesToKilos(double oz)
Converts the passed ounce-weight to kilograms. |
static double |
ouncesToPounds(double oz)
Converts the passed ounce-weight to pounds. |
static long |
parseWeight(java.lang.String args)
Takes the passed weight-specifier and figures out what it is in grams. |
static long |
poundsToGrams(double lbs)
Rounds the specified lb-value to the nearest whole number of grams. |
static double |
poundsToKilos(double lbs)
Converts the passed pound-weight to kilograms. |
static double |
poundsToOunces(double lbs)
Converts a pound-weight to ounces. |
void |
readData(org.w3c.dom.Node bean)
Tells the object to parse its externalized representation from a list of lines. |
void |
setValue(long gram_weight)
Sets the value of the weight in grams. |
void |
setValue(java.lang.String weight)
Sets the value from the passed weight-specifier string. |
void |
setWeightInGrams(long gram_weight)
Sets the object's weight in grams; same as setValue(). |
void |
setWeightInKilos(double kg)
Sets the object's weight by rounding the passed value to the nearest gram. |
void |
setWeightInOunces(double oz)
Sets the object's weight by rounding the passed value to the nearest gram. |
void |
setWeightInPounds(double lbs)
Sets the object's weight by rounding the passed value to the nearest gram. |
boolean |
shouldWrite()
Returns true if we should write the property at all. |
java.lang.String |
toString()
Returns a String representation of this Weight object. |
java.lang.String |
toString(int units)
Prints out the weight in the specified units (e.g. |
java.util.List |
writeData()
Tells the object to write its properties out to a text file. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final double LB_PER_KG
public static final double KG_PER_LB
public static final double OZ_PER_LB
public static final double LB_PER_OZ
public static final double GM_PER_LB
public static final double GM_PER_OZ
public static final double OZ_PER_GM
public static final double OZ_PER_KG
public static final double KG_PER_OZ
public static final double LB_PER_GM
public static final int KILOS
public static final int GRAMS
public static final int OUNCES
public static final int POUNDS
Constructor Detail |
public Weight()
public Weight(long grams)
grams
- the weightpublic Weight(java.lang.String value)
value
- a specifier string consisting of a long or double
number, optional whitespace, and one of four units: "kg", "gm",
"lb" or "oz".
java.lang.IllegalArgumentException
- if the value fails to parsepublic Weight(Weight w)
w
- another Weight object whose value we wish to copyMethod Detail |
public long getValue()
public void setValue(long gram_weight)
gram_weight
- the object's mass in gramspublic void setValue(java.lang.String weight)
weight
- a specifier string consisting of a long or double
number, optional whitespace, and one of four units: "kg", "gm",
"lb" or "oz".
java.lang.IllegalArgumentException
- if the value fails to parsepublic double getWeightInPounds()
public void setWeightInPounds(double lbs)
lbs
- the object's new weight, in poundspublic double getWeightInKilos()
public void setWeightInKilos(double kg)
kg
- the object's new weight, in kgpublic double getWeightInOunces()
public void setWeightInOunces(double oz)
oz
- the object's new weight, specified in ouncespublic long getWeightInGrams()
public void setWeightInGrams(long gram_weight)
gram_weight
- the object's new mass in gramspublic static double gramsToOunces(long grams)
public static double gramsToPounds(long grams)
public static double gramsToKilos(long grams)
public static long ouncesToGrams(double oz)
public static double ouncesToPounds(double oz)
public static double ouncesToKilos(double oz)
public static long poundsToGrams(double lbs)
public static double poundsToKilos(double lbs)
public static double poundsToOunces(double lbs)
public static double kilosToPounds(double kg)
public static double kilosToOunces(double kg)
public static long kilosToGrams(double kg)
public static java.lang.String formatAsPounds(long grams)
public static java.lang.String formatAsGrams(long grams)
public static java.lang.String formatAsOunces(long grams)
public static java.lang.String formatAsKilos(long grams)
public static long parseWeight(java.lang.String args)
The specifier format is
args
- the weight specifier, such as "40.2 lb"
java.lang.IllegalArgumentException
- if the weight specifier
is invalid.
public java.lang.String toString()
public java.lang.String toString(int units)
public void readData(org.w3c.dom.Node bean) throws java.lang.Exception
readData
in interface SelfExternalizable
bean
- the node representing the SelfExternalizable bean
object, which should have at least one child data node.
java.lang.Exception
public java.util.List writeData() throws java.lang.Exception
writeData
in interface SelfExternalizable
java.lang.Exception
public boolean shouldWrite()
shouldWrite
in interface SelfExternalizable
public int hashCode()
public boolean equals(java.lang.Object obj)
obj
- the object to compare for equality
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |