Package de.hybris.platform.util
Class DiscountValue
- java.lang.Object
-
- de.hybris.platform.util.DiscountValue
-
- All Implemented Interfaces:
PDTValue
,java.io.Serializable
,java.lang.Cloneable
public class DiscountValue extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable, PDTValue
string-storeable discount value object.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DiscountValue(java.lang.String code, double value, boolean absolute, double appliedValue, java.lang.String isoCode)
creates a new discount value with applied value.DiscountValue(java.lang.String code, double value, boolean absolute, double appliedValue, java.lang.String isoCode, boolean asTargetPrice)
DiscountValue(java.lang.String code, double value, boolean absolute, java.lang.String currencyIsoCode)
creates a new discount value without applied value ( will be 0.0 ).DiscountValue(java.lang.String code, double value, java.lang.String currencyIsoCode, boolean asTargetPrice)
Creates a new un-applied absolute discount value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DiscountValue
apply(double quantity, double price, int digits, java.lang.String currencyIsoCode)
Creates a copy of this discount value holding the applied value for a given price rounded to given digits.static java.util.List
apply(double quantity, double startPrice, int digits, java.util.List values, java.lang.String currencyIsoCode)
Creates a collection of applied discount values for a given price and a tax value collection.java.lang.Object
clone()
static DiscountValue
createAbsolute(java.lang.String code, java.lang.Double doubleValue, java.lang.String currencyIsoCode)
protected DiscountValue
createAbsoluteAppliedValue(double quantity, int digits, java.lang.String currencyIsoCode)
static DiscountValue
createRelative(java.lang.String code, java.lang.Double doubleValue)
protected DiscountValue
createRelativeAppliedValue(double price, int digits, java.lang.String currencyIsoCode)
static DiscountValue
createTargetPrice(java.lang.String code, java.lang.Double doubleValue, java.lang.String currencyIsoCode)
protected DiscountValue
createTargetPriceAppliedValue(double quantity, double totalPriceWithoutDiscounts, int digits, java.lang.String currencyIsoCode)
boolean
equals(java.lang.Object object)
boolean
equalsIgnoreAppliedValue(DiscountValue discountValue)
double
getAppliedValue()
the actual value of this discount.java.lang.String
getCode()
java.lang.String
getCurrencyIsoCode()
double
getValue()
The discount value.int
hashCode()
boolean
isAbsolute()
Returnstrue
if theDiscountValue
is an absolute discount, otherwisefalse
is returned.boolean
isAsTargetPrice()
If true the contained value represents the intended target price.static DiscountValue
parseDiscountValue(java.lang.String str)
creates a discount value object from its string representation created via @see #toString().static java.util.Collection
parseDiscountValueCollection(java.lang.String str)
creates a discount value collection from its string representation created via @see #toString(Collection).static double
sumAppliedValues(java.util.Collection values)
java.lang.String
toString()
static java.lang.String
toString(java.util.Collection discountValueCollection)
creates the string representation of a collection of discount values.
-
-
-
Constructor Detail
-
DiscountValue
public DiscountValue(java.lang.String code, double value, boolean absolute, java.lang.String currencyIsoCode)
creates a new discount value without applied value ( will be 0.0 ).- Parameters:
code
- the code of the actual discount item - cannot be nullvalue
- the discount rate or valueabsolute
- tells whether this value is relative or absolute
-
DiscountValue
public DiscountValue(java.lang.String code, double value, java.lang.String currencyIsoCode, boolean asTargetPrice)
Creates a new un-applied absolute discount value.
-
DiscountValue
public DiscountValue(java.lang.String code, double value, boolean absolute, double appliedValue, java.lang.String isoCode)
creates a new discount value with applied value.- Parameters:
code
- the code of the actual discount item - cannot be nullvalue
- the discount rate or valueabsolute
- tells whether this value is relative or absoluteappliedValue
- the applied value of this discount
-
DiscountValue
public DiscountValue(java.lang.String code, double value, boolean absolute, double appliedValue, java.lang.String isoCode, boolean asTargetPrice)
-
-
Method Detail
-
createRelative
public static DiscountValue createRelative(java.lang.String code, java.lang.Double doubleValue)
-
createAbsolute
public static DiscountValue createAbsolute(java.lang.String code, java.lang.Double doubleValue, java.lang.String currencyIsoCode)
-
createTargetPrice
public static DiscountValue createTargetPrice(java.lang.String code, java.lang.Double doubleValue, java.lang.String currencyIsoCode)
-
apply
public DiscountValue apply(double quantity, double price, int digits, java.lang.String currencyIsoCode)
Creates a copy of this discount value holding the applied value for a given price rounded to given digits.- Parameters:
price
- the price to apply this tax value todigits
- the digits to round the value to, if < 0 no rounding is done- Returns:
- the copy of this discount vale
- Since:
- 2.20
-
createRelativeAppliedValue
protected DiscountValue createRelativeAppliedValue(double price, int digits, java.lang.String currencyIsoCode)
-
createAbsoluteAppliedValue
protected DiscountValue createAbsoluteAppliedValue(double quantity, int digits, java.lang.String currencyIsoCode)
-
createTargetPriceAppliedValue
protected DiscountValue createTargetPriceAppliedValue(double quantity, double totalPriceWithoutDiscounts, int digits, java.lang.String currencyIsoCode)
-
apply
public static java.util.List apply(double quantity, double startPrice, int digits, java.util.List values, java.lang.String currencyIsoCode)
Creates a collection of applied discount values for a given price and a tax value collection. All resulting applied values prices are rounded to the given number of digits.- Parameters:
values
- the collection of discount values to apply to the pricestartPrice
- the price to apply these discounts to - the discount values are applied iteratively decreasing the (start)price each time !digits
- the number of digits to round, if < 0 no rounding is done- Returns:
- a list containing all applied discount values for a given price and a tax value collection.
- Since:
- 2.20
-
sumAppliedValues
public static double sumAppliedValues(java.util.Collection values)
-
getCode
public java.lang.String getCode()
- Returns:
- the code this values discount. normally this should match a @see de.hybris.platform.jalo.order.price.Discount item's code but dont rely on it (e.g. when discount values are imported along with their orders and the actual discount doesnt exist )
-
getCurrencyIsoCode
public java.lang.String getCurrencyIsoCode()
- Returns:
- the currency isocode
-
getValue
public double getValue()
The discount value. This value represent the discount rate ( or discount value for absolute discount ) only - use @see #getAppliedValue() to get the actual (absolute) discout value for the order or entry.
-
isAsTargetPrice
public boolean isAsTargetPrice()
If true the contained value represents the intended target price. Therefore the applied value is determined from the difference between the base price and the target price.A target price discount value must also contain a currency iso code!
-
getAppliedValue
public double getAppliedValue()
the actual value of this discount. means this is the value you get when the discount was applied to the order or entry which this value relates to.- Returns:
- the applied value of the
DiscountValue
.
-
isAbsolute
public boolean isAbsolute()
Returnstrue
if theDiscountValue
is an absolute discount, otherwisefalse
is returned.- Returns:
true
if theDiscountValue
is an absolute discount, otherwisefalse
.
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- string representation of this discount value. you may restore this object via @see #parseDiscountValue(String).
-
toString
public static java.lang.String toString(java.util.Collection discountValueCollection)
creates the string representation of a collection of discount values. you may restore this collection via @see #parseDiscountValueCollection(String)(String).- Parameters:
discountValueCollection
- a collection containing StandardDiscountValues- Returns:
- the string representation of a collection of discount values.
-
parseDiscountValueCollection
public static java.util.Collection parseDiscountValueCollection(java.lang.String str) throws java.lang.IllegalArgumentException
creates a discount value collection from its string representation created via @see #toString(Collection).- Parameters:
str
- the string representation of the discount values.- Returns:
- a discount value collection from its string representation.
- Throws:
java.lang.IllegalArgumentException
- if a parse error occured
-
parseDiscountValue
public static DiscountValue parseDiscountValue(java.lang.String str) throws java.lang.IllegalArgumentException
creates a discount value object from its string representation created via @see #toString().- Parameters:
str
- the string representation of the discount values.- Returns:
- a discount value object from its string representation.
- Throws:
java.lang.IllegalArgumentException
- if the string is not valid
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
equalsIgnoreAppliedValue
public boolean equalsIgnoreAppliedValue(DiscountValue discountValue)
-
-