T apply(T amount){
- // cast should be safe for implementations that adhere to this spec
- return (T)amount.divide(divisor);
- }
-
- public String toString(){...}
-}
--------------------------------------------------------------------
-
-For simplicity we did not add additional feature such as caching of PresentValue instances using a static factory
-method, or pre-calculation of divisor matrices. Now given the +MonetaryOperator+ a present value can be
-calculated as follows:
-
-[source,java]
-.Example Using a Financial Function
--------------------------------------------------------------------
-Money m = Money.of("CHF", 1000);
-// present value for an amount of 100, available in two periods,
-// with a rate of 5%.
-Money pv = m.with(new PresentValue(new BigDecimal("0.05"), 2));
--------------------------------------------------------------------
-
-
-=== Performing Currency Conversion
-Currency Conversion also is a special case of a +MonetaryOperator+ since it creates a new amount based on another
-amount. Hereby by the conversion the resulting amount will typically have a different currency and a different
-numeric amount:
-
-[source,java]
-.Example Currency Conversion
--------------------------------------------------------------------
-MonetaryAmount inCHF =...;
-CurrencyConversion conv = MonetaryConversions.getConversion("EUR");
-MonetaryAmount inEUR = inCHF.with(conv);
--------------------------------------------------------------------
-
-Also we can define the providers to be used for currency conversion by passing the provider names explicitly:
-[source,java]
--------------------------------------------------------------------------------
-CurrencyConversion conv = MonetaryConversions.getConversion("EUR", "ECB", "IMF");
--------------------------------------------------------------------------------
-
-To cover also more complex usage scenarios we can also pass a +ConversionQuery+ with additional parameters for
-conversion, e.g.:
-
-[source,java]
--------------------------------------------------------------------
-MonetaryAmount inCHF =...;
-CurrencyConversion conv = MonetaryConversions.getConversion(ConversionQueryBuilder.of()
- .setProviders("CS", "ECB", "IMF")
- .setTermCurrency("EUR")
- .set(MonetaryAmount.class, inCHF, MonetaryAmount.class)
- .set(LocalDate.of(2008, 1, 1))
- .setRateType(RateType.HISTORIC)
- .set(StockExchange.NYSE) // custom type
- .set("contractId", "AA-1234.2")
- .build());
-MonetaryAmount inEUR = inCHF.with(conv);
--------------------------------------------------------------------
-
-:numbered!:
-
-== APPENDIX
-[[Bibliography]]
-=== Bibliography
-
-[[[Bitcoin]]]
-http://bitcoin.org/en/
-
-[[[ICU]]]
-http://site.icu-project.org/
-
-[[[ISO-4217]]]
-http://www.iso.org/iso/home/standards/currency_codes.htm
-
-[[[ISO-20022]]]
-http://www.iso20022.org
-
-[[[JadiraFramework]]]
-The Jadira Framework adds Hibernate support for +MonetaryAmount+ if the JSR 354 API and an implementation are on the class path: http://jadira.sourceforge.net/project-info.html
-
-[[[JakartaBeanValidation]]]
-Hibernate Validator supports any sub-type of +MonetaryAmount+ if the JSR 354 API and an implementation are on the class path:
-https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-gettingstarted
-
-[[[SpringSupport]]]
-Since release 4.2 the https://spring.io/projects/spring-framework[Spring Framework] supports JSR 354: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/format/number/money/package-summary.html
-
-[[[ZalandoJacksonBinding]]]
-Zalando created Jackson Binding for JSR 354: https://github.com/zalando/jackson-datatype-money
-
-[[[JodaMoney]]]
-http://www.joda.org/joda-money/
-
-[[[GitHub]]]
-https://javamoney.github.io/
-
-[[[JSR354]]]
-http://jcp.org/en/jsr/detail?id=354
-
-[[[source]]]
-Public Source Code Repository on GitHub: http://github.com/JavaMoney,
- Branch/Tag matching updated PDR is {version}
-
-=== Links
-* http://jcp.org/en/jsr/detail?id=35[JSR 354 on jcp.org]
-* https://github.com/JavaMoney/[JavaMoney Project on GitHub]
- ** https://github.com/JavaMoney/jsr354-api/[JSR 354 API GitHub Repository]
- ** https://github.com/JavaMoney/jsr354-ri/[Moneta RI GitHub Repository]
-* http://www.javapractices.com/topic/TopicAction.do?Id=13[Java Practices about Representing Money]
-* http://blog.eisele.net/2011/08/working-with-money-in-java.html[Working with Money in Java]
-* http://mindprod.com/jgloss/currency.html[Java currency] by Roedy Green, http://mindprod.com[Canadian Mind Products]
-* http://www.eclipse.org/uomo/[UOMo Business], based on ICU4J and concepts by JScience Economics]
-* http://site.icu-project.org/[ICU4J] Uses Number for all operations and internal storage in its Money type.
-* http://moneydance.com/dev/apidoc/[MoneyDance API]
-* http://javamoney.org[JavaMoney] is the Apache 2.0 licensed OSS project that evolved from JSR 354 development. It provides concrete implementations for currency conversion and mapping, advanced formatting, historic data access, regions and a set of financial calculations and formulas.
-* http://www.joda.org/joda-money[Joda Money] can be referred to as an inspiration for API and design style. it is based on real-world use cases in an e-commerce application for airlines
-* http://grails.org/plugin/currencies[Grails Currencies] uses BigDecimal as internal representation, but API only exposes Number in all Money operations like plus(), minus() or similar.
-* http://lemnik.wordpress.com/2011/03/25/bigdecimal-and-your-money/[Why not to use BigDecimal for Money]
-* http://de.wikipedia.org/wiki/M-Pesa[M-Pesa-Mobile Money] in Africa
-* Currency Internationalization (i18n), Multiple Currencies and Foreign Exchange (FX).
-* http://en.wikipedia.org/wiki/Japanese_units_of_measurement#Money: Discussion of internationalization of currencies, rounding, grouping and formatting, separators etc]
-* http://speleotrove.com/decimal/
-* http://sourceforge.net/projects/oquote/
-* http://en.wikipedia.org/wiki/Karatsuba_algorithm[Karatsuba Algorithm] for Fast Big Decimal Multiplication
-
-=== Related Initiatives
-* http://timeandmoney.sourceforge.net/ [Eric Evans Time and Money Library]
-* http://bitcoinj.github.io/ [Bitcoin Java Client]
diff --git a/src/main/asciidoc/images/highlighter.png b/src/main/asciidoc/images/highlighter.png
deleted file mode 100644
index b31145948..000000000
Binary files a/src/main/asciidoc/images/highlighter.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/README b/src/main/asciidoc/images/icons/README
deleted file mode 100644
index f12b2a730..000000000
--- a/src/main/asciidoc/images/icons/README
+++ /dev/null
@@ -1,5 +0,0 @@
-Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook
-icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency
-from the Jimmac icons to get round MS IE and FOP PNG incompatibilies.
-
-Stuart Rackham
diff --git a/src/main/asciidoc/images/icons/callouts/1.png b/src/main/asciidoc/images/icons/callouts/1.png
deleted file mode 100644
index 7d473430b..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/1.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/10.png b/src/main/asciidoc/images/icons/callouts/10.png
deleted file mode 100644
index 997bbc824..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/10.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/11.png b/src/main/asciidoc/images/icons/callouts/11.png
deleted file mode 100644
index ce47dac3f..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/11.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/12.png b/src/main/asciidoc/images/icons/callouts/12.png
deleted file mode 100644
index 31daf4e2f..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/12.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/13.png b/src/main/asciidoc/images/icons/callouts/13.png
deleted file mode 100644
index 14021a89c..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/13.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/14.png b/src/main/asciidoc/images/icons/callouts/14.png
deleted file mode 100644
index 64014b75f..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/14.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/15.png b/src/main/asciidoc/images/icons/callouts/15.png
deleted file mode 100644
index 0d65765fc..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/15.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/2.png b/src/main/asciidoc/images/icons/callouts/2.png
deleted file mode 100644
index 5d09341b2..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/2.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/3.png b/src/main/asciidoc/images/icons/callouts/3.png
deleted file mode 100644
index ef7b70047..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/3.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/4.png b/src/main/asciidoc/images/icons/callouts/4.png
deleted file mode 100644
index adb8364eb..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/4.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/5.png b/src/main/asciidoc/images/icons/callouts/5.png
deleted file mode 100644
index 4d7eb4600..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/5.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/6.png b/src/main/asciidoc/images/icons/callouts/6.png
deleted file mode 100644
index 0ba694af6..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/6.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/7.png b/src/main/asciidoc/images/icons/callouts/7.png
deleted file mode 100644
index 472e96f8a..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/7.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/8.png b/src/main/asciidoc/images/icons/callouts/8.png
deleted file mode 100644
index 5e60973c2..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/8.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/callouts/9.png b/src/main/asciidoc/images/icons/callouts/9.png
deleted file mode 100644
index a0676d26c..000000000
Binary files a/src/main/asciidoc/images/icons/callouts/9.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/caution.png b/src/main/asciidoc/images/icons/caution.png
deleted file mode 100644
index 9a8c515a1..000000000
Binary files a/src/main/asciidoc/images/icons/caution.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/example.png b/src/main/asciidoc/images/icons/example.png
deleted file mode 100644
index 1199e864f..000000000
Binary files a/src/main/asciidoc/images/icons/example.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/home.png b/src/main/asciidoc/images/icons/home.png
deleted file mode 100644
index 37a5231ba..000000000
Binary files a/src/main/asciidoc/images/icons/home.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/important.png b/src/main/asciidoc/images/icons/important.png
deleted file mode 100644
index be685cc4e..000000000
Binary files a/src/main/asciidoc/images/icons/important.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/next.png b/src/main/asciidoc/images/icons/next.png
deleted file mode 100644
index 64e126bdd..000000000
Binary files a/src/main/asciidoc/images/icons/next.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/note.png b/src/main/asciidoc/images/icons/note.png
deleted file mode 100644
index 7c1f3e2fa..000000000
Binary files a/src/main/asciidoc/images/icons/note.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/prev.png b/src/main/asciidoc/images/icons/prev.png
deleted file mode 100644
index 3e8f12fe2..000000000
Binary files a/src/main/asciidoc/images/icons/prev.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/tip.png b/src/main/asciidoc/images/icons/tip.png
deleted file mode 100644
index f087c73b7..000000000
Binary files a/src/main/asciidoc/images/icons/tip.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/up.png b/src/main/asciidoc/images/icons/up.png
deleted file mode 100644
index 2db1ce62f..000000000
Binary files a/src/main/asciidoc/images/icons/up.png and /dev/null differ
diff --git a/src/main/asciidoc/images/icons/warning.png b/src/main/asciidoc/images/icons/warning.png
deleted file mode 100644
index d41edb9ad..000000000
Binary files a/src/main/asciidoc/images/icons/warning.png and /dev/null differ
diff --git a/src/main/asciidoc/images/javamoney_cup.jpg b/src/main/asciidoc/images/javamoney_cup.jpg
deleted file mode 100644
index 077bd20d8..000000000
Binary files a/src/main/asciidoc/images/javamoney_cup.jpg and /dev/null differ
diff --git a/src/main/asciidoc/images/smallnew.png b/src/main/asciidoc/images/smallnew.png
deleted file mode 100644
index 411c2e178..000000000
Binary files a/src/main/asciidoc/images/smallnew.png and /dev/null differ
diff --git a/src/main/asciidoc/images/spi.jpg b/src/main/asciidoc/images/spi.jpg
deleted file mode 100644
index 2865e0d87..000000000
Binary files a/src/main/asciidoc/images/spi.jpg and /dev/null differ
diff --git a/src/main/asciidoc/images/tiger.png b/src/main/asciidoc/images/tiger.png
deleted file mode 100644
index 332b11f3a..000000000
Binary files a/src/main/asciidoc/images/tiger.png and /dev/null differ
diff --git a/src/main/java/javax/money/AbstractContext.java b/src/main/java/javax/money/AbstractContext.java
deleted file mode 100644
index 77341caef..000000000
--- a/src/main/java/javax/money/AbstractContext.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * Represents a general context of data targeting an item of type {@code Q}. Contexts are used to add arbitrary
- * data that cannot be be mapped in a standard way to the money API, e.g. use case or customer specific
- * extensions or specialities.
- * Superclasses of this class must be final, immutable, serializable and thread-safe.
- */
-@SuppressWarnings("unchecked")
-public abstract class AbstractContext implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Key for storing the target providers to be queried
- */
- protected static final String KEY_PROVIDER = "provider";
-
-
- /**
- * The data map containing all values.
- */
- final Map data = new HashMap<>();
-
- /**
- * Private constructor, used by {@link AbstractContextBuilder}.
- *
- * @param builder the Builder.
- */
- protected AbstractContext(AbstractContextBuilder, ?> builder) {
- data.putAll(builder.data);
- }
-
- /**
- * Get the present keys of all entries with a given type, checking hereby if assignable.
- *
- * @param type The attribute type, not null.
- * @return all present keys of attributes being assignable to the type, never null.
- */
- public Set getKeys(Class> type) {
- return data.entrySet().stream().filter(val -> type.isAssignableFrom(val.getValue()
- .getClass())).map(Map.Entry::getKey).collect(Collectors
- .toSet());
- }
-
- /**
- * Get the current attribute type.
- * @param key the entry's key, not null
- * @return the current attribute type, or null, if no such attribute exists.
- */
- public Class> getType(String key) {
- Object val = this.data.get(key);
- return val == null ? null : val.getClass();
- }
-
-
- /**
- * Access an attribute.
- *
- * @param type the attribute's type, not {@code null}
- * @param key the attribute's key, not {@code null}
- * @return the attribute value, or {@code null}.
- */
- public T get(String key, Class type) {
- Object value = this.data.get(key);
- if (value != null && type.isAssignableFrom(value.getClass())) {
- return (T) value;
- }
- return null;
- }
-
- /**
- * Access an attribute, hereby using the class name as key.
- *
- * @param type the type, not {@code null}
- * @return the type attribute value, or {@code null}.
- */
- public T get(Class type) {
- return get(type.getName(), type);
- }
-
-
- /**
- * Access a Long attribute.
- *
- * @param key the attribute's key, not null.
- * @return the value, or null.
- */
- public Long getLong(String key) {
- return get(key, Long.class);
- }
-
-
- /**
- * Access a Float attribute.
- *
- * @param key the attribute's key, not null.
- * @return the value, or null.
- */
- public Float getFloat(String key) {
- return get(key, Float.class);
- }
-
- /**
- * Access an Integer attribute.
- *
- * @param key the attribute's key, not null.
- * @return the value, or null.
- */
- public Integer getInt(String key) {
- return get(key, Integer.class);
- }
-
- /**
- * Access a Boolean attribute.
- *
- * @param key the attribute's key, not null.
- * @return the value, or null.
- */
- public Boolean getBoolean(String key) {
- return get(key, Boolean.class);
- }
-
- /**
- * Access a Double attribute.
- *
- * @param key the attribute's key, not null.
- * @return the value, or null.
- */
- public Double getDouble(String key) {
- return get(key, Double.class);
- }
-
- /**
- * Access a String attribute.
- *
- * @param key the attribute's key, not null.
- * @return the value, or null.
- */
- public String getText(String key) {
- return get(key, String.class);
- }
-
- /**
- * Get the provider name of this context.
- *
- * @return the provider name, or null.
- */
- public String getProviderName() {
- return getText(KEY_PROVIDER);
- }
-
-
- /**
- * Checks if the current instance has no attributes set. This is often the cases, when used in default cases.
- *
- * @return true, if no attributes are set.
- */
- public boolean isEmpty() {
- return this.data.isEmpty();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- return Objects.hash(data);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (obj instanceof AbstractContext) {
- AbstractContext other = (AbstractContext) obj;
- return Objects.equals(data, other.data);
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see Object#toString()
- */
- @Override
- public String toString() {
- return getClass().getSimpleName() + " (\n" + data + ')';
- }
-}
diff --git a/src/main/java/javax/money/AbstractContextBuilder.java b/src/main/java/javax/money/AbstractContextBuilder.java
deleted file mode 100644
index e4a84bc99..000000000
--- a/src/main/java/javax/money/AbstractContextBuilder.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.TreeMap;
-
-/**
- * This interface defines the common generic parts of a query. Queries are used to pass complex parameters sets
- * to lookup monetary artifacts, e.g. {@link MonetaryAmountFactory},
- * {@link javax.money.MonetaryRounding},
- * {@link javax.money.CurrencyUnit}, {@link javax.money.convert.ExchangeRateProvider} and {@link javax.money.convert
- * .CurrencyConversion}.
- *
- * Instances of this class are not thread-safe and not serializable.
- */
-@SuppressWarnings({ "unchecked", "rawtypes" })
-public abstract class AbstractContextBuilder{
-
- /**
- * The data map containing all values.
- */
- final Map data = new HashMap<>();
-
- /**
- * Apply all attributes on the given context.
- *
- * @param context the context to be applied, not null.
- * @param overwriteDuplicates flag, if existing entries should be overwritten.
- * @return this Builder, for chaining
- */
- public B importContext(AbstractContext context, boolean overwriteDuplicates){
- for (Map.Entry en : context.data.entrySet()) {
- if (overwriteDuplicates) {
- this.data.put(en.getKey(), en.getValue());
- }else{
- this.data.putIfAbsent(en.getKey(), en.getValue());
- }
- }
- return (B) this;
- }
-
- /**
- * Apply all attributes on the given context, hereby existing entries are preserved.
- *
- * @param context the context to be applied, not null.
- * @return this Builder, for chaining
- * @see #importContext(AbstractContext, boolean)
- */
- public B importContext(AbstractContext context){
- Objects.requireNonNull(context);
- return importContext(context, false);
- }
-
- /**
- * Sets an Integer attribute.
- *
- * @param key the key, non null.
- * @param value the value
- * @return the Builder, for chaining.
- */
- public B set(String key, int value) {
- this.data.put(key, value);
- return (B) this;
- }
-
-
- /**
- * Sets an Boolean attribute.
- *
- * @param key the key, non null.
- * @param value the value
- * @return the Builder, for chaining.
- */
- public B set(String key, boolean value) {
- this.data.put(key, value);
- return (B) this;
- }
-
-
- /**
- * Sets an Long attribute.
- *
- * @param key the key, non null.
- * @param value the value
- * @return the Builder, for chaining.
- */
- public B set(String key, long value) {
- this.data.put(key, value);
- return (B) this;
- }
-
-
- /**
- * Sets an Float attribute.
- *
- * @param key the key, non null.
- * @param value the value
- * @return the Builder, for chaining.
- */
- public B set(String key, float value) {
- this.data.put(key, value);
- return (B) this;
- }
-
- /**
- * Sets an Double attribute.
- *
- * @param key the key, non null.
- * @param value the value
- * @return the Builder, for chaining.
- */
- public B set(String key, double value) {
- this.data.put(key, value);
- return (B) this;
- }
-
-
- /**
- * Sets an Character attribute.
- *
- * @param key the key, non null.
- * @param value the value
- * @return the Builder, for chaining.
- */
- public B set(String key, char value) {
- this.data.put(key, value);
- return (B) this;
- }
-
-
- /**
- * Sets an attribute, using {@code attribute.getClass()} as attribute
- * type and {@code attribute.getClass().getName()} as attribute
- * name.
- *
- * @param value the attribute value, not null.
- * @return this Builder, for chaining
- */
- public B set(Object value) {
- data.put(value.getClass().getName(), Objects.requireNonNull(value));
- return (B) this;
- }
-
- /**
- * Sets an attribute, using {@code attribute.getClass()} as attribute
- * type.
- *
- * @param value the attribute value, not null.
- * @param key the attribute's key, not {@code null}
- * @return this Builder, for chaining
- */
- public B set(String key, Object value) {
- data.put(key, Objects.requireNonNull(value));
- return (B) this;
- }
-
- /**
- * Sets an attribute, using {@code attribute.getClass()} as attribute
- * type.
- *
- * @param value the attribute value, not null.
- * @param key the attribute's key, not {@code null}
- * @return this Builder, for chaining
- */
- public B set(Class key, T value) {
- Object old = set(key.getName(), Objects.requireNonNull(value));
- if (old != null && old.getClass().isAssignableFrom(value.getClass())) {
- return (B) old;
- }
- return (B) this;
- }
-
- /**
- * Sets the provider.
- *
- * @param provider the provider, not null.
- * @return the Builder for chaining
- */
- public B setProviderName(String provider) {
- set(AbstractContext.KEY_PROVIDER, Objects.requireNonNull(provider));
- return (B) this;
- }
-
- /**
- * Removes an entry of a certain keys. This can be useful, when a context is initialized with another
- * existing context, but only subset of the entries should be visible. For example {@code removeAttributes
- * ("a", "b", "c")} removes all attributes named 'a','b' and 'c'.
- *
- * @param keys the keys
- * @return this Builder, for chaining
- */
- public B removeAttributes(String... keys) {
- for (String key : keys) {
- this.data.remove(key);
- }
- return (B) this;
- }
-
- /**
- * Creates a new {@link AbstractContext} with the data from this Builder
- * instance.
- *
- * @return a new {@link AbstractContext}. never {@code null}.
- */
- public abstract C build();
-
- @Override
- public String toString(){
- return getClass().getSimpleName() + " [attributes:\n" + new TreeMap<>(data).toString() + ']';
- }
-}
\ No newline at end of file
diff --git a/src/main/java/javax/money/AbstractQuery.java b/src/main/java/javax/money/AbstractQuery.java
deleted file mode 100644
index 03e4704de..000000000
--- a/src/main/java/javax/money/AbstractQuery.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Represents a general context of data targeting an item of type {@code Q}. Contexts are used to add arbitrary
- * data that cannot be be mapped in a standard way to the money API, e.g. use case or customer specific
- * extensions or specialities.
- * Superclasses of this class must be final, immutable, serializable and thread-safe.
- */
-public abstract class AbstractQuery extends AbstractContext {
-
- private static final long serialVersionUID = 5309190820845869327L;
-
- /**
- * Key for storing the target providers to be queried
- */
- protected static final String KEY_QUERY_PROVIDERS = "Query.providers";
-
- /**
- * Key name for the timestamp attribute.
- */
- protected static final String KEY_QUERY_TIMESTAMP = "Query.timestamp";
-
- /**
- * Key name for the target type attribute.
- */
- protected static final String KEY_QUERY_TARGET_TYPE = "Query.targetType";
-
-
- /**
- * Constructor, using a builder.
- *
- * @param builder the builder, not null.
- */
- protected AbstractQuery(@SuppressWarnings("rawtypes") AbstractQueryBuilder builder) {
- super(builder);
- }
-
- /**
- * Returns the providers and their ordering to be considered. This information typically must be interpreted by the
- * singleton SPI implementations, which are backing the singleton accessors.
- * If the list returned is empty, the default provider list,
- * determined by methods like {@code getDefaultProviderNames()} should be used.
- *
- * @return the ordered providers, never null.
- */
- public List getProviderNames() {
-
- @SuppressWarnings("unchecked") List result = get(KEY_QUERY_PROVIDERS, List.class);
- if (result == null) {
- return Collections.emptyList();
- }
- return result;
- }
-
- /**
- * Gets the target implementation type required. This can be used to explicitly acquire a specific implementation
- * type and use a query to configure the instance or factory to be returned.
- *
- * @return this Builder for chaining.
- */
- public Class> getTargetType() {
- return get(KEY_QUERY_TARGET_TYPE, Class.class);
- }
-
-}
diff --git a/src/main/java/javax/money/AbstractQueryBuilder.java b/src/main/java/javax/money/AbstractQueryBuilder.java
deleted file mode 100644
index f6985807b..000000000
--- a/src/main/java/javax/money/AbstractQueryBuilder.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * This abstract class defines the common generic parts of a query. Queries are used to pass complex parameters sets
- * to lookup monetary artifacts, e.g. {@link MonetaryAmountFactory},
- * {@link javax.money.MonetaryRounding},
- * {@link javax.money.CurrencyUnit}, {@link javax.money.convert.ExchangeRateProvider} and {@link javax.money.convert
- * .CurrencyConversion}.
- *
- * Instances of this class are not thread-safe and not serializable.
- */
-@SuppressWarnings("rawtypes")
-public abstract class AbstractQueryBuilder
- extends AbstractContextBuilder {
-
- /**
- * Initializes the query builder, as a default query builder.
- */
- public AbstractQueryBuilder() {
- }
-
-
- /**
- * Set the providers to be considered. If not set explicitly the default ISO currencies as
- * returned by {@link java.util.Currency} is used.
- *
- * @param providers the providers to use, not null.
- * @return the query builder for chaining.
- */
- public B setProviderNames(String... providers) {
- return setProviderNames(Arrays.asList(providers));
- }
-
- /**
- * Set the providers to be considered. If not set explicitly the default ISO currencies as
- * returned by {@link java.util.Currency} is used.
- *
- * @param providers the providers to use, not null.
- * @return the query builder for chaining.
- */
- public B setProviderNames(List providers) {
- Objects.requireNonNull(providers);
- return set(AbstractQuery.KEY_QUERY_PROVIDERS, providers);
- }
-
- /**
- * Set the providers to be considered. If not set explicitly the default providers and the corresponding
- * default ordering are used.
- *
- * @param providers the providers in order to use, not null.
- * @return the query builder for chaining.
- */
- public B set(List providers) {
- return set(AbstractQuery.KEY_QUERY_PROVIDERS, providers);
- }
-
- /**
- * Simple override, that sets the provider as provider to use.
- *
- * @param provider the provider, not null.
- * @return the query builder for chaining.
- */
- @Override
- public B setProviderName(String provider) {
- return setProviderNames(provider);
- }
-
-
- /**
- * Sets the target implementation type required. This can be used to explicitly acquire a specific
- * implementation
- * type and use a query to configure the instance or factory to be returned.
- *
- * @param type the target implementation type, not null.
- * @return this query builder for chaining.
- */
- @SuppressWarnings("unchecked")
- public B setTargetType(Class> type) {
- Objects.requireNonNull(type);
- set(AbstractQuery.KEY_QUERY_TARGET_TYPE, type);
- return (B) this;
- }
-
- /**
- * Creates a new {@link AbstractQuery} with the data from this Builder
- * instance.
- *
- * @return a new {@link AbstractQuery}. never {@code null}.
- */
- @Override
- public abstract C build();
-
-}
\ No newline at end of file
diff --git a/src/main/java/javax/money/CurrencyContext.java b/src/main/java/javax/money/CurrencyContext.java
deleted file mode 100644
index abf2d8730..000000000
--- a/src/main/java/javax/money/CurrencyContext.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.io.Serializable;
-
-/**
- * This class models the attributable context of {@link javax.money.CurrencyUnit} instances. It
- * provides information about
- *
- * - the provider that provided the instance (required)
- *
- the target timestamp / temporal unit
- *
- any other attributes, identified by the attribute type, e.g. regions, tenants etc.
- *
- * Instances of this class must be created using the {@link javax.money.CurrencyContextBuilder}. Typically the
- * contexts are created and assigned by the classes that implement the {@link javax.money.spi.CurrencyProviderSpi}.
- * The according implementation classes should document, which attributes are available.
- *
- * This class is immutable, serializable and thread-safe.
- *
- * @author Anatole Tresch
- */
-public final class CurrencyContext extends AbstractContext implements Serializable{
-
- private static final long serialVersionUID = 8450310852172607016L;
-
-
- /**
- * Constructor, used from the {@link javax.money.CurrencyContextBuilder}.
- *
- * @param builder the corresponding builder, not null.
- */
- CurrencyContext(CurrencyContextBuilder builder){
- super(builder);
- }
-
-
- /**
- * Allows to convert a instance into the corresponding {@link javax.money.CurrencyContextBuilder}, which allows
- * to change the values and of another {@link javax.money.CurrencyContext} instance.
- *
- * @return a new Builder instance, preinitialized with the values from this instance.
- */
- public CurrencyContextBuilder toBuilder(){
- return CurrencyContextBuilder.of(this);
- }
-
-
-}
diff --git a/src/main/java/javax/money/CurrencyContextBuilder.java b/src/main/java/javax/money/CurrencyContextBuilder.java
deleted file mode 100644
index f3c0bb7a6..000000000
--- a/src/main/java/javax/money/CurrencyContextBuilder.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.util.Objects;
-
-/**
- * Builder class for creating new instances of {@link CurrencyContext} adding detailed information
- * about a {@link CurrencyUnit} instance. Typically the
- * contexts are created and assigned by the classes that implement the {@link javax.money.spi.CurrencyProviderSpi}.
- * The according implementation classes should document, which attributes are available.
- *
- * Note this class is NOT thread-safe.
- *
- * @see javax.money.CurrencyUnit#getContext()
- */
-public final class CurrencyContextBuilder extends AbstractContextBuilder {
-
- /**
- * Creates a new builder.
- *
- * @param provider the provider name, creating the corresponding {@link CurrencyUnit} containing
- * the final {@link CurrencyContext} created by this builder, not null.
- */
- private CurrencyContextBuilder(String provider) {
- Objects.requireNonNull(provider);
- setProviderName(provider);
- }
-
- /**
- * Creates a new builder.
- *
- * @param context the {@link javax.money.CurrencyContext} to be used for initializing this builder.
- */
- private CurrencyContextBuilder(CurrencyContext context) {
- Objects.requireNonNull(context);
- importContext(context);
- }
-
- /**
- * Creates a new instance of {@link javax.money.CurrencyContext}.
- *
- * @return a new {@link javax.money.CurrencyContext} instance.
- */
- @Override
- public CurrencyContext build() {
- return new CurrencyContext(this);
- }
-
- /**
- * Creates a new builder.
- *
- * @param provider the provider name, creating the corresponding {@link CurrencyUnit} containing
- * the final {@link CurrencyContext} created by this builder, not null.
- * @return a new {@link javax.money.CurrencyContextBuilder} instance, never null.
- */
- public static CurrencyContextBuilder of(String provider) {
- return new CurrencyContextBuilder(provider);
- }
-
- /**
- * Creates a new builder.
- *
- * @param context the {@link javax.money.CurrencyContext} to be used for initializing this builder.
- * @return a new {@link javax.money.CurrencyContextBuilder} instance, never null.
- */
- public static CurrencyContextBuilder of(CurrencyContext context) {
- return new CurrencyContextBuilder(context);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/javax/money/CurrencyQuery.java b/src/main/java/javax/money/CurrencyQuery.java
deleted file mode 100644
index 86f4d82fb..000000000
--- a/src/main/java/javax/money/CurrencyQuery.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Locale;
-
-/**
- * This class models a query for accessing instances of {@link CurrencyUnit}. It
- * provides information such as
- *
- * - the providers that may provide {@link CurrencyUnit} instances
- *
- any other attributes, identified by the attribute type, e.g. regions, tenants,
- * a target timestamp / temporal unit, when the {@link CurrencyUnit} instances should be valid, etc.
- *
- * The effective attributes supported are only determined by the implementations of {@link javax.money.spi
- * .CurrencyProviderSpi}.
- *
- * This class is immutable, serializable and thread-safe.
- *
- * @author Anatole Tresch
- */
-@SuppressWarnings("unchecked")
-public final class CurrencyQuery extends AbstractQuery implements Serializable {
-
- private static final long serialVersionUID = -5117949582074719190L;
-
- /**
- * Key for storing a countries to be queried.
- */
- static final String KEY_QUERY_COUNTRIES = "Query.countries";
-
- /**
- * Key for storing a target literal currency codes to be queried.
- */
- static final String KEY_QUERY_CURRENCY_CODES = "Query.currencyCodes";
-
- /**
- * Key for storing a target numeric currency codes to be queried.
- */
- static final String KEY_QUERY_NUMERIC_CODES = "Query.numericCodes";
-
- /**
- * Constructor, used from the Builder.
- *
- * @param builder the corresponding {@link javax.money.CurrencyQueryBuilder}, not null.
- */
- CurrencyQuery(CurrencyQueryBuilder builder) {
- super(builder);
- }
-
- /**
- * Returns the target locales.
- *
- * @return the target locales, never null.
- */
- public Collection getCountries() {
- Collection result = get(KEY_QUERY_COUNTRIES, Collection.class);
- if (result == null) {
- return Collections.emptySet();
- }
- return result;
- }
-
- /**
- * Gets the currency codes, or the regular expression to select codes.
- *
- * @return the target currency codes or the regular expression, never null.
- */
- public Collection getCurrencyCodes() {
- Collection result = get(KEY_QUERY_CURRENCY_CODES, Collection.class);
- if (result == null) {
- return Collections.emptySet();
- }
- return result;
- }
-
- /**
- * Gets the numeric codes. Setting it to -1 search for currencies that have no numeric code.
- *
- * @return the target numeric codes, never null.
- */
- public Collection getNumericCodes() {
- Collection result = get(KEY_QUERY_NUMERIC_CODES, Collection.class);
- if (result == null) {
- return Collections.emptySet();
- }
- return result;
- }
-
- /**
- * Creates a new builder instances, initialized with the data from this one.
- *
- * @return a new {@link MonetaryAmountFactoryQueryBuilder} instance, never null.
- */
- public CurrencyQueryBuilder toBuilder() {
- return CurrencyQueryBuilder.of(this);
- }
-
-}
diff --git a/src/main/java/javax/money/CurrencyQueryBuilder.java b/src/main/java/javax/money/CurrencyQueryBuilder.java
deleted file mode 100644
index f0366dd35..000000000
--- a/src/main/java/javax/money/CurrencyQueryBuilder.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import java.util.Arrays;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-
-/**
- * Builder for queries for accessing {@link javax.money.CurrencyUnit} instances. If not properties are set the
- * query should
- * returns
- * the default currencies. Similarly if no provider is set explicitly the default ISO currencies as
- * returned by {@link java.util.Currency} should be returned.
- *
- * Note this class is NOT thread-safe.
- */
-public final class CurrencyQueryBuilder extends AbstractQueryBuilder {
-
- /**
- * Default constructor.
- */
- private CurrencyQueryBuilder() {
- }
-
- /**
- * Creates a new instance of {@link javax.money.CurrencyQueryBuilder}.
- *
- * @param currencyQuery {@link javax.money.CurrencyQuery} used for initializing this builder.
- */
- private CurrencyQueryBuilder(CurrencyQuery currencyQuery) {
- Objects.requireNonNull(currencyQuery);
- importContext(currencyQuery);
- }
-
- /**
- * Sets the country for which currencies should be requested.
- *
- * @param countries The ISO countries.
- * @return the query for chaining.
- */
- public CurrencyQueryBuilder setCountries(Locale... countries) {
- return set(CurrencyQuery.KEY_QUERY_COUNTRIES, Arrays.asList(countries));
- }
-
- /**
- * Sets the currency code, or the regular expression to select codes.
- *
- * @param codes the currency codes or code expressions, not null.
- * @return the query for chaining.
- */
- public CurrencyQueryBuilder setCurrencyCodes(String... codes) {
- return set(CurrencyQuery.KEY_QUERY_CURRENCY_CODES, Arrays.asList(codes));
- }
-
- /**
- * Set the numeric code. Setting it to -1 search for currencies that have no numeric code.
- *
- * @param codes the numeric codes.
- * @return the query for chaining.
- */
- public CurrencyQueryBuilder setNumericCodes(int... codes) {
- return set(CurrencyQuery.KEY_QUERY_NUMERIC_CODES,
- Arrays.stream(codes).boxed().collect(Collectors.toList()));
- }
-
- /**
- * Creates a new instance of {@link javax.money.CurrencyQuery}.
- *
- * @return a new {@link javax.money.CurrencyQuery} instance, never null.
- */
- public CurrencyQuery build() {
- return new CurrencyQuery(this);
- }
-
- /**
- * Creates a new instance of {@link javax.money.CurrencyQueryBuilder}.
- *
- * @return a new {@link javax.money.CurrencyQueryBuilder} instance, never null.
- */
- public static CurrencyQueryBuilder of() {
- return new CurrencyQueryBuilder();
- }
-
- /**
- * Creates a new instance of {@link javax.money.CurrencyQueryBuilder}.
- *
- * @param currencyQuery {@link javax.money.CurrencyQuery} used for initializing this builder.
- * @return a new {@link javax.money.CurrencyQueryBuilder} instance, never null.
- */
- public static CurrencyQueryBuilder of(CurrencyQuery currencyQuery) {
- return new CurrencyQueryBuilder(currencyQuery);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/javax/money/CurrencySupplier.java b/src/main/java/javax/money/CurrencySupplier.java
deleted file mode 100644
index 886c4250b..000000000
--- a/src/main/java/javax/money/CurrencySupplier.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-
-/**
- * Represents a supplier of {@link CurrencyUnit}-valued results. This is the
- * {@link CurrencyUnit}-producing specialization of {@code Supplier} (as in Java 8).
- *
- *
- * There is no requirement that a distinct result be returned each time the
- * supplier is invoked.
- *
- *
- * This is a functional interface whose
- * functional method is {@link #getCurrency()}.
- * This class does not extend {@link java.util.function.Supplier} since {@link javax.money.MonetaryAmount} implements
- * both supplier interfaces, {@link javax.money.NumberSupplier} and {@link javax.money.CurrencySupplier},
- * which will lead
- * to method name conflicts.
- *
- *
- * @author Werner Keil
- * @version 0.5
- * @since 0.8
- * @see java.util.function.Supplier
- */
-@FunctionalInterface
-public interface CurrencySupplier {
-
- /**
- * Gets the corresponding {@link javax.money.CurrencyUnit}.
- *
- * @return the corresponding {@link javax.money.CurrencyUnit}, not null.
- */
- CurrencyUnit getCurrency();
-}
\ No newline at end of file
diff --git a/src/main/java/javax/money/CurrencyUnit.java b/src/main/java/javax/money/CurrencyUnit.java
deleted file mode 100644
index bbda28093..000000000
--- a/src/main/java/javax/money/CurrencyUnit.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-/**
- * A unit of currency.
- *
- * This interface represents a unit of currency such as the British Pound, Euro,
- * US Dollar, Bitcoin or other. It provides interoperability between different
- * implementations.
- *
- * Currencies can be distinguished by separate {@link #getCurrencyCode()} codes,
- * similar to {@link java.util.Currency}.
- *
Implementation specification
- * Implementation of this class
- *
- * - are required to implement {@code equals/hashCode} considering the
- * concrete implementation type and currency code.
- * - are required to be thread-safe
- * - are required to be immutable
- * - are required to be comparable
- * - should be serializable (on platforms providing serialization).
- *
- *
- * @author Werner Keil
- * @author Stephen Colebourne
- * @author Anatole Tresch
- *
- * @version 1.0
- *
- * @see Wikipedia: Currency
- */
-public interface CurrencyUnit extends Comparable{
-
- /**
- * Gets the unique currency code, the effective code depends on the
- * currency.
- *
- * Since each currency is identified by this code, the currency code is
- * required to be defined for every {@link CurrencyUnit} and not
- * {@code null} or empty.
- *
- * For ISO codes the 3-letter ISO code should be returned. For non ISO
- * currencies no constraints are defined.
- *
- * @return the currency code, never {@code null}. For ISO-4217 this this
- * will be the three letter ISO-4217 code. However, alternate
- * currencies can have different codes. Also there is no constraint
- * about the formatting of alternate codes, despite the fact that
- * the currency codes must be unique.
- */
- String getCurrencyCode();
-
- /**
- * Gets a numeric currency code. within the ISO-4217 name space, this equals
- * to the ISO numeric code. In other currency name spaces this number may be
- * different, or even undefined (-1).
- *
- * The numeric code is an optional alternative to the standard currency
- * code. If defined, the numeric code is required to be unique.
- *
- * This method matches the API of {@link java.util.Currency}.
- *
- * @return the numeric currency code
- */
- int getNumericCode();
-
- /**
- * Gets the number of fractional digits typically used by this currency.
- *
- * Different currencies have different numbers of fractional digits by
- * default. For example, 'GBP' has 2 fractional digits, but 'JPY' has zero.
- * virtual currencies or those with no applicable fractional are indicated
- * by -1.
- *
- * This method matches the API of {@link java.util.Currency}.
- *
- * @return the fractional digits, from 0 to 9 (normally 0, 2 or 3), or 0 for
- * pseudo-currencies.
- *
- */
- int getDefaultFractionDigits();
-
- /**
- * Returns the {@link javax.money.CurrencyContext} of a currency. This context contains additional information
- * about the type and capabilities of a CurrencyUnit, e.g. its provider and more.
- * @return the currency's context, never null.
- */
- CurrencyContext getContext();
-}
diff --git a/src/main/java/javax/money/DefaultMonetaryCurrenciesSingletonSpi.java b/src/main/java/javax/money/DefaultMonetaryCurrenciesSingletonSpi.java
deleted file mode 100644
index 4f40bbeb9..000000000
--- a/src/main/java/javax/money/DefaultMonetaryCurrenciesSingletonSpi.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import javax.money.spi.Bootstrap;
-import javax.money.spi.CurrencyProviderSpi;
-import javax.money.spi.MonetaryCurrenciesSingletonSpi;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Factory singleton for {@link CurrencyUnit} instances as provided by the
- * different registered {@link javax.money.spi.CurrencyProviderSpi} instances.
- *
- * This class is thread safe.
- *
- * @author Anatole Tresch
- * @version 0.8
- */
-final class DefaultMonetaryCurrenciesSingletonSpi implements MonetaryCurrenciesSingletonSpi {
-
- @Override
- public Set getCurrencies(CurrencyQuery query) {
- Set result = new HashSet<>();
- for (CurrencyProviderSpi spi : Bootstrap.getServices(CurrencyProviderSpi.class)) {
- try {
- result.addAll(spi.getCurrencies(query));
- } catch (Exception e) {
- Logger.getLogger(DefaultMonetaryCurrenciesSingletonSpi.class.getName())
- .log(Level.SEVERE, "Error loading currency provider names for " + spi.getClass().getName(),
- e);
- }
- }
- return result;
- }
-
- /**
- * This default implementation simply returns all providers defined in arbitrary order.
- *
- * @return the default provider chain, never null.
- */
- @Override
- public List getDefaultProviderChain() {
- List list = new ArrayList<>(getProviderNames());
- Collections.sort(list);
- return list;
- }
-
- /**
- * Get the names of the currently loaded providers.
- *
- * @return the names of the currently loaded providers, never null.
- */
- @Override
- public Set getProviderNames() {
- Set result = new HashSet<>();
- for (CurrencyProviderSpi spi : Bootstrap.getServices(CurrencyProviderSpi.class)) {
- try {
- result.add(spi.getProviderName());
- } catch (Exception e) {
- Logger.getLogger(DefaultMonetaryCurrenciesSingletonSpi.class.getName())
- .log(Level.SEVERE, "Error loading currency provider names for " + spi.getClass().getName(),
- e);
- }
- }
- return result;
- }
-
-}
diff --git a/src/main/java/javax/money/DefaultMonetaryRoundingsSingletonSpi.java b/src/main/java/javax/money/DefaultMonetaryRoundingsSingletonSpi.java
deleted file mode 100644
index 5ef5f4182..000000000
--- a/src/main/java/javax/money/DefaultMonetaryRoundingsSingletonSpi.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import javax.money.spi.Bootstrap;
-import javax.money.spi.MonetaryRoundingsSingletonSpi;
-import javax.money.spi.RoundingProviderSpi;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class models the accessor for rounding instances, modeled as
- * {@link javax.money.MonetaryOperator}.
- *
- * This class is thread-safe.
- *
- * @author Anatole Tresch
- * @author Werner Keil
- */
-public final class DefaultMonetaryRoundingsSingletonSpi implements MonetaryRoundingsSingletonSpi {
-
- /**
- * An adaptive rounding instance that transparently looks up the correct
- * rounding.
- */
- private static final MonetaryRounding DEFAULT_ROUNDING = new DefaultCurrencyRounding();
-
- /**
- * Creates an rounding instance using {@link java.math.RoundingMode#UP} rounding.
- *
- * @return the corresponding {@link MonetaryOperator} implementing the
- * rounding.
- * @throws MonetaryException if no such rounding could be evaluated.
- */
- public RoundingQueryBuilder createRoundingQueryBuilder() {
- throw new IllegalStateException("No MonetaryRoundingsSingletonSpi registered.");
- }
-
- /**
- * Get the default rounding, which delegates rounding dynamically depending on the current currency.
- *
- * @return the default rounding, never null.
- */
- @Override
- public MonetaryRounding getDefaultRounding() {
- return DEFAULT_ROUNDING;
- }
-
-
- /**
- * Query all roundings matching the given {@link RoundingQuery}.
- *
- * @param query the rounding query, not null.
- * @return the collection found, not null.
- */
- @Override
- public Collection getRoundings(RoundingQuery query) {
- List result = new ArrayList<>();
- Collection providerNames = query.getProviderNames();
- if (providerNames == null || providerNames.isEmpty()) {
- providerNames = getDefaultProviderChain();
- }
- for (String providerName : providerNames) {
- Bootstrap.getServices(RoundingProviderSpi.class).stream()
- .filter(prov -> providerName.equals(prov.getProviderName())).forEach(prov -> {
- try {
- MonetaryRounding r = prov.getRounding(query);
- if (r != null) {
- result.add(r);
- }
- } catch (Exception e) {
- Logger.getLogger(DefaultMonetaryRoundingsSingletonSpi.class.getName())
- .log(Level.SEVERE, "Error loading RoundingProviderSpi from provider: " + prov, e);
- }
- });
- }
- return result;
- }
-
- /**
- * Get the names of all current registered providers.
- *
- * @return the names of all current registered providers, never null.
- */
- @Override
- public Set getProviderNames() {
- Set result = new HashSet<>();
- for (RoundingProviderSpi prov : Bootstrap.getServices(RoundingProviderSpi.class)) {
- try {
- result.add(prov.getProviderName());
- } catch (Exception e) {
- Logger.getLogger(Monetary.class.getName())
- .log(Level.SEVERE, "Error loading RoundingProviderSpi from provider: " + prov, e);
- }
- }
- return result;
- }
-
- /**
- * Get the default providers list to be used.
- *
- * @return the default provider list and ordering, not null.
- */
- @Override
- public List getDefaultProviderChain() {
- List result = new ArrayList<>(Monetary.getRoundingProviderNames());
- Collections.sort(result);
- return result;
- }
-
- /**
- * Allows to access the identifiers of the current defined roundings.
- *
- * @param providers the providers and ordering to be used. By default providers and ordering as defined in
- * #getDefaultProviders is used, not null.
- * @return the set of custom rounding ids, never {@code null}.
- */
- @Override
- public Set getRoundingNames(String... providers) {
- Set result = new HashSet<>();
- String[] providerNames = providers;
- if (providerNames.length == 0) {
- providerNames = Monetary.getDefaultRoundingProviderChain().toArray(new String[Monetary.getDefaultRoundingProviderChain().size()]);
- }
- for (String providerName : providerNames) {
- for (RoundingProviderSpi prov : Bootstrap.getServices(RoundingProviderSpi.class)) {
- try {
- if (prov.getProviderName().equals(providerName) || prov.getProviderName().matches(providerName)) {
- result.addAll(prov.getRoundingNames());
- }
- } catch (Exception e) {
- Logger.getLogger(DefaultMonetaryRoundingsSingletonSpi.class.getName())
- .log(Level.SEVERE, "Error loading RoundingProviderSpi from provider: " + prov, e);
- }
- }
- }
- return result;
- }
-
- /**
- * Default Rounding that rounds a {@link MonetaryAmount} based on the
- * amount's {@link CurrencyUnit}.
- *
- * @author Anatole Tresch
- */
- private static final class DefaultCurrencyRounding implements MonetaryRounding, Serializable {
-
- private static final long serialVersionUID = 8641545296538357839L;
-
- private static final RoundingContext ROUNDING_CONTEXT = RoundingContextBuilder.of("default", "default").build();
-
- @Override
- public MonetaryAmount apply(MonetaryAmount amount) {
- MonetaryRounding r = Monetary.getRounding(amount.getCurrency());
- return r.apply(amount);
- }
-
- @Override
- public RoundingContext getRoundingContext() {
- return ROUNDING_CONTEXT;
- }
- }
-
-}
diff --git a/src/main/java/javax/money/Monetary.java b/src/main/java/javax/money/Monetary.java
deleted file mode 100644
index c80f14054..000000000
--- a/src/main/java/javax/money/Monetary.java
+++ /dev/null
@@ -1,499 +0,0 @@
-/*
- * Copyright 2012-2016 Credit Suisse
- * Copyright 2018-2020 Werner Keil, Otavio Santana, Trivadis AG
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package javax.money;
-
-import javax.money.spi.*;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Optional;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Factory singleton for {@link CurrencyUnit}, {@link javax.money.MonetaryAmount} and
- * {@link javax.money.MonetaryRounding} instances as provided by the
- * different registered SPI instances.
- *
- * This class is thread safe.
- *
- *
- * @author Anatole Tresch
- */
-public final class Monetary {
- /**
- * The used {@link javax.money.spi.MonetaryCurrenciesSingletonSpi} instance.
- *
- * @return the used {@link javax.money.spi.MonetaryCurrenciesSingletonSpi} instance,
- * never {@code null}
- */
- private static MonetaryCurrenciesSingletonSpi monetaryCurrenciesSingletonSpi() {
- try {
- return Optional.ofNullable(Bootstrap
- .getService(MonetaryCurrenciesSingletonSpi.class)).orElseGet(
- DefaultMonetaryCurrenciesSingletonSpi::new);
- } catch (Exception e) {
- Logger.getLogger(Monetary.class.getName())
- .log(Level.WARNING, "Failed to load MonetaryCurrenciesSingletonSpi, using default.", e);
- return new DefaultMonetaryCurrenciesSingletonSpi();
- }
- }
-
- /**
- * The used {@link javax.money.spi.MonetaryAmountsSingletonSpi} instance.
- */
- private static MonetaryAmountsSingletonSpi monetaryAmountsSingletonSpi() {
- try {
- return Bootstrap.getService(MonetaryAmountsSingletonSpi.class);
- } catch (Exception e) {
- Logger.getLogger(Monetary.class.getName())
- .log(Level.SEVERE, "Failed to load MonetaryAmountsSingletonSpi.", e);
- return null;
- }
- }
-
- /**
- * The used {@link javax.money.spi.MonetaryAmountsSingletonSpi} instance.
- */
- private static MonetaryAmountsSingletonQuerySpi monetaryAmountsSingletonQuerySpi() {
- try {
- return Bootstrap.getService(MonetaryAmountsSingletonQuerySpi.class);
- } catch (Exception e) {
- Logger.getLogger(Monetary.class.getName()).log(Level.SEVERE, "Failed to load " +
- "MonetaryAmountsSingletonQuerySpi, " +
- "query functionality will not be " +
- "available.", e);
- return null;
- }
- }
-
- /**
- * The used {@link javax.money.spi.MonetaryCurrenciesSingletonSpi} instance.
- *
- * @return the used {@link javax.money.spi.MonetaryCurrenciesSingletonSpi} instance,
- * never {@code null}
- */
- private static MonetaryRoundingsSingletonSpi monetaryRoundingsSingletonSpi() {
- try {
- return Optional.ofNullable(Bootstrap
- .getService(MonetaryRoundingsSingletonSpi.class))
- .orElseGet(DefaultMonetaryRoundingsSingletonSpi::new);
- } catch (Exception e) {
- Logger.getLogger(Monetary.class.getName())
- .log(Level.SEVERE, "Failed to load MonetaryCurrenciesSingletonSpi, using default.", e);
- return new DefaultMonetaryRoundingsSingletonSpi();
- }
- }
-
- /**
- * Private singletons constructor.
- */
- private Monetary() {
- }
-
- /**
- * Allows to access the names of the current registered providers.
- *
- * @return the set of provider names, never {@code null}.
- */
- public static Set getRoundingProviderNames() {
- return monetaryRoundingsSingletonSpi()
- .getProviderNames();
- }
-
- /**
- * Allows to access the default providers chain used if no provider chain was passed explicitly..
- *
- * @return the chained list of provider names, never {@code null}.
- */
- public static List getDefaultRoundingProviderChain() {
- return monetaryRoundingsSingletonSpi()
- .getDefaultProviderChain();
- }
-
- /**
- * Creates a rounding that can be added as {@link MonetaryOperator} to
- * chained calculations. The instance will lookup the concrete
- * {@link MonetaryOperator} instance from the {@link Monetary}
- * based on the input {@link MonetaryAmount}'s {@link CurrencyUnit}.
- *
- * @return the (shared) default rounding instance.
- */
- public static MonetaryRounding getDefaultRounding() {
- return monetaryRoundingsSingletonSpi()
- .getDefaultRounding();
- }
-
- /**
- * Creates an {@link MonetaryOperator} for rounding {@link MonetaryAmount}
- * instances given a currency.
- *
- * @param currencyUnit The currency, which determines the required scale. As
- * {@link java.math.RoundingMode}, by default, {@link java.math.RoundingMode#HALF_UP}
- * is used.
- * @param providers the providers and ordering to be used. By default providers and ordering as defined in
- * #getDefaultProviders is used.
- * @return a new instance {@link MonetaryOperator} implementing the
- * rounding, never {@code null}.
- */
- public static MonetaryRounding getRounding(CurrencyUnit currencyUnit, String... providers) {
- return monetaryRoundingsSingletonSpi()
- .getRounding(currencyUnit, providers);
- }
-
- /**
- * Access an {@link MonetaryOperator} for custom rounding
- * {@link MonetaryAmount} instances.
- *
- * @param roundingName The rounding identifier.
- * @param providers the providers and ordering to be used. By default providers and ordering as defined in
- * #getDefaultProviders is used.
- * @return the corresponding {@link MonetaryOperator} implementing the
- * rounding, never {@code null}.
- * @throws IllegalArgumentException if no such rounding is registered using a
- * {@link javax.money.spi.RoundingProviderSpi} instance.
- */
- public static MonetaryRounding getRounding(String roundingName, String... providers) {
- return monetaryRoundingsSingletonSpi()
- .getRounding(roundingName, providers);
- }
-
- /**
- * Access a {@link MonetaryRounding} using a possibly complex query.
- *
- * @param roundingQuery The {@link javax.money.RoundingQuery} that may contains arbitrary parameters to be
- * evaluated.
- * @return the corresponding {@link javax.money.MonetaryRounding}, never {@code null}.
- * @throws IllegalArgumentException if no such rounding is registered using a
- * {@link javax.money.spi.RoundingProviderSpi} instance.
- */
- public static MonetaryRounding getRounding(RoundingQuery roundingQuery) {
- return monetaryRoundingsSingletonSpi()
- .getRounding(roundingQuery);
- }
-
- /**
- * Checks if a {@link MonetaryRounding} is available given a roundingId.
- *
- * @param roundingName The rounding identifier.
- * @param providers the providers and ordering to be used. By default providers and ordering as defined in
- * #getDefaultProviders is used.
- * @return true, if a corresponding {@link javax.money.MonetaryRounding} is available.
- * @throws IllegalArgumentException if no such rounding is registered using a
- * {@link javax.money.spi.RoundingProviderSpi} instance.
- */
- public static boolean isRoundingAvailable(String roundingName, String... providers) {
- return monetaryRoundingsSingletonSpi()
- .isRoundingAvailable(roundingName, providers);
- }
-
- /**
- * Checks if a {@link MonetaryRounding} is available given a roundingId.
- *
- * @param currencyUnit The currency, which determines the required scale. As {@link java.math.RoundingMode},
- * by default, {@link java.math.RoundingMode#HALF_UP} is used.
- * @param providers the providers and ordering to be used. By default providers and ordering as defined in
- * #getDefaultProviders is used.
- * @return true, if a corresponding {@link javax.money.MonetaryRounding} is available.
- * @throws IllegalArgumentException if no such rounding is registered using a
- * {@link javax.money.spi.RoundingProviderSpi} instance.
- */
- public static boolean isRoundingAvailable(CurrencyUnit currencyUnit, String... providers) {
- return monetaryRoundingsSingletonSpi()
- .isRoundingAvailable(currencyUnit, providers);
- }
-
- /**
- * Checks if a {@link MonetaryRounding} matching the query is available.
- *
- * @param roundingQuery The {@link javax.money.RoundingQuery} that may contains arbitrary parameters to be
- * evaluated.
- * @return true, if a corresponding {@link javax.money.MonetaryRounding} is available.
- * @throws IllegalArgumentException if no such rounding is registered using a
- * {@link javax.money.spi.RoundingProviderSpi} instance.
- */
- public static boolean isRoundingAvailable(RoundingQuery roundingQuery) {
- return monetaryRoundingsSingletonSpi()
- .isRoundingAvailable(roundingQuery);
- }
-
-
- /**
- * Access multiple {@link MonetaryRounding} instances using a possibly complex query
- *
- * @param roundingQuery The {@link javax.money.RoundingQuery} that may contains arbitrary parameters to be
- * evaluated.
- * @return all {@link javax.money.MonetaryRounding} instances matching the query, never {@code null}.
- */
- public static Collection getRoundings(RoundingQuery roundingQuery) {
- return monetaryRoundingsSingletonSpi()
- .getRoundings(roundingQuery);
- }
-
-
- /**
- * Allows to access the names of the current defined roundings.
- *
- * @param providers the providers and ordering to be used. By default providers and ordering as defined in
- * #getDefaultProviders is used.
- * @return the set of custom rounding ids, never {@code null}.
- */
- public static Set