public class PriceIncrements extends Object implements Serializable
All price ranges shall be mutually exclusive and they shall cover entire space from 0 to infinity. Therefore all ranges can be represented as a sequence of numbers where increments are interleaved with range limits, with extreme limits (0 and infinity) omitted for short. Negative space (from negative infinity to 0) uses symmetrical price ranges.
There is a special value EMPTY
which is used to represent unknown or undefined rules.
This value has empty textual representation and is considered to have sole increment with value 0.
See getText()
and getPriceIncrements()
for details about used formats and representations.
NOTE:This class produces precise results for decimal numbers with at most 14 significant digits and at most 14 digits after decimal point.
Modifier and Type | Field and Description |
---|---|
static PriceIncrements |
EMPTY
Empty price increments - it has empty text and sole increment with value 0.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
double |
getPriceIncrement()
Returns first price increment (for price range adjacent to 0), usually the smallest one.
|
double |
getPriceIncrement(double price)
Returns price increment which shall be applied to the specified price.
|
double |
getPriceIncrement(double price,
int direction)
Returns price increment which shall be applied to the specified price in the specified direction.
|
double[] |
getPriceIncrements()
Returns internal representation of price increments as a single array of double values.
|
int |
getPricePrecision()
Returns first price precision (for price range adjacent to 0), usually the largest one.
|
int |
getPricePrecision(double price)
Returns price precision for the price range which contains specified price.
|
String |
getText()
Returns textual representation of price increments in the format:
|
int |
hashCode() |
double |
incrementPrice(double price,
int direction)
Returns specified price incremented in the specified direction
by appropriate increment and then rounded to nearest valid value.
|
double |
incrementPrice(double price,
int direction,
double step)
Returns specified price incremented in the specified direction by the maximum of
specified step and appropriate increment, and then rounded to nearest valid value.
|
double |
roundPrice(double price)
Returns specified price rounded to nearest valid value.
|
double |
roundPrice(double price,
int direction)
Returns specified price rounded in the specified direction to nearest value
that is valid according to price increment rules.
|
double |
roundPrice(double price,
RoundingMode mode)
Returns specified price rounded according to specified rounding mode to nearest value
that is valid according to price increment rules.
|
String |
toString() |
static PriceIncrements |
valueOf(double increment)
Returns an instance of price increments for specified single increment.
|
static PriceIncrements |
valueOf(double[] increments)
Returns an instance of price increments for specified internal representation.
|
static PriceIncrements |
valueOf(String text)
Returns an instance of price increments for specified textual representation.
|
public static final PriceIncrements EMPTY
public static PriceIncrements valueOf(String text)
getText()
for format specification.IllegalArgumentException
- if text uses wrong format or contains invalid valuespublic static PriceIncrements valueOf(double increment)
IllegalArgumentException
- if increment uses invalid valuepublic static PriceIncrements valueOf(double[] increments)
getPriceIncrements()
for details about internal representation.IllegalArgumentException
- if data contains invalid valuespublic String getText()
TEXT ::= "" | LIST LIST ::= INCREMENT | RANGE "; " LIST RANGE ::= INCREMENT " " UPPER_LIMITWhere INCREMENT is a price increment in the given price range and UPPER_LIMIT is the upper bound of that range. All ranges are listed in the ascending order of upper limits and the last range is considered to extend toward infinity and is therefore specified without upper limit. All increments and limits are finite positive numbers. The case with empty text is a special stub used for
EMPTY
value, it uses sole increment with value 0.public double[] getPriceIncrements()
getText()
) in the same order.
Therefore numbers at even positions are increments and numbers at odd positions are upper limits.
The array always has odd length - the infinite upper limit of last range is always omitted and
the first increment (for price range adjacent to 0) is always included even for EMPTY
value.public double getPriceIncrement()
EMPTY
price increments.public double getPriceIncrement(double price)
getPriceIncrement(price, 0)
.public double getPriceIncrement(double price, int direction)
public int getPricePrecision()
EMPTY
price increments.public int getPricePrecision(double price)
public double roundPrice(double price)
roundPrice(price, 0)
.public double roundPrice(double price, int direction)
public double roundPrice(double price, RoundingMode mode)
public double incrementPrice(double price, int direction)
incrementPrice(price, direction, 0)
.IllegalArgumentException
- if direction is 0public double incrementPrice(double price, int direction, double step)
IllegalArgumentException
- if direction is 0 or step uses invalid valueCopyright © 2002–2023 Devexperts LLC. All rights reserved.