net.commerce.zocalo.currency
Class Price

java.lang.Object
  extended by net.commerce.zocalo.currency.Quantity
      extended by net.commerce.zocalo.currency.RangedQuantity
          extended by net.commerce.zocalo.currency.Price
All Implemented Interfaces:
java.lang.Comparable

public class Price
extends RangedQuantity

Prices have a quantity, a maximum, and a scale. The Maximum is the maximum price in some market, the scale tells how to scale prices for printing (when holdings are in dollars and prices are in cents, scale would be 2.) RoundingMode wants PRECISION instead of SCALE, so we have to be careful in converting. We want to know how many digits to the right of the decimal place to maintain in various operations (SCALE). PRECISION means how many significant digits in total, not how many to the right of the decimal. BigDecimal uses SCALE the way we want, but we have to be careful to round with movePointLeft(x).newScale(0). Need maxPrice, conversion for Currency scale. (Plus computation resolution) Example: 1-99, 0, 0 (Chapman experiments) .01-99.99, -2, 0 (holdings should print to .00) 1-399, 0, 0 (Chapman experiments) .1-99.9, -1, 0 (InTrade) 1-99, 0, 0 (NewsFutures)


Field Summary
static Price ONE_DOLLAR
           
static Price ZERO_DOLLARS
           
 
Fields inherited from class net.commerce.zocalo.currency.RangedQuantity
maxValue
 
Fields inherited from class net.commerce.zocalo.currency.Quantity
EPSILON, NINE_DIGITS, ONE, Q100, quant, ROUNDING_CONTEXT, ZERO
 
Constructor Summary
Price(java.math.BigDecimal q, Price prior)
           
Price(double q, Price prior)
           
Price(Quantity priceLimit)
           
Price(Quantity q, Price prior)
           
Price(Quantity price, Quantity max)
           
Price(java.lang.String q, Price prior)
           
 
Method Summary
 Probability asProbability()
           
 int compareTo(Quantity quantity)
           
static Price dollarPrice(double p)
           
static Price dollarPrice(java.lang.String p)
           
 Price inverted()
           
 Quantity negate()
           
 Price newValue(java.math.BigDecimal quantity)
           
 Price newValue(Quantity quantity)
           
 java.lang.String printAsWholeCents()
           
 java.lang.String printHighPrecision()
           
 java.lang.String printQuant()
           
 Price round(java.math.MathContext c)
           
 Price simplify()
           
 java.lang.String toString()
           
 
Methods inherited from class net.commerce.zocalo.currency.RangedQuantity
asQuantity, eq, equals, getMaxValue, hashCode, setMaxValue
 
Methods inherited from class net.commerce.zocalo.currency.Quantity
abs, absLog, approaches, asValue, compareTo, div, div, exp, floor, getId, getQuant, isNegative, isNegligible, isNonNegative, isPositive, isZero, max, min, minus, movePointLeft, newScale, plus, printAsDetailedQuantity, printAsDollars, printAsIntegerQuantity, printAsQuantity, printAsScore, remainder, round, roundFloor, scale, setId, setQuant, times
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_DOLLAR

public static final Price ONE_DOLLAR

ZERO_DOLLARS

public static final Price ZERO_DOLLARS
Constructor Detail

Price

public Price(java.math.BigDecimal q,
             Price prior)

Price

public Price(double q,
             Price prior)

Price

public Price(java.lang.String q,
             Price prior)

Price

public Price(Quantity q,
             Price prior)

Price

public Price(Quantity price,
             Quantity max)

Price

public Price(Quantity priceLimit)
Method Detail

dollarPrice

public static Price dollarPrice(java.lang.String p)

dollarPrice

public static Price dollarPrice(double p)

negate

public Quantity negate()
Overrides:
negate in class Quantity

asProbability

public Probability asProbability()
Overrides:
asProbability in class RangedQuantity

printQuant

public java.lang.String printQuant()

inverted

public Price inverted()
Specified by:
inverted in class RangedQuantity

round

public Price round(java.math.MathContext c)
Specified by:
round in class RangedQuantity

newValue

public Price newValue(Quantity quantity)
Specified by:
newValue in class RangedQuantity

newValue

public Price newValue(java.math.BigDecimal quantity)
Specified by:
newValue in class RangedQuantity

simplify

public Price simplify()
Overrides:
simplify in class Quantity

compareTo

public int compareTo(Quantity quantity)
Overrides:
compareTo in class Quantity

printAsWholeCents

public java.lang.String printAsWholeCents()

printHighPrecision

public java.lang.String printHighPrecision()

toString

public java.lang.String toString()
Overrides:
toString in class Quantity