Package de.hybris.platform.jalo.c2l
Class Currency
- All Implemented Interfaces:
Serializable,Comparable
The hybris Platform currency item.
Currencies are used mainly for pricing purpose. For this reason the <codeCurrency specified in
SessionContext.getCurrency() of the current
JaloSession defines the default Currency of this session. All pricing
information will use this Currency by default.
Some examples for the use of Currency 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:
-
Nested Class Summary
Nested classes/interfaces inherited from class de.hybris.platform.jalo.GenericItem
GenericItem.GenericItemImplNested classes/interfaces inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LocalizableItem.LocalizableItemImplNested classes/interfaces inherited from class de.hybris.platform.jalo.ExtensibleItem
ExtensibleItem.ExtensibleItemImplNested 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, SYMBOLFields inherited from class de.hybris.platform.jalo.c2l.GeneratedC2LItem
ACTIVE, ISOCODE, NAMEFields inherited from class de.hybris.platform.jalo.c2l.LocalizableItem
LANGUAGE_FALLBACK_ENABLEDFields 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, TYPEFields inherited from class de.hybris.platform.util.BridgeAbstraction
impl, tenant -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DecimalFormatadjustDigits(DecimalFormat nf, Currency c) Deprecated.since agesstatic DecimalFormatadjustSymbol(DecimalFormat nf, Currency c) Deprecated.since agesprotected voidChecks whether or not this it may be removed or not.doubleDeprecated.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.format(double price) Deprecated.since ages - seeUtilities.getCurrencyInstance(Currency)format(double price, NumberFormat numberFormat) Deprecated.since ages - seeUtilities#getCurrencyInstance()formatPrice(double price) Deprecated.since agesformatPrice(double price, NumberFormat numberFormat) Deprecated.since agesGenerated method - Getter of theCurrency.conversionattribute.doubleDeprecated.since ages - useGeneratedCurrency.getConversion()insteaddoubleDeprecated.since ages - usegetConversion(SessionContext)insteadprotected Map<String,Item.AttributeMode> getDigits(SessionContext ctx) Generated method - Getter of theCurrency.digitsattribute.isBase(SessionContext ctx) Generated method - Getter of theCurrency.baseattribute.protected CurrencymatchJavaCurrency(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, Boolean value) Generated method - Setter of theCurrency.baseattribute.voidsetConversion(SessionContext ctx, 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, 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, setSymbolMethods inherited from class de.hybris.platform.jalo.c2l.C2LItem
checkConsistencyActive, checkConsistencyIsocode, getAllNames, getIsoCode, getIsoCode, isActive, setActive, setAllNames, setIsocode, setIsoCode, setIsoCode, toStringMethods 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, setNameMethods inherited from class de.hybris.platform.jalo.GenericItem
getImplementation, getInitialProperties, getNonInitialAttributes, getRelatedItems, getRelatedItems, setRelatedItemsMethods 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, setLocalizedPropertyMethods inherited from class de.hybris.platform.jalo.ExtensibleItem
createNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setPropertyMethods 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, getPartOfRemovedSessionMarker, 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, suppressRelation, useTA, writeReplaceMethods inherited from class de.hybris.platform.util.BridgeAbstraction
setTenant
-
Constructor Details
-
Currency
public Currency()
-
-
Method Details
-
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
- Overrides:
getDefaultAttributeModesin classGeneratedCurrency
-
getJavaCurrency
- Since:
- 3.0 M2
-
matchJavaCurrency
-
setBase
public void setBase()Set thisCurrencyas the base currency of this system. -
setBase
Description copied from class:GeneratedCurrencyGenerated method - Setter of theCurrency.baseattribute.- Overrides:
setBasein classGeneratedCurrencyvalue- the base
-
setConversionFactor
@Deprecated(since="ages", forRemoval=false) 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(since="ages", forRemoval=false) 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
Description copied from class:GeneratedCurrencyGenerated method - Setter of theCurrency.conversionattribute.- Overrides:
setConversionin classGeneratedCurrencyvalue- the conversion
-
convertAndRound
@Deprecated(since="ages", forRemoval=false) 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(since="ages", forRemoval=false) 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
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.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(since="ages", forRemoval=false) public static DecimalFormat adjustDigits(DecimalFormat nf, Currency c) Deprecated.since ages- Since:
- 3.0 M2
-
adjustSymbol
@Deprecated(since="ages", forRemoval=false) public static DecimalFormat adjustSymbol(DecimalFormat nf, Currency c) Deprecated.since ages- Since:
- 3.0 M2
-
formatPrice
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(since="ages", forRemoval=false) public String formatPrice(double price, 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.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
Description copied from class:GeneratedCurrencyGenerated method - Getter of theCurrency.baseattribute.- Overrides:
isBasein classGeneratedCurrency- Returns:
- the base
-
format
@Deprecated(since="ages", forRemoval=false) public String format(double price, 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.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.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
Description copied from class:GeneratedCurrencyGenerated method - Getter of theCurrency.conversionattribute.- Overrides:
getConversionin classGeneratedCurrency- Returns:
- the conversion
-
getDigits
Description copied from class:GeneratedCurrencyGenerated method - Getter of theCurrency.digitsattribute.- Overrides:
getDigitsin classGeneratedCurrency- Returns:
- the digits
-
checkRemovable
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
-