barsuift.simLife
Class Percent

java.lang.Object
  extended by barsuift.simLife.Percent
All Implemented Interfaces:
java.lang.Comparable<Percent>

public class Percent
extends java.lang.Object
implements java.lang.Comparable<Percent>

Immutable percent number.


Constructor Summary
Percent()
          Creates a random percentage value
Percent(java.math.BigDecimal value)
          Creates a percent from given BigDecimal value
Percent(int value)
          Creates a percent from given int value
Percent(Percent percent)
          Creates a percent which is a copy of the given percent
Percent(PercentState percentState)
          Creates a percent from given PercentState value
 
Method Summary
 int compareTo(Percent o)
           
 boolean equals(java.lang.Object obj)
           
 int getIntValue()
           
 PercentState getState()
           
 java.math.BigDecimal getValue()
           
 int hashCode()
           
 java.lang.String toString()
          Return a formatted string representing the percent value, in the form xx.00%
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Percent

public Percent()
Creates a random percentage value


Percent

public Percent(Percent percent)
Creates a percent which is a copy of the given percent

Parameters:
percent - the percent to copy value from
Throws:
java.lang.NullPointerException - if given percent is null

Percent

public Percent(PercentState percentState)
Creates a percent from given PercentState value

Parameters:
percentState - must be between 0 and 1 (and not null)
Throws:
java.lang.IllegalArgumentException - if the given value is not between 0 and 1 (or is null)

Percent

public Percent(int value)
Creates a percent from given int value

Parameters:
value - must be between 0 and 100
Throws:
java.lang.IllegalArgumentException - if the given value is not between 0 and 100

Percent

public Percent(java.math.BigDecimal value)
Creates a percent from given BigDecimal value

Parameters:
value - must be between 0 and 1 (and not null)
Throws:
java.lang.IllegalArgumentException - if the given value is not between 0 and 1 (or is null)
Method Detail

getValue

public java.math.BigDecimal getValue()
Returns:
the BigDecimal value of the percentage

getIntValue

public int getIntValue()
Returns:
an approximated int value, between 0 and 100 (rounded down)

getState

public PercentState getState()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Return a formatted string representing the percent value, in the form xx.00%

Overrides:
toString in class java.lang.Object
Returns:
xx.00%

compareTo

public int compareTo(Percent o)
Specified by:
compareTo in interface java.lang.Comparable<Percent>


Copyright © 2010. All Rights Reserved.