ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.xmlconfig
Class TimeParam

java.lang.Object
  extended by umontreal.iro.lecuyer.xmlconfig.AbstractParam
      extended by umontreal.iro.lecuyer.xmlconfig.TimeParam
All Implemented Interfaces:
Cloneable, Param

public class TimeParam
extends AbstractParam
implements Cloneable

Represents a time duration or a rate parameter expressed in a time unit. This parameter object can be constructed from a string, or a value with a TimeUnit instance representing its unit. The get(umontreal.iro.lecuyer.util.TimeUnit) method can be used to obtain the value of the parameter, converted into a user-specified time unit. Usually, this parameter is used to represent a duration. Rates are supported for distribution scale parameters.

The time parameter can also be used as an XML attribute type or as a nested element when using ParamReader to parse an XML document into a parameter object.


Constructor Summary
TimeParam()
          Constructs a time parameter with value 0.
TimeParam(double value)
          Equivalent to TimeParam (value, false, null).
TimeParam(double value, boolean rate, TimeUnit unit)
          Constructs a new time parameter with encoded value value, rate indicator rate, and time unit unit.
TimeParam(double value, TimeUnit unit)
          Equivalent to TimeParam (value, false, unit).
TimeParam(String str)
          Constructs a time parameter from the string str.
 
Method Summary
 TimeParam clone()
           
 boolean equals(Object other)
           
 String formatHMS()
           
 String formatSI()
           
static String formatSI(double time)
           
 double get(boolean dstRate, TimeUnit dstUnit)
          Returns the rate or time extracted from this parameter, expressed in dstUnit.
 double get(TimeUnit dstUnit)
          Equivalent to get (false, dstUnit).
 boolean getRateIndicator()
          Returns the rate indicator of this time parameter.
 TimeUnit getTimeUnit()
          Returns the time unit of this parameter.
 double getValue()
          Returns the value of this time parameter, without conversion.
 boolean isAttributeSupported(String a)
          For internal use only.
 void nestedText(String str)
          For internal use only.
 void setRateIndicator(boolean rate)
          Sets the rate indicator of this time parameter to rate.
 void setTimeUnit(TimeUnit unit)
          Sets the time unit of this parameter to unit.
 void setValue(double value)
          Sets the value of this time parameter to value.
 String toString()
          Formats this time parameter as a string.
static TimeParam valueOf(String str)
          Constructs a new time parameter from the string str, using TimeParam(String) and returns the constructed instance.
 
Methods inherited from class umontreal.iro.lecuyer.xmlconfig.AbstractParam
check, createDocument, getId, getXref, setId, setXref, write, write, write, write, write, write, write, write
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeParam

public TimeParam()
Constructs a time parameter with value 0.


TimeParam

public TimeParam(double value)
Equivalent to TimeParam (value, false, null).

Parameters:
value - the encoded value.
Throws:
IllegalArgumentException - if value is negative.

TimeParam

public TimeParam(double value,
                 TimeUnit unit)
Equivalent to TimeParam (value, false, unit).

Parameters:
value - the encoded value.
unit - the time unit in which the value is assumed to be expressed.
Throws:
IllegalArgumentException - if value is negative.

TimeParam

public TimeParam(double value,
                 boolean rate,
                 TimeUnit unit)
Constructs a new time parameter with encoded value value, rate indicator rate, and time unit unit. If rate is true, value represents a rate that must be converted to a time by inversion before any time unit conversion is performed. unit represents the time unit in which value is assumed to be expressed. If unit is null, the get(umontreal.iro.lecuyer.util.TimeUnit) method performs no time conversion.

Parameters:
value - the encoded value.
rate - the rate indicator.
unit - the time unit in which the value is assumed to be expressed.
Throws:
IllegalArgumentException - if value is negative.

TimeParam

public TimeParam(String str)
Constructs a time parameter from the string str. A string representing a time parameter must contain a value, an optional rate indicator and an optional unit. If the value is followed by the rate indicator /, it is inverted before time unit conversion is performed by get(umontreal.iro.lecuyer.util.TimeUnit). The time unit must be the short name of any instance of TimeUnit. For example, 12s represents 12 seconds and 12/m represents a rate of 12 units per minute.

Parameters:
str - the string representation of the time parameter.
Throws:
IllegalArgumentException - if the string is invalid.
Method Detail

getValue

public double getValue()
Returns the value of this time parameter, without conversion.

Returns:
the time parameter's value.

setValue

public void setValue(double value)
Sets the value of this time parameter to value.

Parameters:
value - the new time parameter's value.
Throws:
IllegalArgumentException - if value is negative or NaN.

getRateIndicator

public boolean getRateIndicator()
Returns the rate indicator of this time parameter.

Returns:
the time parameter's rate indicator.

setRateIndicator

public void setRateIndicator(boolean rate)
Sets the rate indicator of this time parameter to rate.

Parameters:
rate - the new time parameter's rate indicator.

getTimeUnit

public TimeUnit getTimeUnit()
Returns the time unit of this parameter.

Returns:
this parameter's time unit.

setTimeUnit

public void setTimeUnit(TimeUnit unit)
Sets the time unit of this parameter to unit.

Parameters:
unit - the new time unit of this parameter.

get

public double get(TimeUnit dstUnit)
Equivalent to get (false, dstUnit).

Parameters:
dstUnit - the destination time unit.
Returns:
the computed duration.

get

public double get(boolean dstRate,
                  TimeUnit dstUnit)
Returns the rate or time extracted from this parameter, expressed in dstUnit. If dstRate is true, the returned value corresponds to a rate. Otherwise, it corresponds to a time.

If getTimeUnit() returns null, the method returns getValue() unchanged. Otherwise, if getRateIndicator() returns true, 1/getValue() is used instead of getValue(). The method uses TimeUnit.convert(double, umontreal.iro.lecuyer.util.TimeUnit, umontreal.iro.lecuyer.util.TimeUnit) to convert the value from source unit getTimeUnit() to destination unit dstUnit. If dstRate is true, one over the converted value is returned. Otherwise, the converted value is returned.

Parameters:
dstRate - determines if the returned value must be a rate.
dstUnit - the destination time unit.
Returns:
the computed duration or rate.

valueOf

public static TimeParam valueOf(String str)
Constructs a new time parameter from the string str, using TimeParam(String) and returns the constructed instance.

Parameters:
str - the string representation of the time parameter.
Returns:
the constructed time parameter.
Throws:
IllegalArgumentException - if the string is invalid.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

toString

public String toString()
Formats this time parameter as a string. The returned string can be used by TimeParam(String) or valueOf(java.lang.String) to construct a time parameter.

Overrides:
toString in class AbstractParam
Returns:
the time parameter, formatted as a string.

formatHMS

public String formatHMS()

formatSI

public String formatSI()

formatSI

public static String formatSI(double time)

isAttributeSupported

public boolean isAttributeSupported(String a)
For internal use only.


nestedText

public void nestedText(String str)
For internal use only.


clone

public TimeParam clone()
Overrides:
clone in class Object

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.