public class Currency extends GeneratedCurrency
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
GenericItem.GenericItemImplLocalizableItem.LocalizableItemImplExtensibleItem.ExtensibleItemImplItem.AttributeFilter, Item.AttributeMode, Item.CachedGetter, Item.CachedSetter, Item.ItemAttributeMap, Item.ItemConstraint, Item.ItemImpl, Item.JaloCachedComputationExceptionBASE, CONVERSION, DEFAULT_INITIAL_ATTRIBUTES, DIGITS, SYMBOLACTIVE, ISOCODE, NAMELANGUAGE_FALLBACK_ENABLED_CREATION_TIME_INTERNAL, _MODIFIED_TIME_INTERNAL, accessorLog, CREATION_TIME, DISABLE_ATTRIBUTE_CHECK, DISABLE_ITEMCHECK_BEFORE_REMOVABLE, EVEN, FEATURE_ACCESSMAP_QUALIFIER, INITIAL_CREATION_FLAG, isJaloOnly, MODIFIED_TIME, NEGATIVE, NOT_FOUND, OWNER, PK, POSITIVE, SAVE_FROM_SERVICE_LAYER, staticTransientObjects, TYPEimpl, tenant| Constructor and Description |
|---|
Currency() |
| Modifier and Type | Method and Description |
|---|---|
static DecimalFormat |
adjustDigits(DecimalFormat nf,
Currency c)
Deprecated.
|
static DecimalFormat |
adjustSymbol(DecimalFormat nf,
Currency c)
Deprecated.
|
protected void |
checkRemovable(SessionContext ctx)
Checks whether or not this it may be removed or not.
|
double |
convert(Currency targetCurrency,
double value)
Deprecated.
|
double |
convertAndRound(Currency targetCurrency,
double value)
Deprecated.
|
protected Item |
createItem(SessionContext ctx,
ComposedType type,
Item.ItemAttributeMap allAttributes)
Has to be implemented for each concrete subtype of item.
|
String |
format(double price)
Deprecated.
|
String |
format(double price,
Locale locale)
Deprecated.
|
String |
format(double price,
NumberFormat numberFormat)
Deprecated.
|
String |
formatPrice(double price)
Deprecated.
|
String |
formatPrice(double price,
NumberFormat numberFormat)
Deprecated.
|
Double |
getConversion(SessionContext ctx)
Generated method - Getter of the
Currency.conversion attribute. |
double |
getConversionFactor()
Deprecated.
use
GeneratedCurrency.getConversion() instead |
double |
getConversionFactor(SessionContext ctx)
Deprecated.
use
getConversion(SessionContext) instead |
protected Map<String,Item.AttributeMode> |
getDefaultAttributeModes() |
Integer |
getDigits(SessionContext ctx)
Generated method - Getter of the
Currency.digits attribute. |
Currency |
getJavaCurrency() |
Boolean |
isBase(SessionContext ctx)
Generated method - Getter of the
Currency.base attribute. |
protected Currency |
matchJavaCurrency(String code) |
double |
round(double value)
Deprecated.
use
CommonI18NService.roundCurrency(double, int) instead. |
void |
setBase()
Set this
Currency as the base currency of this system. |
void |
setBase(SessionContext ctx,
Boolean value)
Generated method - Setter of the
Currency.base attribute. |
void |
setConversion(SessionContext ctx,
Double value)
Generated method - Setter of the
Currency.conversion attribute. |
void |
setConversionFactor(double conversionFactor)
Deprecated.
use
GeneratedCurrency.setConversion(double) instead |
void |
setConversionFactor(SessionContext ctx,
double conversionFactor)
Deprecated.
|
void |
setDigits(SessionContext ctx,
Integer digits)
Changes the number of digits used by this currency.
|
getConversion, getConversionAsPrimitive, getConversionAsPrimitive, getDigits, getDigitsAsPrimitive, getDigitsAsPrimitive, getSymbol, getSymbol, isBase, isBaseAsPrimitive, isBaseAsPrimitive, setBase, setBase, setBase, setConversion, setConversion, setConversion, setDigits, setDigits, setDigits, setSymbol, setSymbolcheckConsistencyActive, checkConsistencyIsocode, getAllNames, getIsoCode, getIsoCode, isActive, setActive, setAllNames, setIsocode, setIsoCode, setIsoCode, toStringgetAllName, getAllName, getIsocode, getIsocode, getName, getName, isActive, isActiveAsPrimitive, isActiveAsPrimitive, setActive, setActive, setActive, setAllName, setAllName, setIsocode, setName, setNamegetInitialProperties, getNonInitialAttributesgetAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllLocalizedProperties, getAllValuesSessionContext, getLocalizedProperty, getLocalizedProperty, getLocalizedPropertyInternal, getLocalizedPropertyNames, getLocalizedPropertyNames, hasLanguage, isEmptyValue, isFallbackEnabled, removeLocalizedProperty, removeLocalizedProperty, setAllLocalizedProperties, setAllLocalizedProperties, setLocalizedProperty, setLocalizedPropertycreateNonClassAccessor, getAllProperties, getAllProperties, getProperty, getProperty, getPropertyNames, getPropertyNames, removeProperty, removeProperty, setAllProperties, setAllProperties, setProperty, setPropertyaddLinkedItems, 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, isRelationLocalizationFallbackEnabled, newInstance, notifyExtensionsAfterItemCreation, notifyExtensionsBeforeItemCreation, notifyItemRemoval, readResolve, refreshRemote, 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, writeReplacegetImplementation, setTenantprotected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
ItemComposedType.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; }
createItem in class GenericItemctx - 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 )JaloBusinessException - indicates an error during creation - any changes will be rollbackedprotected Map<String,Item.AttributeMode> getDefaultAttributeModes()
getDefaultAttributeModes in class GeneratedCurrencypublic Currency getJavaCurrency()
public void setBase()
Currency as the base currency of this system.public void setBase(SessionContext ctx, Boolean value)
GeneratedCurrencyCurrency.base attribute.setBase in class GeneratedCurrencyvalue - the base@Deprecated public void setConversionFactor(double conversionFactor) throws JaloInvalidParameterException
GeneratedCurrency.setConversion(double) insteadconversionFactor - the conversion factorJaloInvalidParameterException - if the conversion factor is set to 0.@Deprecated public void setConversionFactor(SessionContext ctx, double conversionFactor) throws JaloInvalidParameterException
GeneratedCurrency.setConversion(SessionContext, double) insteadctx - the SessionContext which will be usedconversionFactor - the conversion factorJaloInvalidParameterException - if the conversion factor is set to 0.public void setConversion(SessionContext ctx, Double value)
GeneratedCurrencyCurrency.conversion attribute.setConversion in class GeneratedCurrencyvalue - the conversion@Deprecated public double convertAndRound(Currency targetCurrency, double value)
CommonI18NService.convertAndRoundCurrency(double, double, int, double)
instead.targetCurrency - the target Currencyvalue - the value which should be converted@Deprecated public double convert(Currency targetCurrency, double value)
CommonI18NService.convertCurrency(double, double, double)
instead.targetCurrency - the target Currencyvalue - the value which should be convertedpublic void setDigits(SessionContext ctx, Integer digits)
Currency globally!setDigits in class GeneratedCurrencyctx - the SessionContext which will be useddigits - the new number of digits used by this currency@Deprecated public double round(double value)
CommonI18NService.roundCurrency(double, int) instead.value - the currency value which should be rounded.@Deprecated public static DecimalFormat adjustDigits(DecimalFormat nf, Currency c)
@Deprecated public static DecimalFormat adjustSymbol(DecimalFormat nf, Currency c)
@Deprecated public String formatPrice(double price)
format(double)
instead!price - the price value which should be formated@Deprecated public String formatPrice(double price, NumberFormat numberFormat)
price - the price value which should be formattednumberFormat - the java.text.NumberFormat for formatting the price@Deprecated public String format(double price)
Utilities.getCurrencyInstance(Currency)price - the price valueformat(double, Locale),
format(double, NumberFormat),
Utilities.getCurrencyInstance(),
Utilities.getCurrencyInstance(Currency),
Utilities.getCurrencyInstance(Currency, Locale)@Deprecated public String format(double price, Locale locale)
Utilities.getCurrencyInstance(Currency, Locale)locale - the locale which determines the currency pattern, decimal delimter and currency symbol positionprice - the price valueformat(double, Locale),
format(double, NumberFormat),
Utilities.getCurrencyInstance(),
Utilities.getCurrencyInstance(Currency),
Utilities.getCurrencyInstance(Currency, Locale)public Boolean isBase(SessionContext ctx)
GeneratedCurrencyCurrency.base attribute.isBase in class GeneratedCurrency@Deprecated public String format(double price, NumberFormat numberFormat)
Utilities.getCurrencyInstance()numberFormat - the specified number formatprice - the price valueformat(double, Locale),
format(double, NumberFormat),
Utilities.getCurrencyInstance(),
Utilities.getCurrencyInstance(Currency),
Utilities.getCurrencyInstance(Currency, Locale)@Deprecated public double getConversionFactor()
GeneratedCurrency.getConversion() insteadconvert(Currency,double) method to convert values between different currencies.@Deprecated public double getConversionFactor(SessionContext ctx)
getConversion(SessionContext) instead
Since every currency has one factor you can use the convert(Currency,double) method to convert values
among them.
ctx - the session context can be used for cached acces of this fieldpublic Double getConversion(SessionContext ctx)
GeneratedCurrencyCurrency.conversion attribute.getConversion in class GeneratedCurrencypublic Integer getDigits(SessionContext ctx)
GeneratedCurrencyCurrency.digits attribute.getDigits in class GeneratedCurrencyprotected void checkRemovable(SessionContext ctx) throws ConsistencyCheckException
ItemcheckRemovable in class ItemConsistencyCheckException - to indicate that the item cannot be removedCopyright © 2017 SAP SE. All Rights Reserved.