com.retek.commons.util.type
Class Percent

java.lang.Object
  extended bycom.retek.commons.util.type.Percent
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public final class Percent
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

A representation of a Percent intended for use in arithmetic manipulation of Monies and Quantities.

    Characteristics of this implementation .
  1. Percents are immutable
  2. Percents are non-negative, i.e. can only be zero, or positive.
  3. Percents can be greater than 100.

Retek Inc. Copyright (c) 2003

See Also:
Serialized Form

Field Summary
static Percent ONE_HUNDRED
           
static Percent ZERO
           
 
Constructor Summary
Percent(java.math.BigDecimal value)
           
Percent(long value)
          Convenience constructor for creating whole integer Percents, such as 50%
Percent(java.lang.String value)
           
 
Method Summary
 Percent add(Percent other)
           
 int compareTo(java.lang.Object o)
           
 Percent difference(Percent other)
          This method exists instead of a subtract method due to the design decision that this class only represents non-negative percent values.
 boolean equals(java.lang.Object other)
           
 int hashCode()
           
 boolean isGreaterThan(Percent that)
           
 boolean isPositive()
           
 boolean isZero()
           
 java.math.BigDecimal multiply(java.math.BigDecimal bigDecimal)
           
 Percent multiply(Percent other)
           
static Percent ratioAsPercent(java.math.BigDecimal numerator, java.math.BigDecimal denominator)
           
 java.math.BigDecimal toBigDecimal()
           
 java.lang.String toString()
           
 java.lang.String toString(int decimalPlaces)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_HUNDRED

public static final Percent ONE_HUNDRED

ZERO

public static final Percent ZERO
Constructor Detail

Percent

public Percent(java.math.BigDecimal value)

Percent

public Percent(java.lang.String value)
Throws:
java.lang.NumberFormatException - if value can't be parsed as a number.

Percent

public Percent(long value)
Convenience constructor for creating whole integer Percents, such as 50%

Method Detail

isZero

public boolean isZero()

isPositive

public boolean isPositive()

add

public Percent add(Percent other)

difference

public Percent difference(Percent other)
This method exists instead of a subtract method due to the design decision that this class only represents non-negative percent values.


isGreaterThan

public boolean isGreaterThan(Percent that)

multiply

public Percent multiply(Percent other)

multiply

public java.math.BigDecimal multiply(java.math.BigDecimal bigDecimal)

toBigDecimal

public java.math.BigDecimal toBigDecimal()

toString

public java.lang.String toString()

toString

public java.lang.String toString(int decimalPlaces)

equals

public boolean equals(java.lang.Object other)

hashCode

public int hashCode()

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

ratioAsPercent

public static Percent ratioAsPercent(java.math.BigDecimal numerator,
                                     java.math.BigDecimal denominator)


Copyright © 2004 Retek Inc. All Rights Reserved. - Generated at Fri, 10/22/2004 07:28