Package de.hybris.platform.jalo.c2l
Class Currency
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable
public class Currency extends GeneratedCurrency
The hybris Platform currency item. Currencies are used mainly for pricing purpose. For this reason thespecified in SessionContext.getCurrency()
of the currentJaloSession
defines the defaultCurrency
of this session. All pricing information will use thisCurrency
by default. Some examples for the use ofCurrency
items: Furthermore currencies offer convenience methods for price formatting and conversion. If you want to format a price according to its currency's digits you got to do it like this:PriceValue pv = ...; String priceStr = pv.getCurrency().formatPrice( pv.getValue() );
Rounding a price is also provided by this class:
Currency c = ...; c.setDigits( 3 ); // now c rounds any value to 3 digits double rounded = c.round( 1.234567 );
Converting a value between two currencies can be done this way:
Currency source = ... , target = ... ; source.setConversionFactor( 2 ); target.setConversionFactor( 1 ); target.setDigits( 1 ); // now convert from source to target value * 1 / 2 double result = source.convert( target , 4.44444 ); // result should be 2.2 , since conversion does rounding to 1 target digit
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.GenericItem
GenericItem.GenericItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LocalizableItem.LocalizableItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.ExtensibleItem
ExtensibleItem.ExtensibleItemImpl
-
Nested classes/interfaces inherited from class de.hybris.platform.jalo.Item
Item.AttributeFilter, Item.AttributeMode, Item.CachedGetter, Item.CachedSetter, Item.ItemAttributeMap, Item.ItemConstraint, Item.ItemImpl, Item.JaloCachedComputationException
-
-
Field Summary
-
Fields inherited from class de.hybris.platform.jalo.c2l.GeneratedCurrency
BASE, CONVERSION, DEFAULT_INITIAL_ATTRIBUTES, DIGITS, SYMBOL
-
Fields inherited from class de.hybris.platform.jalo.c2l.GeneratedC2LItem
ACTIVE, ISOCODE, NAME
-
Fields inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LANGUAGE_FALLBACK_ENABLED
-
Fields inherited from class de.hybris.platform.jalo.Item
_CREATION_TIME_INTERNAL, _MODIFIED_TIME_INTERNAL, accessorLog, CREATION_TIME, DISABLE_ATTRIBUTE_CHECK, DISABLE_ITEMCHECK_BEFORE_REMOVABLE, EVEN, FEATURE_ACCESSMAP_QUALIFIER, HJMPTS, INITIAL_CREATION_FLAG, isJaloOnly, MODIFIED_TIME, NEGATIVE, NOT_FOUND, OWNER, PK, POSITIVE, SAVE_FROM_SERVICE_LAYER, staticTransientObjects, TYPE
-
Fields inherited from class de.hybris.platform.util.BridgeAbstraction
impl, tenant
-
-
Constructor Summary
Constructors Constructor Description Currency()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.text.DecimalFormat
adjustDigits(java.text.DecimalFormat nf, Currency c)
Deprecated.since agesstatic java.text.DecimalFormat
adjustSymbol(java.text.DecimalFormat nf, Currency c)
Deprecated.since agesprotected void
checkRemovable(SessionContext ctx)
Checks whether or not this it may be removed or not.double
convert(Currency targetCurrency, double value)
Deprecated.since ages - useCommonI18NService.convertCurrency(double, double, double)
instead.double
convertAndRound(Currency targetCurrency, double value)
Deprecated.since ages - useCommonI18NService.convertAndRoundCurrency(double, double, int, double)
instead.protected Item
createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes)
Has to be implemented for each concrete subtype of item.java.lang.String
format(double price)
Deprecated.since ages - seeUtilities.getCurrencyInstance(Currency)
java.lang.String
format(double price, java.text.NumberFormat numberFormat)
Deprecated.since ages - seeUtilities#getCurrencyInstance()
java.lang.String
formatPrice(double price)
Deprecated.since agesjava.lang.String
formatPrice(double price, java.text.NumberFormat numberFormat)
Deprecated.since agesjava.lang.Double
getConversion(SessionContext ctx)
Generated method - Getter of theCurrency.conversion
attribute.double
getConversionFactor()
Deprecated.since ages - useGeneratedCurrency.getConversion()
insteaddouble
getConversionFactor(SessionContext ctx)
Deprecated.since ages - usegetConversion(SessionContext)
insteadprotected java.util.Map<java.lang.String,Item.AttributeMode>
getDefaultAttributeModes()
java.lang.Integer
getDigits(SessionContext ctx)
Generated method - Getter of theCurrency.digits
attribute.java.util.Currency
getJavaCurrency()
java.lang.Boolean
isBase(SessionContext ctx)
Generated method - Getter of theCurrency.base
attribute.protected java.util.Currency
matchJavaCurrency(java.lang.String code)
double
round(double value)
Deprecated.since ages - useCommonI18NService.roundCurrency(double, int)
instead.void
setBase()
Set thisCurrency
as the base currency of this system.void
setBase(SessionContext ctx, java.lang.Boolean value)
Generated method - Setter of theCurrency.base
attribute.void
setConversion(SessionContext ctx, java.lang.Double value)
Generated method - Setter of theCurrency.conversion
attribute.void
setConversionFactor(double conversionFactor)
Deprecated.since ages - useGeneratedCurrency.setConversion(double)
insteadvoid
setConversionFactor(SessionContext ctx, double conversionFactor)
Deprecated.since ages - useGeneratedCurrency.setConversion(SessionContext, double)
insteadvoid
setDigits(SessionContext ctx, java.lang.Integer digits)
Changes the number of digits used by this currency.-
Methods inherited from class de.hybris.platform.jalo.c2l.GeneratedCurrency
getConversion, getConversionAsPrimitive, getConversionAsPrimitive, getDigits, getDigitsAsPrimitive, getDigitsAsPrimitive, getSymbol, getSymbol, isBase, isBaseAsPrimitive, isBaseAsPrimitive, setBase, setBase, setBase, setConversion, setConversion, setConversion, setDigits, setDigits, setDigits, setSymbol, setSymbol
-
Methods inherited from class de.hybris.platform.jalo.c2l.C2LItem
checkConsistencyActive, checkConsistencyIsocode, getAllNames, getIsoCode, getIsoCode, isActive, setActive, setAllNames, setIsocode, setIsoCode, setIsoCode, toString
-
Methods inherited from class de.hybris.platform.jalo.c2l.GeneratedC2LItem
getAllName, getAllName, getIsocode, getIsocode, getName, getName, isActive, isActiveAsPrimitive, isActiveAsPrimitive, setActive, setActive, setActive, setAllName, setAllName, setIsocode, setName, setName
-
Methods inherited from class de.hybris.platform.jalo.GenericItem
getImplementation, getInitialProperties, getNonInitialAttributes, getRelatedItems, setRelatedItems
-
Methods inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllValuesSessionContext, getLocalizedProperty, getLocalizedProperty, getLocalizedPropertyInternal, getLocalizedPropertyNames, getLocalizedPropertyNames, hasLanguage, isEmptyValue, isFallbackEnabled, removeLocalizedProperty, removeLocalizedProperty, setAllLocalizedProperties, setAllLocalizedProperties, setLocalizedProperty, setLocalizedProperty
-
Methods inherited from class de.hybris.platform.jalo.ExtensibleItem
createNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setProperty
-
Methods inherited from class de.hybris.platform.jalo.Item
addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addLinkedItems, addNegativePermission, addPermission, addPositivePermission, assureExtensionsLoaded, changeTypeAfterCreation, checkConstraint, checkItemPermission, checkMandatoryAttribute, checkMandatoryAttribute, checkPermission, checkPermission, clearPermission, compareTo, ctx, doAfterRemove, doBeforeRemove, equals, getAccessorFor, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributes, getAllAttributesInternal, getAllLinkedItems, getAndCheckCacheBoundItem, getAttribute, getAttribute, getCacheBoundItem, getComposedType, getComposedTypePK, getCreationTime, getCurrentlyRemovingCount, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItems, getLinkedItemsCount, getLinkedItemsCount, getLinkedItemsCount, getModificationTime, getNegativePermissions, getOwner, getPermissionMap, getPermissions, getPersistenceVersion, getPK, getPositivePermissions, getRestrictedPrincipals, getSession, getSyncObject, getTenant, getTransientObject, getTransientObjectMap, hashCode, hasRegisteredClassAccessorFor, internal_registerClassAccessorFor, internal_registerNonClassAccessorFor, invalidateLocalCaches, isAlive, isCacheBound, isCurrentlyRemoving, isCurrentlyRemoving, isEmptyRelationValue, isInCreate, isInstanceOf, isItemCheckBeforeRemoveableDisabled, isMarkModifiedDisabled, isRelationLocalizationFallbackEnabled, newInstance, notifyExtensionsAfterItemCreation, notifyExtensionsBeforeItemCreation, notifyItemRemoval, notifyManagerAboutItemRemoval, readResolve, registerAccessFor, registerAccessFor, registerJaloInvalidationListeners, remove, remove, removeItemCollection, removeItemCollection, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinkedItems, removeLinks, removePartOfItems, removePartOfItems, setAllAttributes, setAllAttributes, setAllAttributesInternal, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAllLinkedItems, setAttribute, setAttribute, setAttributeFromString, setAttributeFromString, setCacheBound, setComposedType, setCreationTime, setImplementation, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setLinkedItems, setModificationTime, setNonInitialAttributes, setOwner, setPermissionsByMap, setTransientObject, setUseTA, useTA, writeReplace
-
Methods inherited from class de.hybris.platform.util.BridgeAbstraction
setTenant
-
-
-
-
Method Detail
-
createItem
protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
Description copied from class:Item
Has to be implemented for each concrete subtype of item. This method is responsible for creating a new item instance ( by calling managers, ejb homes, etc. ) duringComposedType.newInstance(Map)
.In case this method uses any of the attribute values during creation it is required to override
Item.getNonInitialAttributes(SessionContext, ItemAttributeMap)
too.
Sn example:public static final String MY_ATTRIBUTE = "someAttribute"; ... protected Item createItem(SessionContext ctx, ComposedType type, Map allAttributes ) throws JaloBusinessException { MyManager man = ... return man.createMyItem( (String)allAttributes.get(MY_ATTRIBUTE) ); // here MY_ATTRIBUTE is used for creation, so it must not be set again } protected Map getNonInitialAttributes( SessionContext ctx, Map allAttributes ) { // let superclass remove its own initial attributes Map ret = super.getNonInitialAttributes( ctx, allAttributes ); // remove MY_ATTRIBUTE from all attributes since if has already been set ret.remove(MY_ATTRIBUTE); return ret; }
- Overrides:
createItem
in classGenericItem
- Parameters:
ctx
- the current session context which this item is created withintype
- the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )- Returns:
- the new item instance
- Throws:
JaloBusinessException
- indicates an error during creation - any changes will be rollbacked
-
getDefaultAttributeModes
protected java.util.Map<java.lang.String,Item.AttributeMode> getDefaultAttributeModes()
- Overrides:
getDefaultAttributeModes
in classGeneratedCurrency
-
getJavaCurrency
public java.util.Currency getJavaCurrency()
- Since:
- 3.0 M2
-
matchJavaCurrency
protected java.util.Currency matchJavaCurrency(java.lang.String code)
-
setBase
public void setBase()
Set thisCurrency
as the base currency of this system.
-
setBase
public void setBase(SessionContext ctx, java.lang.Boolean value)
Description copied from class:GeneratedCurrency
Generated method - Setter of theCurrency.base
attribute.- Overrides:
setBase
in classGeneratedCurrency
value
- the base
-
setConversionFactor
@Deprecated public void setConversionFactor(double conversionFactor) throws JaloInvalidParameterException
Deprecated.since ages - useGeneratedCurrency.setConversion(double)
insteadChanges the conversion factor of this currency. Can not be set to '0', otherwise aJaloInvalidParameterException is thrown. - Parameters:
conversionFactor
- the conversion factor- Throws:
JaloInvalidParameterException
- if the conversion factor is set to 0.
-
setConversionFactor
@Deprecated public void setConversionFactor(SessionContext ctx, double conversionFactor) throws JaloInvalidParameterException
Deprecated.since ages - useGeneratedCurrency.setConversion(SessionContext, double)
insteadChanges the conversion factor of this currency. is thrown.- Parameters:
ctx
- theSessionContext
which will be usedconversionFactor
- the conversion factor- Throws:
JaloInvalidParameterException
- if the conversion factor is set to 0.
-
setConversion
public void setConversion(SessionContext ctx, java.lang.Double value)
Description copied from class:GeneratedCurrency
Generated method - Setter of theCurrency.conversion
attribute.- Overrides:
setConversion
in classGeneratedCurrency
value
- the conversion
-
convertAndRound
@Deprecated public double convertAndRound(Currency targetCurrency, double value)
Deprecated.since ages - useCommonI18NService.convertAndRoundCurrency(double, double, int, double)
instead.Converts a (price) value of this currency into a value for the specified target currency and rounds the result according to the target currency's digits.- Parameters:
targetCurrency
- the targetCurrency
value
- the value which should be converted- Returns:
- the converted and rounded value
-
convert
@Deprecated public double convert(Currency targetCurrency, double value)
Deprecated.since ages - useCommonI18NService.convertCurrency(double, double, double)
instead.Converts a (price) value of this currency into a value of the specified target currency. The result is not rounded.- Parameters:
targetCurrency
- the targetCurrency
value
- the value which should be converted- Returns:
- the converted value
-
setDigits
public void setDigits(SessionContext ctx, java.lang.Integer digits)
Changes the number of digits used by this currency. This attribute affects rounding of price values for thisCurrency
globally!- Overrides:
setDigits
in classGeneratedCurrency
- Parameters:
ctx
- theSessionContext
which will be useddigits
- the new number of digits used by this currency
-
round
@Deprecated public double round(double value)
Deprecated.since ages - useCommonI18NService.roundCurrency(double, int)
instead.Rounds a price value according to this currency's number of digits.- Parameters:
value
- the currency value which should be rounded.- Returns:
- the rounded currency value
-
adjustDigits
@Deprecated public static java.text.DecimalFormat adjustDigits(java.text.DecimalFormat nf, Currency c)
Deprecated.since ages- Since:
- 3.0 M2
-
adjustSymbol
@Deprecated public static java.text.DecimalFormat adjustSymbol(java.text.DecimalFormat nf, Currency c)
Deprecated.since ages- Since:
- 3.0 M2
-
formatPrice
@Deprecated public java.lang.String formatPrice(double price)
Deprecated.since agesFormats the specified price value according to this currency's properties (includes rounding). Please note that the result string will not contain the currency symbol - useformat(double)
instead!- Parameters:
price
- the price value which should be formated- Returns:
- the formated price value
-
formatPrice
@Deprecated public java.lang.String formatPrice(double price, java.text.NumberFormat numberFormat)
Deprecated.since agesFormats the specified price value according to this currency's properties (includes rounding) and uses the given NumberFormat.- Parameters:
price
- the price value which should be formattednumberFormat
- the java.text.NumberFormat for formatting the price- Returns:
- the formatted price value
- Since:
- 1.3.1
-
format
@Deprecated public java.lang.String format(double price)
Deprecated.since ages - seeUtilities.getCurrencyInstance(Currency)
Formats a price according to the current session context locale. The currency symbol will be included in the result text according to the locale's rules.- Parameters:
price
- the price value- See Also:
#format(double, Locale)
,format(double, NumberFormat)
,Utilities#getCurrencyInstance()
,Utilities.getCurrencyInstance(Currency)
,Utilities.getCurrencyInstance(Currency, Locale)
-
isBase
public java.lang.Boolean isBase(SessionContext ctx)
Description copied from class:GeneratedCurrency
Generated method - Getter of theCurrency.base
attribute.- Overrides:
isBase
in classGeneratedCurrency
- Returns:
- the base
-
format
@Deprecated public java.lang.String format(double price, java.text.NumberFormat numberFormat)
Deprecated.since ages - seeUtilities#getCurrencyInstance()
Formats a price according using a specified number format. The currency will modify the minimum and maximum digits to reflect its number of digits. In addition it will try to set its symbol as currency symbol of the given number format, which will of course only work if it's a currency format.- Parameters:
numberFormat
- the specified number formatprice
- the price value- See Also:
#format(double, Locale)
,format(double, NumberFormat)
,Utilities#getCurrencyInstance()
,Utilities.getCurrencyInstance(Currency)
,Utilities.getCurrencyInstance(Currency, Locale)
-
getConversionFactor
@Deprecated public double getConversionFactor()
Deprecated.since ages - useGeneratedCurrency.getConversion()
insteadThe conversion factor of this currency. This factor denotes the virtual value of this currency in respect to the base currency (whose conversion factor should normally be 1.0 ). Since every currency has one factor you can use theconvert(Currency, double)
method to convert values between different currencies.- Returns:
- the conversion factor of the currency.
-
getConversionFactor
@Deprecated public double getConversionFactor(SessionContext ctx)
Deprecated.since ages - usegetConversion(SessionContext)
insteadThe conversion factor of this currency. This factor denotes the virtual value of this currency in respect to the base currency (whose conversion factor should normally be '1' ).Since every currency has one factor you can use the
convert(Currency, double)
method to convert values among them.- Parameters:
ctx
- the session context can be used for cached acces of this field- Returns:
- the conversion factor
-
getConversion
public java.lang.Double getConversion(SessionContext ctx)
Description copied from class:GeneratedCurrency
Generated method - Getter of theCurrency.conversion
attribute.- Overrides:
getConversion
in classGeneratedCurrency
- Returns:
- the conversion
-
getDigits
public java.lang.Integer getDigits(SessionContext ctx)
Description copied from class:GeneratedCurrency
Generated method - Getter of theCurrency.digits
attribute.- Overrides:
getDigits
in classGeneratedCurrency
- Returns:
- the digits
-
checkRemovable
protected void checkRemovable(SessionContext ctx) throws ConsistencyCheckException
Description copied from class:Item
Checks whether or not this it may be removed or not. Called before the actual removal process.- Overrides:
checkRemovable
in classItem
- Throws:
ConsistencyCheckException
- to indicate that the item cannot be removed
-
-