Skip to content

Commit 7c00999

Browse files
committed
Updated spec to latest changes.
1 parent e4b9d46 commit 7c00999

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

src/main/asciidoc/JavaMoneySpecification.adoc

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public interface CurrencyUnit{
655655
String getCurrencyCode();
656656
int getNumericCode();
657657
int getDefaultFractionDigits();
658-
CurrencyContext getCurrencyContext();
658+
CurrencyContext getContext();
659659
}
660660
--------------------------------------------
661661
@@ -724,7 +724,7 @@ The interface is defined as follows:
724724
public interface MonetaryAmount{
725725
CurrencyUnit getCurrency();
726726
NumberValue getNumber();
727-
MonetaryContext getMonetaryContext();
727+
MonetaryContext getContext();
728728

729729
// Create a factory that allows to create a new amount based on this amount
730730
MonetaryAmountFactory<?> getFactory();
@@ -776,7 +776,7 @@ Hereby
776776
return type to a more specific implementation of +CurrencyUnit+ if desired.
777777
* +NumberValue getNumber()+ returns a +NumberValue+ (discussed within the next section) that models the numeric part of
778778
an amount for data interoperability.
779-
* +getMonetaryContext()+ allows to access the monetary meta-data context of an amount, which may include data similar
779+
* +getContext()+ allows to access the monetary meta-data context of an amount, which may include data similar
780780
to +java.math.MathContext+ but also other arbitrary attributes determined by the implementation (refer to section
781781
<<metadata modelling>> for more details on contexts).
782782
* Instances of +MonetaryOperator+ and +MonetaryQuery<R>+ can be applied on a +MonetaryAmount+ instance by passing them
@@ -1589,7 +1589,7 @@ Summarizing an +ExchangeRate+ is modelled as follows:
15891589
-------------------------------------------------------------------------------
15901590
public interface ExchangeRate extends CurrencySupplier{
15911591
...
1592-
ConversionContext getConversionContext();
1592+
ConversionContext getContext();
15931593
CurrencyUnit getBaseCurrency();
15941594
CurrencyUnit getCurrency();
15951595
NumberValue getFactor();
@@ -1605,7 +1605,7 @@ Hereby
16051605
* +isDerived()+ allows to check if the mapping in fact is backed up by a derived mapping, e.g. a triangular rate chain.
16061606
* +getExchangeRateChain()+ return the full rate chain. In case of a non derived rate, this chain must contain only
16071607
the single rate itself. In case of triangular rate the chain contains all contained subrates.
1608-
* the +ConversionContext+ accessible from +getConversionContext()+ allows to store additional meta data (refer also to
1608+
* the +ConversionContext+ accessible from +getContext()+ allows to store additional meta data (refer also to
16091609
<<MetadataModeling>> for further details) about the rate instance, such as
16101610
** the rate's provider
16111611
** the rate's timestamp
@@ -1637,7 +1637,7 @@ Summarizing an +ExchangeRateProvider+ is modelled as follows:
16371637
.Interface ExchangeRateProvider
16381638
-------------------------------------------------------------------------------
16391639
public interface ExchangeRateProvider{
1640-
ProviderContext getProviderContext();
1640+
ProviderContext getContext();
16411641

16421642
boolean isAvailable(ConversionQuery conversionQuery);
16431643
ExchangeRate getExchangeRate(ConversionQuery conversionQuery);
@@ -1717,7 +1717,7 @@ be accessed. In fact all the examples seen so far rely on the default provider c
17171717
+MonetaryConversions.getDefaultProviderChain()+. Hereby the chain contains an ordered list of provider names, which
17181718
correspond to the provider names that identify each registered +ExchangeRateProvider+ uniquely. The provider name is
17191719
defined as a mandatory attribute on the +ProviderContext+, accessible from each +ExchangeRateProvider+ from
1720-
+ExchangeRateProvider.getProviderContext()+.
1720+
+ExchangeRateProvider.getContext()+.
17211721
17221722
E.g. the output of the +European Central Bank (ECB)+ provider context, shipped with the _Moneta reference
17231723
implementation_, prints out the following when accessing +toString()+:
@@ -1801,7 +1801,7 @@ public interface MonetaryAmountFormat extends MonetaryQuery<String>{
18011801
default String format(MonetaryAmount<?> amount){...}
18021802
void print(Appendable appendable, MonetaryAmount<?> amount) throws IOException;
18031803
MonetaryAmount<?> parse(CharSequence text) throws ParseException;
1804-
AmountFormatContext getAmountFormatContext();
1804+
AmountFormatContext getContext();
18051805
}
18061806
-------------------------------------------------------------------------------
18071807
@@ -1909,7 +1909,7 @@ Hereby the above listing illustrates quite well, what are the minimal properties
19091909
+MonetaryAmountFactory+ instance to be used for creating amounts on parsing etc.
19101910
19111911
The configuration active for a concrete +MonetaryAmountFormat+ is accessible also from the +AmountFormatContext+, which
1912-
can obtained by calling +MonetaryAmountFormat.getAmountFormatContext()+.
1912+
can obtained by calling +MonetaryAmountFormat.getContext()+.
19131913
19141914
19151915
[[AccessingFormats]]
@@ -2421,7 +2421,7 @@ Hereby
24212421
24222422
* multiple +ExchangeRateProvider+ instances can be registered.
24232423
* each +ExchangeRateProvider+ is identified by it's (unique) name, accessible from
2424-
+ExchangeRateProvider.getProviderContext().getProviderName()+.
2424+
+ExchangeRateProvider.getContext().getProviderName()+.
24252425
* +getProviderNames()+ allows to evaluate the names of the registered providers for the current context.
24262426
* +getDefaultProviderChain()+ return the ordered list of provider names representing the default provider chain
24272427
used, when no explicit rounding providers are selected.
@@ -2712,18 +2712,6 @@ The following sections give further information on these concepts.
27122712
27132713
27142714
2715-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2716-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2717-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2718-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2719-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2720-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2721-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2722-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2723-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2724-
2725-
2726-
27272715
[[AbstractContext]]
27282716
=== AbstractContext ===
27292717
@@ -2739,8 +2727,6 @@ public abstract class AbstractContext
27392727
implements Serializable{
27402728
...
27412729
public String getProviderName();
2742-
public Long getTimestampMillis();
2743-
public LocalDateTime getTimestamp();
27442730

27452731
public Boolean getBoolean(String key);
27462732
public Integer getInt(String key);
@@ -2760,7 +2746,6 @@ implements Serializable{
27602746
Hereby
27612747
27622748
* each context instance is related to a provider, that created the context, accessible from +getProviderName()+.
2763-
* each context instance can have an (optional) timestamp, e.g. usable for historic data.
27642749
* additional attributes can be set, which models a type safe interface for adding properties, without
27652750
duplicating artifacts or creating non portable dependencies.
27662751
** identified by the attribute’s type.
@@ -2802,8 +2787,6 @@ builder, which provides a type safe mechanism for storing arbitrary meta-data:
28022787
public abstract class AbstractContextBuilder<B extends AbstractContextBuilder, C extends AbstractContext>
28032788
implements Serializable{
28042789
public B setProviderName(String provider);
2805-
public B setTimestampMillis(long timestamp);
2806-
public B setTimestamp(LocalDateTime timestamp);
28072790

28082791
public B set(Object value);
28092792
public <T> B set(T value, Class<? extends T> type);
@@ -2840,8 +2823,6 @@ public abstract class AbstractQuery extends AbstractContext{
28402823

28412824
public List<String> getProviderNames();
28422825
public Class<?> getTargetType();
2843-
public Long getTimestampMillis();
2844-
public TemporalAccessor getTimestamp();
28452826

28462827
}
28472828
-------------------------------------------------------------------------------
@@ -2855,7 +2836,6 @@ The query provides basic query properties:
28552836
+MonetaryCurrencies.getProviderNames+, +MonetaryRoundings.getProviderNames+, +MonetaryConversions.getProviderNames+
28562837
etc.
28572838
* a query may defines a target type, hereby defining the target result type expected.
2858-
* a query contains an (optional) timestamp defining the validity timestamp of the query's result.
28592839
28602840
Hereby +AbstractQuery+ inherits most of the functionality from the +<<AbstractContext>>+
28612841
super class.
@@ -2877,8 +2857,6 @@ public abstract class AbstractQueryBuilder<B extends javax.money.AbstractQueryBu
28772857
...
28782858
public B setProviderNames(String... providers);
28792859
public B setProviderNames(List<String> providers);
2880-
public B setTimestampMillis(long timestamp);
2881-
public B setTimestamp(TemporalUnit timestamp);
28822860
public B setTargetType(Class<?> type);
28832861
}
28842862
-------------------------------------------------------------------------------
@@ -2905,15 +2883,6 @@ Nevertheless we think some practices are important and should be followed by imp
29052883
relevant ones in the following sections.
29062884
29072885
2908-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2909-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2910-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2911-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2912-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2913-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2914-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2915-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2916-
29172886
=== Monetary Arithmetic
29182887
When dealing with monetary amounts the following aspects should be considered:
29192888
@@ -3002,6 +2971,7 @@ The precision used for displaying of monetary amounts on the screen, a printout
30022971
systems, is completely dependent on the use cases. This JSR supports these scenarios with the possibility to apply
30032972
arbitrary monetary adjustments (modeled as +MonetaryOperator+).
30042973
2974+
30052975
== Examples
30062976
The following sections illustrate the API’s usage in more detail.
30072977
@@ -3017,7 +2987,7 @@ As an example the reference implementation provides a class +org.javamoney.monet
30172987
.Class Money
30182988
-------------------------------------------------------------------------------
30192989
public final class Money
3020-
implements MonetaryAmount, Comparable<MonetaryAmount>, Serializable {
2990+
implements MonetaryAmount, Comparable<MonetaryAmount>, Serializable, CurrencySupplier {
30212991
...
30222992
}
30232993
-------------------------------------------------------------------------------
@@ -3077,7 +3047,8 @@ if(ctx.getMaxScale()>=5){
30773047
}
30783048
-------------------------------------------------------------------
30793049
3080-
Finally performing arithmetic operations in both above scenarios works similar as it is when using +java.math.BigDecimal+:
3050+
Finally performing arithmetic operations in both above scenarios works similar as it is when using
3051+
+java.math.BigDecimal+:
30813052
30823053
[source,java]
30833054
.Example Usage Monetary Arithmetic
@@ -3110,7 +3081,7 @@ When accessing +MonetaryAmountFactory+ instances it is possible to configure the
31103081
-------------------------------------------------------------------
31113082
MonetaryAmountFactory<Money> fact = MonetaryAmounts.getAmountFactory(
31123083
MonetaryAmountFactoryQueryBuilder.of(Money.class)
3113-
.set(new MathContext(250, RoundingMode.HALF_EVEN)).build()
3084+
.set(new MathContext(250, RoundingMode.HALF_DOWN)).build()
31143085
);
31153086
// Creates an instance of Money with the given MathContext
31163087
MonetaryAmount m1 = fact.setCurrency("CHF").setNumber(250.34).create();
@@ -3152,7 +3123,7 @@ the same numeric value, but with XXX (undefined) as currency:
31523123
-------------------------------------------------------------------------------
31533124
public final class ToInvalid implements MonetaryOperator{
31543125
public <T extends MonetaryAmount> T apply(T amount){
3155-
return (T)amount.getFactory().with("XXX").create();
3126+
return (T)amount.getFactory().setCurrency("XXX").create();
31563127
}
31573128
}
31583129
-------------------------------------------------------------------------------
@@ -3263,12 +3234,16 @@ The present value (abbreviated PV) shows how financial formulas can be implement
32633234
models the current value of a financial in- or outflow in the future, weighted with a calculatory interest rate.
32643235
The PV is defined as follows:
32653236
3237+
C
3238+
-------
3239+
(1+r)^n
32663240

32673241
Hereby
32683242

3269-
* the time of the cash flow (in periods)
3270-
* the discount rate (the rate of return that could be earned on an investment in the financial markets with similar risk.); the opportunity cost of capital
3271-
* the net cash flow i.e. cash inflow – cash outflow, at time t . For educational purposes,
3243+
* +n+ is the time of the cash flow (in periods)
3244+
* +r+ is the discount rate (the rate of return that could be earned on an investment in the financial markets with
3245+
similar risk.); the opportunity cost of capital.
3246+
* +C+ is the net cash flow i.e. cash inflow – cash outflow, at time t . For educational purposes,
32723247

32733248
The same financial function now can be implemented for example as follows:
32743249

@@ -3356,7 +3331,7 @@ CurrencyConversion conv = MonetaryConversions.getConversion(ConversionQueryBuild
33563331
.setProviders("CS", "EZB", "IMF")
33573332
.setTermCurrency("EUR")
33583333
.set(MonetaryAmount.class, inCHF, MonetaryAmount.class)
3359-
.setTimestamp(ts)
3334+
.set(LocalDate.of(2008, 1, 1))
33603335
.setRateType(RateType.HISTORIC)
33613336
.set(StockExchange.NYSE) // custom type
33623337
.set("contractId", "AA-1234.2")
@@ -3396,7 +3371,6 @@ Public Source Code Repository on GitHub: http://github.com/JavaMoney,
33963371
Branch/Tag matching updated PDR is {version}
33973372

33983373

3399-
34003374
=== Links
34013375
* http://jcp.org/en/jsr/detail?id=35[JSR 354 on jcp.org]
34023376
* http://java.net/projects/javamoney/[JavaMoney Project on Java.net]

0 commit comments

Comments
 (0)