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 currentJaloSessiondefines the defaultCurrencyof this session. All pricing information will use thisCurrencyby default. Some examples for the use ofCurrencyitems: 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.DecimalFormatadjustDigits(java.text.DecimalFormat nf, Currency c)Deprecated.since agesstatic java.text.DecimalFormatadjustSymbol(java.text.DecimalFormat nf, Currency c)Deprecated.since agesprotected voidcheckRemovable(SessionContext ctx)Checks whether or not this it may be removed or not.doubleconvert(Currency targetCurrency, double value)Deprecated.since ages - useCommonI18NService.convertCurrency(double, double, double)instead.doubleconvertAndRound(Currency targetCurrency, double value)Deprecated.since ages - useCommonI18NService.convertAndRoundCurrency(double, double, int, double)instead.protected ItemcreateItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes)Has to be implemented for each concrete subtype of item.java.lang.Stringformat(double price)Deprecated.since ages - seeUtilities.getCurrencyInstance(Currency)java.lang.Stringformat(double price, java.text.NumberFormat numberFormat)Deprecated.since ages - seeUtilities#getCurrencyInstance()java.lang.StringformatPrice(double price)Deprecated.since agesjava.lang.StringformatPrice(double price, java.text.NumberFormat numberFormat)Deprecated.since agesjava.lang.DoublegetConversion(SessionContext ctx)Generated method - Getter of theCurrency.conversionattribute.doublegetConversionFactor()Deprecated.since ages - useGeneratedCurrency.getConversion()insteaddoublegetConversionFactor(SessionContext ctx)Deprecated.since ages - usegetConversion(SessionContext)insteadprotected java.util.Map<java.lang.String,Item.AttributeMode>getDefaultAttributeModes()java.lang.IntegergetDigits(SessionContext ctx)Generated method - Getter of theCurrency.digitsattribute.java.util.CurrencygetJavaCurrency()java.lang.BooleanisBase(SessionContext ctx)Generated method - Getter of theCurrency.baseattribute.protected java.util.CurrencymatchJavaCurrency(java.lang.String code)doubleround(double value)Deprecated.since ages - useCommonI18NService.roundCurrency(double, int)instead.voidsetBase()Set thisCurrencyas the base currency of this system.voidsetBase(SessionContext ctx, java.lang.Boolean value)Generated method - Setter of theCurrency.baseattribute.voidsetConversion(SessionContext ctx, java.lang.Double value)Generated method - Setter of theCurrency.conversionattribute.voidsetConversionFactor(double conversionFactor)Deprecated.since ages - useGeneratedCurrency.setConversion(double)insteadvoidsetConversionFactor(SessionContext ctx, double conversionFactor)Deprecated.since ages - useGeneratedCurrency.setConversion(SessionContext, double)insteadvoidsetDigits(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:ItemHas 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:
createItemin 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:
getDefaultAttributeModesin 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 thisCurrencyas the base currency of this system.
-
setBase
public void setBase(SessionContext ctx, java.lang.Boolean value)
Description copied from class:GeneratedCurrencyGenerated method - Setter of theCurrency.baseattribute.- Overrides:
setBasein classGeneratedCurrencyvalue- the base
-
setConversionFactor
@Deprecated public void setConversionFactor(double conversionFactor) throws JaloInvalidParameterExceptionDeprecated.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- theSessionContextwhich 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:GeneratedCurrencyGenerated method - Setter of theCurrency.conversionattribute.- Overrides:
setConversionin classGeneratedCurrencyvalue- 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 targetCurrencyvalue- 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 targetCurrencyvalue- 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 thisCurrencyglobally!- Overrides:
setDigitsin classGeneratedCurrency- Parameters:
ctx- theSessionContextwhich 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:GeneratedCurrencyGenerated method - Getter of theCurrency.baseattribute.- Overrides:
isBasein 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:GeneratedCurrencyGenerated method - Getter of theCurrency.conversionattribute.- Overrides:
getConversionin classGeneratedCurrency- Returns:
- the conversion
-
getDigits
public java.lang.Integer getDigits(SessionContext ctx)
Description copied from class:GeneratedCurrencyGenerated method - Getter of theCurrency.digitsattribute.- Overrides:
getDigitsin classGeneratedCurrency- Returns:
- the digits
-
checkRemovable
protected void checkRemovable(SessionContext ctx) throws ConsistencyCheckException
Description copied from class:ItemChecks whether or not this it may be removed or not. Called before the actual removal process.- Overrides:
checkRemovablein classItem- Throws:
ConsistencyCheckException- to indicate that the item cannot be removed
-
-