Agent System POND 1.2 (28.2.2002)

FIM.payment
Class Price

java.lang.Object
  |
  +--FIM.payment.Price
All Implemented Interfaces:
Comparable, Serializable, XMLEncodeable

public class Price
extends Object
implements XMLEncodeable, Serializable, Comparable

A class for representing a price by a currency object and a value. Also supports parsing both from a string.

Version:
1.0
Author:
Michael Sonntag
See Also:
Serialized Form

Constructor Summary
Price(Currency curr, double price)
          Creates a new price object.
Price(Element elem)
          Creates a new price object from values stored in an XML Element.
 
Method Summary
 int compareTo(Object o)
          Compares this price to another one.
 void decodeXMLElement(Element elem)
          Parse back the price from an XML element.
 boolean equals(Object obj)
          Compares two prices for equality.
 Serializable getAsSerializable()
          Retrieve the price as a serializable (just returns this as this object is directly serializable).
 Element getAsXMLElement(Document doc)
          Retrieve the price as an XML element.
 Currency getCurrency()
          Retrieve the currency of this price.
 double getPrice()
          Retrieve the value of this price.
 double getStandardPrice()
          Retrieve the value of this price in Euro.
 String toString()
          Retrieve a string representation of this price.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Price

public Price(Currency curr,
             double price)
Creates a new price object.
Parameters:
curr - the currency
price - the value
Throws:
IllegalArgumentException - if the currency is null or the price is < 0.0

Price

public Price(Element elem)
Creates a new price object from values stored in an XML Element.
Parameters:
elem - the XML element to parse the values from
Throws:
IllegalArgumentException - if the price could not be parsed back completely
Method Detail

getCurrency

public Currency getCurrency()
Retrieve the currency of this price.
Returns:
the currency

getPrice

public double getPrice()
Retrieve the value of this price.
Returns:
the value

getStandardPrice

public double getStandardPrice()
Retrieve the value of this price in Euro. Uses the exchange factor stored in the currency.
Parameters:
IllegalStateException - if no exchange value is present
Returns:
the value in Euro

toString

public String toString()
Retrieve a string representation of this price. Includes the price and the value. Uses the locale for formatting.
Specified by:
toString in interface XMLEncodeable
Overrides:
toString in class Object
Returns:
the price as a string

equals

public boolean equals(Object obj)
Compares two prices for equality.
Overrides:
equals in class Object
Parameters:
obj - the object to compare to this one
Returns:
true if the currency and the value is the same

compareTo

public int compareTo(Object o)
Compares this price to another one. If the currency is the same, the value is compared. Otherwise the value in Euro is compared. If no conversion is abailable for one of the currencies, a ClassCastException is thrown.
Specified by:
compareTo in interface Comparable
Parameters:
o - the object to compare to this one
Returns:
returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
Throws:
ClassCastException - if the other object is not a price
ClassCastException - if the other object has a different currency and one of the currencies cannot be converted to Euros

getAsSerializable

public Serializable getAsSerializable()
Retrieve the price as a serializable (just returns this as this object is directly serializable).
Specified by:
getAsSerializable in interface XMLEncodeable
Returns:
the price object as a serializable

getAsXMLElement

public Element getAsXMLElement(Document doc)
Retrieve the price as an XML element.
Specified by:
getAsXMLElement in interface XMLEncodeable
Parameters:
doc - the document within which to create the element
Returns:
the price as an element

decodeXMLElement

public void decodeXMLElement(Element elem)
                      throws IllegalArgumentException
Parse back the price from an XML element.
Specified by:
decodeXMLElement in interface XMLEncodeable
Parameters:
elem - the element containing the price to parse back
Throws:
IllegalArgumentException - if the element is incorrect (e. g. wrong tag name)

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.