resources = IMFRemoteSearch.INSTANCE.getResources(YearMonth.of(2015, Month.MAY), null);
37 | assertNotNull(resources.get(IMFHistoricalType.Currency_SDR));
38 | assertNotNull(resources.get(IMFHistoricalType.SDR_Currency));
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/moneta-convert/moneta-convert-imf/src/test/resources/META-INF/services/javax.money.spi.RoundingProviderSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.convert.imf.TestRoundingProvider
16 |
--------------------------------------------------------------------------------
/moneta-convert/moneta-convert-imf/update_imf.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | printf "\n Downloading the IMF resource. \n"
3 | # wget https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y
4 | # mv rms_five.aspx?tsvflag=Y src/main/resources/org/javamoney/moneta/convert/imf/defaults/rms_five.tsv
5 | curl --fail "https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y" \
6 | --output src/main/resources/org/javamoney/moneta/convert/imf/defaults/rms_five.tsv
7 | printf "\n Done. \n"
--------------------------------------------------------------------------------
/moneta-convert/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.javamoney
6 | moneta-parent
7 | 1.5-SNAPSHOT
8 |
9 | org.javamoney.moneta
10 | moneta-convert-parent
11 | pom
12 | Moneta Currency Conversion (Parent)
13 | This is the parent POM for JSR 354 exchange rate providers.
14 |
15 |
16 | moneta-convert-base
17 | moneta-convert-ecb
18 | moneta-convert-imf
19 |
20 |
21 |
22 |
23 |
24 | biz.aQute.bnd
25 | bnd-maven-plugin
26 |
27 |
28 |
29 | bnd-process
30 |
31 |
32 |
33 |
34 |
35 | org.apache.maven.plugins
36 | maven-jar-plugin
37 |
38 |
39 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/moneta-core/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | test-output/
3 | bin/
4 | /doc
5 | *.iml
6 | *.log
7 | .classpath
8 | -project
9 | /.resourceCache
10 | /.project
11 | /.idea
12 | .settings/
13 |
--------------------------------------------------------------------------------
/moneta-core/bnd.bnd:
--------------------------------------------------------------------------------
1 | # Javac settings
2 | javac.source: 1.8
3 | javac.target: 1.8
4 |
5 | # Override automatic runtime requirement when building with JDK9+
6 | Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version>=8.0))"
7 |
8 | -buildpath: \
9 | osgi.annotation; version=8.0.0,\
10 | osgi.core; version=8.0
11 |
12 | # JPMS
13 | Automatic-Module-Name: org.javamoney.moneta
14 |
15 | # Bundle description
16 | Bundle-Version: ${project.version}.${tstamp}
17 | Bundle-Name: JavaMoney Moneta Reference Implementation
18 | Bundle-Activator: org.javamoney.moneta.internal.OSGIActivator
19 | Bundle-SymbolicName: org.javamoney.moneta
20 | Bundle-Description: JavaMoney - Moneta Reference Implementation
21 | Bundle-Category: Implementation
22 | Bundle-Copyright: (C) 2012, 2018 Anatole Tresch, Werner Keil and others
23 | Bundle-License: Apache License, Version 2.0
24 | Bundle-Vendor: JavaMoney Project
25 | Bundle-DocURL: http://www.javamoney.org
26 |
27 | # Bundle capabilities and requirements
28 | Import-Package: *
29 | Export-Package: ${packages;NAMED;!*internal*}
30 | Export-Service: \
31 | javax.money.spi.CurrencyProviderSpi,\
32 | javax.money.spi.MonetaryAmountFactoryProviderSpi,\
33 | javax.money.spi.MonetaryAmountFormatProviderSpi,\
34 | javax.money.spi.MonetaryAmountsSingletonQuerySpi,\
35 | javax.money.spi.MonetaryAmountsSingletonSpi,\
36 | javax.money.spi.MonetaryConversionsSingletonSpi,\
37 | javax.money.spi.MonetaryCurrenciesSingletonSpi,\
38 | javax.money.spi.RoundingProviderSpi,\
39 | javax.money.spi.ServiceProvider,\
40 | org.javamoney.moneta.spi.loader.LoaderService
41 |
--------------------------------------------------------------------------------
/moneta-core/src/etc/header.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, 2020, Werner Keil, Anatole Tresch and others by the @author tag.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | use this file except in compliance with the License. You may obtain a copy of
5 | the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | License for the specific language governing permissions and limitations under
13 | the License.
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/highlighter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/highlighter.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/README:
--------------------------------------------------------------------------------
1 | Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook
2 | icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency
3 | from the Jimmac icons to get round MS IE and FOP PNG incompatibilies.
4 |
5 | Stuart Rackham
6 |
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/1.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/10.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/11.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/12.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/13.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/14.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/15.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/2.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/3.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/4.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/5.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/6.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/7.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/8.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/callouts/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/callouts/9.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/caution.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/example.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/home.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/important.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/important.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/next.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/note.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/note.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/prev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/prev.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/tip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/tip.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/up.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/icons/warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/icons/warning.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/smallnew.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/smallnew.png
--------------------------------------------------------------------------------
/moneta-core/src/main/asciidoc/images/tiger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-core/src/main/asciidoc/images/tiger.png
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/NumberVerifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta;
17 |
18 | /**
19 | * Internal helper class, utils to {@link Number}
20 | * @author otaviojava
21 | * @author keilw
22 | * @since 1.0.1
23 | */
24 | class NumberVerifier {
25 |
26 | private NumberVerifier() {
27 | }
28 |
29 | public static void checkNoInfinityOrNaN(Number number) {
30 | if (Double.class == number.getClass() || Float.class == number.getClass()) {
31 | double dValue = number.doubleValue();
32 | if (Double.isNaN(dValue)) {
33 | throw new ArithmeticException("Not a valid input: NaN.");
34 | } else if (Double.isInfinite(dValue)) {
35 | throw new ArithmeticException("Not a valid input: INFINITY: " + dValue);
36 | }
37 | }
38 | }
39 |
40 | public static boolean isInfinityAndNotNaN(Number number) {
41 | if (Double.class == number.getClass() || Float.class == number.getClass()) {
42 | double dValue = number.doubleValue();
43 | if (Double.isNaN(dValue)) {
44 | throw new ArithmeticException("Not a valid input: NaN.");
45 | } else if (Double.isInfinite(dValue)) {
46 | return true;
47 | }
48 | }
49 | return false;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/format/AmountFormatParams.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.format;
17 |
18 | /**
19 | * Class holding constants for passing additional parameters to {@link javax.money.MonetaryAmountFactoryQuery}
20 | * instances for configuring {@link javax.money.format.MonetaryAmountFormat} instances to be accessed.
21 | */
22 | public final class AmountFormatParams {
23 |
24 | /**
25 | * Non instantiatable class.
26 | */
27 | private AmountFormatParams() {
28 | }
29 |
30 | /**
31 | * Allows to pass a pattern as defined by {@link java.text.DecimalFormat}.
32 | */
33 | public static final String PATTERN = "pattern";
34 |
35 | /**
36 | * Allows to define the grouping sizes of the number groups as {@code int[]}, hereby starting from the decimal point.
37 | * So {@code 2, 2, 3} will format the number {@code 1234567890} as {@code 123.456.78.90}, assuming '.' as the only
38 | * grouping char. The grouping chars used can be similarly adapted/combined, see #GROUPING_GROUPING_SEPARATORS.
39 | */
40 | public static final String GROUPING_SIZES = "groupingSizes";
41 |
42 | /**
43 | * Allows to define the grouping characters of a number groups as {@code char[]}, hereby starting from the decimal point.
44 | * So {@code '''',':','.'} will format the number {@code 1234567890} as {@code 1'234:567.890}, assuming 3 as the only
45 | * grouping size. The grouping sizes used can be similarly adapted/combined, see #GROUPING_SIZES.
46 | */
47 | public static final String GROUPING_GROUPING_SEPARATORS = "groupingSeparators";
48 | }
49 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/format/CurrencyStyle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.format;
17 |
18 |
19 |
20 | /**
21 | * Defines the different variants of currency formatting.
22 | *
23 | * @author Anatole Tresch
24 | * @author Werner Keil
25 | */
26 | public enum CurrencyStyle {
27 |
28 | /**
29 | * The currency will be rendered as its (non localized) currency code.
30 | *
31 | * @see javax.money.CurrencyUnit#getCurrencyCode()
32 | */
33 | CODE,
34 |
35 | /**
36 | * The currency will be rendered as its localized display name. If no display
37 | * name is known for the required {@link javax.money.CurrencyUnit}, the currency code
38 | * should be used as a fall-back.
39 | *
40 | * @see javax.money.CurrencyUnit#getCurrencyCode()
41 | * @see java.util.Currency#getDisplayName(java.util.Locale)
42 | */
43 | NAME,
44 |
45 | /**
46 | * The currency will be rendered as its (non localized) numeric code.
47 | *
48 | * @see javax.money.CurrencyUnit#getNumericCode()
49 | */
50 | NUMERIC_CODE,
51 |
52 | /**
53 | * The currency will be rendered as its localized currency symbol. If no
54 | * symbol name is known for the required {@link javax.money.CurrencyUnit}, the currency
55 | * code should be used as a fall-back.
56 | *
57 | * @see javax.money.CurrencyUnit#getCurrencyCode()
58 | * @see java.util.Currency#getSymbol(java.util.Locale)
59 | */
60 | SYMBOL
61 | }
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/format/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Contains RI specific additions to the JSR 354 format API.
18 | */
19 | package org.javamoney.moneta.format;
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/DefaultMonetaryRoundedFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static java.util.Objects.requireNonNull;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryAmount;
22 | import javax.money.MonetaryOperator;
23 |
24 | import org.javamoney.moneta.RoundedMoney;
25 |
26 | /**
27 | * The default implementation to {@link MonetaryRoundedFactory}, this implementation returns the {@link RoundedMoney}.
28 | * @see MonetaryRoundedFactory#create(Number, CurrencyUnit)
29 | * @author Otavio Santana
30 | */
31 | public class DefaultMonetaryRoundedFactory implements MonetaryRoundedFactory {
32 |
33 | private final MonetaryOperator roundingOperator;
34 |
35 | public DefaultMonetaryRoundedFactory(MonetaryOperator roundingOperator) {
36 | this.roundingOperator = roundingOperator;
37 | }
38 |
39 | @Override
40 | public MonetaryAmount create(Number number, CurrencyUnit currencyUnit) {
41 | return RoundedMoney.of(requireNonNull(number), requireNonNull(currencyUnit), roundingOperator);
42 | }
43 |
44 | @Override
45 | public MonetaryOperator getRoundingOperator() {
46 | return roundingOperator;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return DefaultMonetaryRoundedFactory.class.getName() + '{' +
52 | "roundingOperator: " + roundingOperator + '}';
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/ExtractorMajorPartOperator.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import javax.money.*;
19 | import java.math.RoundingMode;
20 | import java.util.Objects;
21 |
22 | /**
23 | * This class allows to extract the major part of a {@link MonetaryAmount} instance.
24 | *
25 | * @author Anatole Tresch
26 | */
27 | final class ExtractorMajorPartOperator implements MonetaryOperator {
28 |
29 | private static final MonetaryRounding DOWN_ROUNDING =
30 | Monetary.getRounding(RoundingQueryBuilder.of().setScale(0).set(RoundingMode.DOWN).build());
31 |
32 | /**
33 | * Access the shared instance of {@link ExtractorMajorPartOperator} for use.
34 | */
35 | ExtractorMajorPartOperator() {
36 | }
37 |
38 | /**
39 | * Gets the amount in major units as a {@code MonetaryAmount} with scale 0.
40 | *
41 | * This returns the monetary amount in terms of the major units of the currency, truncating the
42 | * amount if necessary. For example, 'EUR 2.35' will return 'EUR 2', and 'BHD -1.345' will
43 | * return 'BHD -1'.
44 | *
45 | * This is returned as a {@code MonetaryAmount} rather than a {@code BigInteger} . This is to
46 | * allow further calculations to be performed on the result. Should you need a
47 | * {@code BigInteger}, simply call {@code asType(BigInteger.class)}.
48 | *
49 | *
50 | * @return the major units part of the amount, never {@code null}
51 | */
52 | @Override
53 | public MonetaryAmount apply(MonetaryAmount amount) {
54 | Objects.requireNonNull(amount, "Amount required.");
55 | return amount.with(DOWN_ROUNDING);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/ExtractorMajorPartQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.math.RoundingMode;
19 | import java.util.Objects;
20 |
21 | import javax.money.*;
22 |
23 | /**
24 | * This class allows to extract the major part of a {@link MonetaryAmount}
25 | * instance. Gets the amount in major units as a {@code long}.
26 | *
27 | * For example, 'EUR 2.35' will return 2,
28 | * and 'BHD -1.345' will return -1.
29 | *
30 | * @author Anatole Tresch
31 | * @author Otavio Santana
32 | */
33 | final class ExtractorMajorPartQuery implements MonetaryQuery {
34 |
35 | private final MonetaryOperator downRounding =
36 | Monetary.getRounding(RoundingQueryBuilder.of().setScale(0).set(RoundingMode.DOWN).build());
37 |
38 | /**
39 | * Access the shared instance of {@link ExtractorMajorPartQuery} for use.
40 | */
41 | ExtractorMajorPartQuery() {
42 | }
43 |
44 | /**
45 | * Gets the amount in major units as a {@code long}.
46 | *
47 | * This returns the monetary amount in terms of the major units of the
48 | * currency, truncating the amount if necessary. For example, 'EUR 2.35'
49 | * will return 2, and 'BHD -1.345' will return -1.
50 | *
51 | * This method matches the API of {@link java.math.BigDecimal}.
52 | *
53 | * @return the major units part of the amount
54 | * @throws ArithmeticException if the amount is too large for a {@code long}
55 | */
56 | @Override
57 | public Long queryFrom(MonetaryAmount amount) {
58 | Objects.requireNonNull(amount, "Amount required.");
59 | return amount.with(downRounding).getNumber().longValueExact();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/ExtractorMinorPartOperator.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2018, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.Objects;
21 |
22 | import javax.money.MonetaryAmount;
23 | import javax.money.MonetaryOperator;
24 |
25 | /**
26 | * This class allows to extract the minor part of a {@link MonetaryAmount}
27 | * instance.
28 | *
29 | * @author Anatole Tresch
30 | * @author Otavio Santana
31 | */
32 | final class ExtractorMinorPartOperator implements MonetaryOperator {
33 |
34 | /**
35 | * Package private constructor used from MonetaryFunctions.
36 | */
37 | ExtractorMinorPartOperator() {
38 | }
39 |
40 | /**
41 | * Gets the minor part of a {@code MonetaryAmount} with the same scale.
42 | *
43 | * This returns the monetary amount in terms of the minor units of the
44 | * currency, truncating the whole part if necessary. For example, 'EUR 2.35'
45 | * will return 'EUR 0.35', and 'BHD -1.345' will return 'BHD -0.345'.
46 | *
47 | * This is returned as a {@code MonetaryAmount} rather than a
48 | * {@code BigDecimal} . This is to allow further calculations to be
49 | * performed on the result. Should you need a {@code BigDecimal}, simply
50 | * call {@code asType(BigDecimal.class)}.
51 | *
52 | * @return the minor units part of the amount, never {@code null}
53 | */
54 | @Override
55 | public MonetaryAmount apply(MonetaryAmount amount){
56 | Objects.requireNonNull(amount, "Amount required.");
57 | BigDecimal number = amount.getNumber().numberValue(BigDecimal.class);
58 | BigDecimal wholes = number.setScale(0, RoundingMode.DOWN);
59 | return amount.subtract(amount.getFactory().setNumber(wholes).create());
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/ExtractorMinorPartQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.Objects;
21 |
22 | import javax.money.MonetaryAmount;
23 | import javax.money.MonetaryQuery;
24 |
25 | /**
26 | * This class allows to extract the minor part of a {@link MonetaryAmount}
27 | * instance.
28 | *
29 | * @author Anatole Tresch
30 | * @author Otavio Santana
31 | */
32 | final class ExtractorMinorPartQuery implements MonetaryQuery {
33 |
34 | /**
35 | * Package private constructor used from MonetaryFunctions.
36 | */
37 | ExtractorMinorPartQuery() {
38 | }
39 |
40 | /**
41 | * Extract the minor part of a {@code MonetaryAmount} with the same scale.
42 | *
43 | * This returns the monetary amount in terms of the minor units of the
44 | * currency, truncating the whole part if necessary. For example, 'EUR 2.35'
45 | * will return 35, and 'BHD -1.345' will return -345.
46 | *
47 | * This is returned as a {@code MonetaryAmount} rather than a
48 | * {@code BigDecimal} . This is to allow further calculations to be
49 | * performed on the result. Should you need a {@code BigDecimal}, simply
50 | * call {@code asType(BigDecimal.class)}.
51 | * @return the minor units part of the amount, never {@code null}
52 | */
53 | @Override
54 | public Long queryFrom(MonetaryAmount amount) {
55 | Objects.requireNonNull(amount, "Amount required.");
56 | int fractionDigits = amount.getCurrency().getDefaultFractionDigits();
57 | BigDecimal number = amount.getNumber().numberValue(BigDecimal.class);
58 | return number.setScale(fractionDigits, RoundingMode.DOWN)
59 | .remainder(BigDecimal.ONE)
60 | .movePointRight(fractionDigits).longValue();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/FastMoneyProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.util.Objects;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryAmount;
22 |
23 | import org.javamoney.moneta.FastMoney;
24 |
25 | /**
26 | * The implementation of {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
27 | * using {@link FastMoney} implementation.
28 | * @author Otavio Santana
29 | * @since 1.0.1
30 | */
31 | public final class FastMoneyProducer implements MonetaryAmountProducer {
32 |
33 | @Override
34 | public MonetaryAmount create(CurrencyUnit currency, Number number) {
35 | return FastMoney.of(Objects.requireNonNull(number), Objects.requireNonNull(currency));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/MonetaryAmountProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import javax.money.CurrencyUnit;
19 | import javax.money.MonetaryAmount;
20 |
21 | /**
22 | *The producer of {@link MonetaryAmount} from {@link CurrencyUnit} and {@link Number}
23 | * @author Otavio Santana
24 | * @see FastMoneyProducer
25 | * @see MoneyProducer
26 | * @see RoundedMoneyProducer
27 | * @since 1.0.1
28 | */
29 | @FunctionalInterface
30 | public interface MonetaryAmountProducer {
31 | /**
32 | * Creates a {@link MonetaryAmount} from {@link CurrencyUnit} and {@link Number}
33 | * @param currency the currency unit, not null.
34 | * @param number the amount, not null.
35 | * @return a {@link MonetaryAmount} never null
36 | * @throws NullPointerException if currency and Number is null
37 | */
38 | MonetaryAmount create(CurrencyUnit currency, Number number);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/MoneyProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.util.Objects;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryAmount;
22 |
23 | import org.javamoney.moneta.Money;
24 |
25 | /**
26 | * The implementation of {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
27 | * using {@link Money} implementation.
28 | * @author Otavio Santana
29 | * @since 1.0.1
30 | */
31 | public final class MoneyProducer implements MonetaryAmountProducer {
32 |
33 | @Override
34 | public MonetaryAmount create(CurrencyUnit currency, Number number) {
35 | return Money.of(Objects.requireNonNull(number), Objects.requireNonNull(currency));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/ReciprocalOperator.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.math.BigDecimal;
19 |
20 | import javax.money.MonetaryAmount;
21 | import javax.money.MonetaryOperator;
22 | import javax.money.NumberValue;
23 |
24 | import static java.math.BigDecimal.ONE;
25 | import static java.math.RoundingMode.HALF_EVEN;
26 | import static java.util.Objects.requireNonNull;
27 |
28 | /**
29 | * This class allows to extract the reciprocal value (multiplicative inversion)
30 | * of a {@link MonetaryAmount} instance.
31 | *
32 | * @author Anatole Tresch
33 | */
34 | final class ReciprocalOperator implements MonetaryOperator {
35 |
36 | /**
37 | * Access the shared instance of {@link ReciprocalOperator} for use.
38 | */
39 | ReciprocalOperator(){
40 | }
41 |
42 | /**
43 | * Gets the amount as reciprocal / multiplicative inversed value (1/n).
44 | *
45 | * E.g. 'EUR 2.0' will be converted to 'EUR 0.5'.
46 | *
47 | * @return the reciprocal / multiplicative inversed of the amount
48 | * @throws ArithmeticException if the arithmetic operation failed
49 | */
50 | @Override
51 | public MonetaryAmount apply(MonetaryAmount amount) {
52 | requireNonNull(amount, "Amount required.");
53 | NumberValue num = amount.getNumber();
54 | BigDecimal one = ONE.setScale(num.getScale() < 5 ? 5 : num.getScale(), HALF_EVEN);
55 | BigDecimal reciprocal = one.divide(num.numberValue(BigDecimal.class), HALF_EVEN);
56 | return amount.getFactory().setNumber(reciprocal).create();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/RoundedMoneyProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.util.Objects;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.Monetary;
22 | import javax.money.MonetaryAmount;
23 | import javax.money.MonetaryOperator;
24 |
25 | import org.javamoney.moneta.RoundedMoney;
26 |
27 | /**
28 | * The implementation of {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
29 | * using {@link RoundedMoney} using the {@link MonetaryOperator} as rounding operator
30 | * @see RoundedMoneyProducer#RoundedMoneyProducer(MonetaryOperator)
31 | * @author Otavio Santana
32 | * @since 1.0.1
33 | */
34 | public final class RoundedMoneyProducer implements MonetaryAmountProducer {
35 |
36 | private final MonetaryOperator operator;
37 |
38 | /**
39 | * Creates this producer using this operator
40 | * as rounding operator in all MonetaryAmount produced.
41 | * @param operator the rounding, not null.
42 | * @throws NullPointerException if operator is null
43 | */
44 | public RoundedMoneyProducer(MonetaryOperator operator) {
45 | this.operator = Objects.requireNonNull(operator);
46 | }
47 |
48 | /**
49 | * Returns the {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
50 | * using the {@link RoundedMoney} implementation using {@link Monetary#getDefaultRounding()}
51 | * as rounding operator
52 | * @see RoundedMoneyProducer
53 | */
54 | public RoundedMoneyProducer() {
55 | this.operator = MonetaryOperators.rounding();
56 | }
57 |
58 | @Override
59 | public MonetaryAmount create(CurrencyUnit currency, Number number) {
60 | return RoundedMoney.of(Objects.requireNonNull(number), Objects.requireNonNull(currency), operator);
61 | }
62 |
63 | public MonetaryOperator getOperator() {
64 | return operator;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/RoundingMonetaryAmountOperator.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import java.math.BigDecimal;
19 | import java.math.RoundingMode;
20 | import java.util.Objects;
21 | import java.util.OptionalInt;
22 |
23 | import javax.money.CurrencyUnit;
24 | import javax.money.MonetaryAmount;
25 | import javax.money.MonetaryOperator;
26 |
27 | class RoundingMonetaryAmountOperator implements MonetaryOperator {
28 |
29 | static final RoundingMode DEFAULT_ROUNDING_MONETARY_AMOUNT = RoundingMode.HALF_EVEN;
30 |
31 | private final RoundingMode roundingMode;
32 |
33 | private final OptionalInt scaleOptional;
34 |
35 | public RoundingMonetaryAmountOperator() {
36 | this.roundingMode = DEFAULT_ROUNDING_MONETARY_AMOUNT;
37 | scaleOptional = OptionalInt.empty();
38 | }
39 |
40 | public RoundingMonetaryAmountOperator(RoundingMode roundingMode) {
41 | this.roundingMode = roundingMode;
42 | scaleOptional = OptionalInt.empty();
43 | }
44 |
45 | public RoundingMonetaryAmountOperator(RoundingMode roundingMode, int scale) {
46 | this.roundingMode = roundingMode;
47 | this.scaleOptional = OptionalInt.of(scale);
48 |
49 | }
50 |
51 | @Override
52 | public MonetaryAmount apply(MonetaryAmount amount) {
53 | Objects.requireNonNull(amount, "Amount required.");
54 | CurrencyUnit currency = amount.getCurrency();
55 | int scale = scaleOptional.orElse(currency.getDefaultFractionDigits());
56 | BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode);
57 | return amount.getFactory().setNumber(value).create();
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/function/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Contains additional functional extensions.
18 | */
19 | package org.javamoney.moneta.function;
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/internal/OSGIServiceComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2017, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.internal;
17 |
18 | import org.osgi.framework.ServiceReference;
19 |
20 | import jakarta.annotation.Priority;
21 | import java.util.Comparator;
22 |
23 | /**
24 | * Comparator implementation for ordering services loaded based on their increasing priority values.
25 | */
26 | class OSGIServiceComparator implements Comparator> {
27 |
28 | @Override
29 | public int compare(ServiceReference> o1, ServiceReference> o2) {
30 | return Integer.compare(getPriority(o1), getPriority(o2));
31 | }
32 |
33 | /**
34 | * Checks the given instance for a @Priority annotation. If present the annotation's value is evaluated. If no such
35 | * annotation is present, a default priority {@code 1} is returned.
36 | *
37 | * @param o the instance, not {@code null}.
38 | * @return a priority, by default 1.
39 | */
40 | public static int getPriority(Object o) {
41 | return getPriority(o.getClass());
42 | }
43 |
44 | /**
45 | * Checks the given type optionally annotated with a @Priority. If present the annotation's value is evaluated.
46 | * If no such annotation is present, a default priority {@code 1} is returned.
47 | *
48 | * @param type the type, not {@code null}.
49 | * @return a priority, by default 1.
50 | */
51 | public static int getPriority(Class> type) {
52 | int prio = 1;
53 | Priority priority = type.getAnnotation(Priority.class);
54 | if (priority != null) {
55 | prio = priority.value();
56 | }
57 | return prio;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/internal/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2022, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Contains format artifacts implementing {@link javax.money.spi.CurrencyProviderSpi},
18 | * {@link javax.money.MonetaryAmountFactory},
19 | * {@link javax.money.spi.MonetaryAmountFactoryProviderSpi} and {@link javax.money.spi.RoundingProviderSpi}.
20 | */
21 | package org.javamoney.moneta.internal;
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Contains public core implementation artifacts, e.g. implementations of {@link javax.money.MonetaryAmount}.
18 | */
19 | package org.javamoney.moneta;
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/FastMoneyAmountFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import java.math.RoundingMode;
19 |
20 | import javax.money.*;
21 |
22 | import org.javamoney.moneta.FastMoney;
23 |
24 | /**
25 | * Implementation of {@link javax.money.MonetaryAmountFactory} creating instances of {@link FastMoney}.
26 | *
27 | * @author Anatole Tresch
28 | * @author Werner Keil
29 | */
30 | public class FastMoneyAmountFactory extends AbstractAmountFactory {
31 |
32 | static final MonetaryContext DEFAULT_CONTEXT =
33 | MonetaryContextBuilder.of(FastMoney.class).setPrecision(19).setMaxScale(5).setFixedScale(true)
34 | .set(RoundingMode.HALF_EVEN).build();
35 | static final MonetaryContext MAX_CONTEXT =
36 | MonetaryContextBuilder.of(FastMoney.class).setPrecision(19).setMaxScale(5).setFixedScale(true)
37 | .set(RoundingMode.HALF_EVEN).build();
38 |
39 | @Override
40 | protected FastMoney create(Number number, CurrencyUnit currency, MonetaryContext monetaryContext) {
41 | return FastMoney.of(number, currency);
42 | }
43 |
44 | @Override
45 | public Class getAmountType() {
46 | return FastMoney.class;
47 | }
48 |
49 | @Override
50 | public NumberValue getMaxNumber() {
51 | return FastMoney.MAX_VALUE.getNumber();
52 | }
53 |
54 | @Override
55 | public NumberValue getMinNumber() {
56 | return FastMoney.MIN_VALUE.getNumber();
57 | }
58 |
59 | @Override
60 | protected MonetaryContext loadDefaultMonetaryContext() {
61 | return DEFAULT_CONTEXT;
62 | }
63 |
64 | @Override
65 | protected MonetaryContext loadMaxMonetaryContext() {
66 | return MAX_CONTEXT;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/FastMoneyAmountFactoryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import javax.money.MonetaryAmountFactory;
19 | import javax.money.MonetaryContext;
20 | import javax.money.spi.MonetaryAmountFactoryProviderSpi;
21 |
22 | import org.javamoney.moneta.FastMoney;
23 |
24 | /**
25 | * Implementation of {@link MonetaryAmountFactoryProviderSpi} creating instances of
26 | * {@link FastMoneyAmountFactory}.
27 | *
28 | * @author Anatole Tresch
29 | */
30 | public final class FastMoneyAmountFactoryProvider implements MonetaryAmountFactoryProviderSpi{
31 |
32 | @Override
33 | public Class getAmountType(){
34 | return FastMoney.class;
35 | }
36 |
37 | @Override
38 | public MonetaryAmountFactory createMonetaryAmountFactory(){
39 | // TODO ensure context!
40 | return new FastMoneyAmountFactory();
41 | }
42 |
43 | /*
44 | * (non-Javadoc)
45 | * @see javax.money.spi.MonetaryAmountFactoryProviderSpi#getQueryInclusionPolicy()
46 | */
47 | @Override
48 | public QueryInclusionPolicy getQueryInclusionPolicy(){
49 | return QueryInclusionPolicy.ALWAYS;
50 | }
51 |
52 | @Override
53 | public MonetaryContext getDefaultMonetaryContext(){
54 | return FastMoneyAmountFactory.DEFAULT_CONTEXT;
55 | }
56 |
57 | @Override
58 | public MonetaryContext getMaximalMonetaryContext(){
59 | return FastMoneyAmountFactory.MAX_CONTEXT;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/FastMoneyProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import java.util.Objects;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryAmount;
22 |
23 | import org.javamoney.moneta.FastMoney;
24 |
25 | /**
26 | * The implementation of {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
27 | * using {@link FastMoney} implementation.
28 | * @author Otavio Santana
29 | */
30 | public final class FastMoneyProducer implements MonetaryAmountProducer {
31 |
32 | @Override
33 | public MonetaryAmount create(CurrencyUnit currency, Number number) {
34 | return FastMoney.of(Objects.requireNonNull(number), Objects.requireNonNull(currency));
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/MonetaryAmountProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import javax.money.CurrencyUnit;
19 | import javax.money.MonetaryAmount;
20 |
21 | /**
22 | *The producer of {@link MonetaryAmount} from {@link CurrencyUnit} and {@link Number}
23 | * @author Otavio Santana
24 | * @see FastMoneyProducer
25 | * @see MoneyProducer
26 | * @see RoundedMoneyProducer
27 | */
28 | @FunctionalInterface
29 | public interface MonetaryAmountProducer {
30 | /**
31 | * Creates a {@link MonetaryAmount} from {@link CurrencyUnit} and {@link Number}
32 | * @param currency the currency, not null
33 | * @param number the amount, not null.
34 | * @return a {@link MonetaryAmount} never null
35 | * @throws NullPointerException if currency and Number is null
36 | */
37 | MonetaryAmount create(CurrencyUnit currency, Number number);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/MonetaryConfigProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import java.util.Map;
19 |
20 | /**
21 | * Dynamic interface for providing monetary configuration. Register a custom implementation with the {@link java.util.ServiceLoader}
22 | * to configure JavaMoney.
23 | */
24 | public interface MonetaryConfigProvider {
25 |
26 | /**
27 | * Simple methoid to get a property.
28 | * @param key the key, not null.
29 | * @return the value, or null.
30 | */
31 | default String getProperty(String key){
32 | return getProperties().get(key);
33 | }
34 |
35 | /**
36 | * Get all currently known properties.
37 | * @return the properties, never null.
38 | */
39 | Map getProperties();
40 | }
41 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/MoneyAmountFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2022, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import java.math.RoundingMode;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryContext;
22 | import javax.money.MonetaryContextBuilder;
23 | import javax.money.NumberValue;
24 |
25 | import org.javamoney.moneta.Money;
26 |
27 | /**
28 | * Implementation of {@link javax.money.MonetaryAmountFactory} creating instances of {@link Money}.
29 | *
30 | * @author Anatole Tresch
31 | * @author Werner Keil
32 | */
33 | public class MoneyAmountFactory extends AbstractAmountFactory {
34 |
35 | static final MonetaryContext DEFAULT_CONTEXT =
36 | MonetaryContextBuilder.of(Money.class).set(64).setMaxScale(63).set(RoundingMode.HALF_EVEN).build();
37 | static final MonetaryContext MAX_CONTEXT =
38 | MonetaryContextBuilder.of(Money.class).setPrecision(0).setMaxScale(-1).set(RoundingMode.HALF_EVEN).build();
39 |
40 | @Override
41 | protected Money create(Number number, CurrencyUnit currency, MonetaryContext monetaryContext) {
42 | return Money.of(number, currency, MonetaryContext.from(monetaryContext, Money.class));
43 | }
44 |
45 | @Override
46 | public NumberValue getMaxNumber() {
47 | return null;
48 | }
49 |
50 | @Override
51 | public NumberValue getMinNumber() {
52 | return null;
53 | }
54 |
55 | @Override
56 | public Class getAmountType() {
57 | return Money.class;
58 | }
59 |
60 | @Override
61 | protected MonetaryContext loadDefaultMonetaryContext() {
62 | return DEFAULT_CONTEXT;
63 | }
64 |
65 | @Override
66 | protected MonetaryContext loadMaxMonetaryContext() {
67 | return MAX_CONTEXT;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/MoneyAmountFactoryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import jakarta.annotation.Priority;
19 | import javax.money.MonetaryAmountFactory;
20 | import javax.money.MonetaryContext;
21 | import javax.money.spi.MonetaryAmountFactoryProviderSpi;
22 |
23 | import org.javamoney.moneta.Money;
24 |
25 | /**
26 | * Implementation of {@link MonetaryAmountFactoryProviderSpi} creating instances of
27 | * {@link MoneyAmountFactory}.
28 | *
29 | * @author Anatole Tresch
30 | */
31 | @Priority(10)
32 | public final class MoneyAmountFactoryProvider implements MonetaryAmountFactoryProviderSpi{
33 |
34 | @Override
35 | public Class getAmountType(){
36 | return Money.class;
37 | }
38 |
39 | @Override
40 | public MonetaryAmountFactory createMonetaryAmountFactory(){
41 | return new MoneyAmountFactory();
42 | }
43 |
44 | /*
45 | * (non-Javadoc)
46 | * @see javax.money.spi.MonetaryAmountFactoryProviderSpi#getQueryInclusionPolicy()
47 | */
48 | @Override
49 | public QueryInclusionPolicy getQueryInclusionPolicy(){
50 | return QueryInclusionPolicy.ALWAYS;
51 | }
52 |
53 | @Override
54 | public MonetaryContext getDefaultMonetaryContext(){
55 | return MoneyAmountFactory.DEFAULT_CONTEXT;
56 | }
57 |
58 | @Override
59 | public MonetaryContext getMaximalMonetaryContext(){
60 | return MoneyAmountFactory.MAX_CONTEXT;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/MoneyProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import java.util.Objects;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryAmount;
22 |
23 | import org.javamoney.moneta.Money;
24 |
25 | /**
26 | * The implementation of {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
27 | * using {@link Money} implementation.
28 | * @author Otavio Santana
29 | */
30 | public final class MoneyProducer implements MonetaryAmountProducer {
31 |
32 | @Override
33 | public MonetaryAmount create(CurrencyUnit currency, Number number) {
34 | return Money.of(Objects.requireNonNull(number), Objects.requireNonNull(currency));
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/RoundedMoneyAmountFactoryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import javax.money.MonetaryAmountFactory;
19 | import javax.money.MonetaryContext;
20 | import javax.money.spi.MonetaryAmountFactoryProviderSpi;
21 |
22 | import org.javamoney.moneta.RoundedMoney;
23 |
24 | /**
25 | * Implementation of {@link MonetaryAmountFactoryProviderSpi} creating instances of
26 | * {@link RoundedMoneyAmountFactory}.
27 | *
28 | * @author Anatole Tresch
29 | */
30 | public final class RoundedMoneyAmountFactoryProvider implements MonetaryAmountFactoryProviderSpi{
31 |
32 | @Override
33 | public Class getAmountType(){
34 | return RoundedMoney.class;
35 | }
36 |
37 | @Override
38 | public MonetaryAmountFactory createMonetaryAmountFactory(){
39 | return new RoundedMoneyAmountFactory();
40 | }
41 |
42 | /*
43 | * (non-Javadoc)
44 | * @see javax.money.spi.MonetaryAmountFactoryProviderSpi#getQueryInclusionPolicy()
45 | */
46 | @Override
47 | public QueryInclusionPolicy getQueryInclusionPolicy(){
48 | return QueryInclusionPolicy.DIRECT_REFERENCE_ONLY;
49 | }
50 |
51 | @Override
52 | public MonetaryContext getDefaultMonetaryContext(){
53 | return RoundedMoneyAmountFactory.DEFAULT_CONTEXT;
54 | }
55 |
56 | @Override
57 | public MonetaryContext getMaximalMonetaryContext(){
58 | return RoundedMoneyAmountFactory.MAX_CONTEXT;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/RoundedMoneyProducer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import java.util.Objects;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.MonetaryAmount;
22 | import javax.money.MonetaryOperator;
23 |
24 | import org.javamoney.moneta.RoundedMoney;
25 | import org.javamoney.moneta.function.MonetaryOperators;
26 |
27 | /**
28 | * The implementation of {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
29 | * using {@link RoundedMoney} using the {@link MonetaryOperator} as rounding operator
30 | * @see RoundedMoneyProducer#RoundedMoneyProducer(MonetaryOperator)
31 | * @author Otavio Santana
32 | */
33 | public final class RoundedMoneyProducer implements MonetaryAmountProducer {
34 |
35 | private final MonetaryOperator operator;
36 |
37 | /**
38 | * Creates this producer using this operator
39 | * as rounding operator in all MonetaryAmount produced.
40 | * @param operator the rounding, not null.
41 | * @throws NullPointerException if operator is null
42 | */
43 | public RoundedMoneyProducer(MonetaryOperator operator) {
44 | this.operator = Objects.requireNonNull(operator);
45 | }
46 |
47 | /**
48 | * Returns the {@link MonetaryAmountProducer} that creates {@link MonetaryAmount}
49 | * using the {@link RoundedMoney} implementation using {@link MonetaryOperators#rounding()}
50 | * as rounding operator
51 | * @see RoundedMoneyProducer
52 | */
53 | public RoundedMoneyProducer() {
54 | this.operator = MonetaryOperators.rounding();
55 | }
56 |
57 | @Override
58 | public MonetaryAmount create(CurrencyUnit currency, Number number) {
59 | return RoundedMoney.of(Objects.requireNonNull(number), Objects.requireNonNull(currency), operator);
60 | }
61 |
62 | public MonetaryOperator getOperator() {
63 | return operator;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/format/FormatToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi.format;
17 |
18 | import java.io.IOException;
19 |
20 | import javax.money.MonetaryAmount;
21 | import javax.money.format.MonetaryParseException;
22 |
23 | /**
24 | * Abstraction for a token that is part of a token stream, used for formatting
25 | * and parsing.
26 | *
27 | * @author Anatole Tresch
28 | */
29 | public interface FormatToken {
30 | /**
31 | * Parse the context, based on the given {@link ParseContext}.
32 | *
33 | * @param context
34 | * the current {@link ParseContext}.
35 | * @throws MonetaryParseException
36 | * if parsing fails.
37 | */
38 | void parse(ParseContext context) throws MonetaryParseException;
39 |
40 | /**
41 | * Formats the given {@link MonetaryAmount} to an {@link Appendable}.
42 | * @param appendable the {@link Appendable}, not {@code null}.
43 | * @param amount the {@link MonetaryAmount} to be formatted, not {@code null}.
44 | * @throws IOException thrown by the {@link Appendable} on appending.
45 | */
46 | void print(Appendable appendable, MonetaryAmount amount)
47 | throws IOException;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/format/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2024, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Contains format service implementations.
18 | */
19 | package org.javamoney.moneta.spi.format;
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/DaemonThreadFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.spi.loader;
17 |
18 | import java.util.concurrent.Executors;
19 | import java.util.concurrent.ThreadFactory;
20 |
21 | /**
22 | * Decorator to {@link Executors#defaultThreadFactory()} that make thread as daemon.
23 | * Set {@link Thread#setDaemon(boolean)} as true
24 | * @see Thread
25 | * @author Otavio Santana
26 | */
27 | public enum DaemonThreadFactory implements ThreadFactory {
28 |
29 | /**
30 | * The singleton instance to {@link DaemonThreadFactory}
31 | */
32 | INSTANCE;
33 |
34 | private final ThreadFactory threadFactory;
35 |
36 | DaemonThreadFactory () {
37 | threadFactory = Executors.defaultThreadFactory();
38 | }
39 |
40 | @Override
41 | public Thread newThread(Runnable runnable) {
42 | Thread thread = threadFactory.newThread(runnable);
43 | thread.setDaemon(true);
44 | return thread;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/DataStreamFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2012, 2024, Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.spi.loader;
17 |
18 | import java.io.InputStream;
19 |
20 | @FunctionalInterface
21 | public interface DataStreamFactory {
22 | InputStream getDataStream();
23 | }
24 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/ResourceCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2023, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi.loader;
17 |
18 | import java.io.IOException;
19 |
20 | /**
21 | * Abstraction of a {@link ResourceCache}.
22 | *
23 | * @author Anatole Tresch
24 | * @author Werner Keil
25 | */
26 | public interface ResourceCache {
27 | /**
28 | * Write the given byte array to the format store and register it on the
29 | * given resource ID.
30 | *
31 | * @param resourceId
32 | * the resource id, never {@code null}.
33 | * @param data
34 | * the data
35 | * @throws IOException
36 | * when an IO error occurs.
37 | */
38 | void write(String resourceId, byte[] data)throws IOException;
39 |
40 | /**
41 | * Allows to query if a resource with the given id is present within the
42 | * local cache.
43 | *
44 | * @param resourceId
45 | * The resourceId
46 | * @return true, if the resource was found in the local cache.
47 | */
48 | boolean isCached(String resourceId);
49 |
50 | /**
51 | * Reads the given resource, identified by the resourceId, from the cache.
52 | *
53 | * @param resourceId
54 | * the resource id.
55 | * @return the data of the resource.
56 | * @throws IllegalArgumentException
57 | * if no such resource is existing.
58 | */
59 | byte[] read(String resourceId);
60 |
61 | /**
62 | * Remove a cache entry.
63 | * @param resourceId the resource identifier, not null.
64 | */
65 | void clear(String resourceId);
66 | }
67 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/HttpLoadLocalDataService.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2024, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi.loader.okhttp;
17 |
18 | import org.javamoney.moneta.spi.loader.LoaderListener;
19 |
20 | import java.util.Map;
21 | import java.util.Objects;
22 | import java.util.logging.Level;
23 | import java.util.logging.Logger;
24 |
25 | class HttpLoadLocalDataService {
26 |
27 | private static final Logger LOG = Logger.getLogger(HttpLoadLocalDataService.class.getName());
28 |
29 | private final Map resources;
30 |
31 | private final LoaderListener listener;
32 |
33 |
34 | HttpLoadLocalDataService(Map resources,
35 | LoaderListener listener) {
36 | this.resources = resources;
37 | this.listener = listener;
38 | }
39 |
40 |
41 | public boolean execute(String resourceId) {
42 | LoadableHttpResource load = this.resources.get(resourceId);
43 | if (Objects.nonNull(load)) {
44 | try {
45 | if (load.loadFallback()) {
46 | listener.trigger(resourceId, load);
47 | return true;
48 | }
49 | } catch (Exception e) {
50 | LOG.log(Level.SEVERE, "Failed to load resource locally: " + resourceId, e);
51 | }
52 | } else {
53 | throw new IllegalArgumentException("No such resource: " + resourceId);
54 | }
55 | return false;
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return HttpLoadLocalDataService.class.getName() + '{' + " resources: "
61 | + resources + ", defaultLoaderListener: " + listener + '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/HttpLoadRemoteDataService.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2024, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi.loader.okhttp;
17 |
18 | import org.javamoney.moneta.spi.loader.LoaderListener;
19 | import org.javamoney.moneta.spi.loader.DataStreamFactory;
20 |
21 | import java.util.Map;
22 | import java.util.Objects;
23 | import java.util.logging.Level;
24 | import java.util.logging.Logger;
25 |
26 | class HttpLoadRemoteDataService {
27 |
28 | private static final Logger LOG = Logger.getLogger(HttpLoadRemoteDataService.class.getName());
29 |
30 | private final LoaderListener listener;
31 |
32 | HttpLoadRemoteDataService(LoaderListener listener) {
33 | this.listener = listener;
34 | }
35 |
36 | public boolean execute(String resourceId,
37 | Map resources) {
38 |
39 | LoadableHttpResource load = resources.get(resourceId);
40 | if (Objects.nonNull(load)) {
41 | try {
42 | load.readCache();
43 | listener.trigger(resourceId, load);
44 | load.loadRemote();
45 | listener.trigger(resourceId, load);
46 | LOG.config("The exchange rate with resourceId " + resourceId + " was started remotely");
47 | return true;
48 | } catch (Exception e) {
49 | LOG.log(Level.SEVERE, "Failed to load resource: " + resourceId,
50 | e);
51 | }
52 | } else {
53 | throw new IllegalArgumentException("No such resource: "
54 | + resourceId);
55 | }
56 | return false;
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | return HttpLoadRemoteDataService.class.getName() + '{' + " listener: " + listener + '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/okhttp/LoadableHttpResourceBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2023, 2024, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | package org.javamoney.moneta.spi.loader.okhttp;
17 |
18 | import org.javamoney.moneta.spi.loader.LoadDataInformation;
19 | import org.javamoney.moneta.spi.loader.ResourceCache;
20 |
21 | import java.util.Objects;
22 |
23 | /**
24 | * Builder for {@link LoadableHttpResource}.
25 | * @author Werner Keil
26 | */
27 | class LoadableHttpResourceBuilder {
28 |
29 | private LoadDataInformation loadDataInformation;
30 |
31 | private ResourceCache cache;
32 |
33 | public LoadableHttpResourceBuilder withLoadDataInformation(LoadDataInformation loadDataInformation) {
34 | this.loadDataInformation = loadDataInformation;
35 | return this;
36 | }
37 |
38 | public LoadableHttpResourceBuilder withCache(ResourceCache cache) {
39 | this.cache = cache;
40 | return this;
41 | }
42 |
43 | public LoadableHttpResource build() {
44 | if(Objects.isNull(cache)) {
45 | throw new IllegalStateException("The cache should be present");
46 | }
47 | if(Objects.isNull(loadDataInformation)) {
48 | throw new IllegalStateException("The loadDataInformation should be present");
49 | }
50 | return new LoadableHttpResource(cache, loadDataInformation);
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return LoadableHttpResourceBuilder.class.getName() + '{' +
56 | " loadDataInformation: " + loadDataInformation + ',' +
57 | " cache: " + loadDataInformation + '}';
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/loader/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2024, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Contains loaders for updating resources from remote locations, e.g. currency conversion rates.
18 | */
19 | package org.javamoney.moneta.spi.loader;
--------------------------------------------------------------------------------
/moneta-core/src/main/java/org/javamoney/moneta/spi/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | use this file except in compliance with the License. You may obtain a copy of
6 | the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | License for the specific language governing permissions and limitations under
14 | the License.
15 | */
16 | /**
17 | * Defines common base classes used for implementing SPIs and the {@link org.javamoney.moneta.spi.loader.LoaderService}.
18 | */
19 | package org.javamoney.moneta.spi;
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.CurrencyProviderSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.JDKCurrencyProvider
16 | org.javamoney.moneta.spi.ConfigurableCurrencyUnitProvider
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.MonetaryAmountFactoryProviderSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.MoneyAmountFactoryProvider
16 | org.javamoney.moneta.spi.FastMoneyAmountFactoryProvider
17 | org.javamoney.moneta.spi.RoundedMoneyAmountFactoryProvider
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.MonetaryAmountFormatProviderSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.format.DefaultAmountFormatProviderSpi
16 |
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.MonetaryAmountsSingletonQuerySpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.DefaultMonetaryAmountsSingletonQuerySpi
16 |
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.MonetaryAmountsSingletonSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.DefaultMonetaryAmountsSingletonSpi
16 |
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.MonetaryCurrenciesSingletonSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.DefaultMonetaryCurrenciesSingletonSpi
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.RoundingProviderSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.DefaultRoundingProvider
16 |
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/javax.money.spi.ServiceProvider:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.PriorityAwareServiceProvider
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/org.javamoney.moneta.spi.MonetaryConfigProvider:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.DefaultConfigProvider
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/META-INF/services/org.javamoney.moneta.spi.loader.LoaderService:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2025, Credit Suisse, Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.spi.loader.okhttp.OkHttpLoaderService
--------------------------------------------------------------------------------
/moneta-core/src/main/resources/javamoney.properties:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | # Default MathContext for Money
16 | #-------------------------------
17 | # Custom MathContext, overrides entries from
18 | {-1}org.javamoney.moneta.Money.defaults.precision=256
19 | # RoundingMode enum values
20 | {-1}org.javamoney.moneta.Money.defaults.roundingMode=HALF_EVEN
21 | # or, use one of DECIMAL32,DECIMAL64(default),DECIMAL128,UNLIMITED
22 | # org.javamoney.moneta.Money.defaults.mathContext=DECIMAL128
23 |
24 | #Values to Test Override Mechanism
25 | {1}theWinner1=theWinner1
26 | theWinner2=theLooser1
27 | {-1}theWinner3=theLooser1
28 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/BuildableCurrencyUnitTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta;
17 |
18 | import static org.testng.Assert.assertEquals;
19 |
20 | import java.io.ByteArrayInputStream;
21 | import java.io.ByteArrayOutputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.io.ObjectInputStream;
25 | import java.io.ObjectOutputStream;
26 |
27 | import javax.money.CurrencyUnit;
28 |
29 | import org.testng.annotations.Test;
30 |
31 | /**
32 | * @author Philippe Marschall
33 | */
34 | public class BuildableCurrencyUnitTest {
35 |
36 | /**
37 | * Tests that currencies built by {@link CurrencyUnitBuilder} are serializable.
38 | */
39 | @Test
40 | public void testSerialization() throws ClassNotFoundException, IOException {
41 | CurrencyUnit currencyUnit = CurrencyUnitBuilder.of("SDR", "serialization-test")
42 | .setDefaultFractionDigits(3).build(false);
43 |
44 | CurrencyUnit copy = (CurrencyUnit) deserailize(serailize(currencyUnit));
45 | assertEquals(currencyUnit, copy);
46 | }
47 |
48 | private byte[] serailize(Object obj) throws IOException {
49 | ByteArrayOutputStream out = new ByteArrayOutputStream();
50 | try (ObjectOutputStream objectStream = new ObjectOutputStream(out)) {
51 | objectStream.writeObject(obj);
52 | }
53 | return out.toByteArray();
54 | }
55 |
56 | private Object deserailize(byte[] buf) throws IOException, ClassNotFoundException {
57 | try (InputStream in = new ByteArrayInputStream(buf);
58 | ObjectInputStream objectStream = new ObjectInputStream(in)) {
59 | return objectStream.readObject();
60 | }
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/CurrencyQueryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta;
17 |
18 | import static java.util.stream.Collectors.toSet;
19 | import static org.testng.Assert.assertFalse;
20 | import static org.testng.Assert.assertTrue;
21 |
22 | import java.util.Collection;
23 | import java.util.Set;
24 | import java.util.regex.Pattern;
25 |
26 | import javax.money.CurrencyQuery;
27 | import javax.money.CurrencyQueryBuilder;
28 | import javax.money.CurrencyUnit;
29 | import javax.money.Monetary;
30 |
31 | import org.testng.annotations.Test;
32 |
33 | /**
34 | * @author Philippe Marschall
35 | */
36 | public class CurrencyQueryTest {
37 |
38 | /**
39 | * Tests that searching currencies by regex is supported.
40 | */
41 | @Test
42 | public void testSeachByRegex() {
43 | String dollarRegex = "\\p{Upper}{2}D";
44 | Pattern dollarPattern = Pattern.compile(dollarRegex);
45 | Collection allCurrencies = Monetary.getCurrencies(CurrencyQueryBuilder.of().build());
46 | Set availableDollarCodes = allCurrencies.stream()
47 | .map(CurrencyUnit::getCurrencyCode)
48 | .filter(currencyCode -> dollarPattern.matcher(currencyCode).matches())
49 | .collect(toSet());
50 |
51 | assertFalse(availableDollarCodes.isEmpty());
52 |
53 | CurrencyQuery dollarQuery = CurrencyQueryBuilder.of().setCurrencyCodes(dollarRegex).build();
54 | Collection dollarCurrencies = Monetary.getCurrencies(dollarQuery);
55 | for (CurrencyUnit dollarCurrency : dollarCurrencies) {
56 | availableDollarCodes.remove(dollarCurrency.getCurrencyCode());
57 | }
58 |
59 | assertTrue(availableDollarCodes.isEmpty());
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/InvalidCurrency.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta;
17 |
18 | import javax.money.CurrencyContext;
19 | import javax.money.CurrencyUnit;
20 |
21 | public class InvalidCurrency implements CurrencyUnit {
22 |
23 | @Override
24 | public int compareTo(CurrencyUnit o) {
25 | // TODO Auto-generated method stub
26 | return 0;
27 | }
28 |
29 | @Override
30 | public String getCurrencyCode() {
31 | // TODO Auto-generated method stub
32 | return null;
33 | }
34 |
35 | @Override
36 | public int getNumericCode() {
37 | // TODO Auto-generated method stub
38 | return 0;
39 | }
40 |
41 | @Override
42 | public int getDefaultFractionDigits() {
43 | return -1;
44 | }
45 |
46 | @Override
47 | public CurrencyContext getContext() {
48 | // TODO Auto-generated method stub
49 | return null;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/ConvertMinorPartQueryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import javax.money.CurrencyUnit;
22 | import javax.money.Monetary;
23 | import javax.money.MonetaryAmount;
24 | import javax.money.MonetaryQuery;
25 |
26 | import org.javamoney.moneta.Money;
27 | import org.testng.annotations.BeforeMethod;
28 | import org.testng.annotations.Test;
29 |
30 | public class ConvertMinorPartQueryTest {
31 |
32 | private MonetaryQuery query;
33 |
34 | @BeforeMethod
35 | public void setup() {
36 | query = new ConvertMinorPartQuery();
37 | }
38 |
39 |
40 | @Test(expectedExceptions = NullPointerException.class)
41 | public void shouldReturnNPEWhenTheMonetaryAmountIsNull() {
42 | query.queryFrom(null);
43 | fail();
44 | }
45 |
46 | @Test(expectedExceptions = ArithmeticException.class)
47 | public void shouldReturnWhenTheValueIsBiggerThanLong() {
48 | CurrencyUnit real = Monetary.getCurrency("BRL");
49 | MonetaryAmount monetaryAmount = Money.of(Long.MAX_VALUE, real);
50 | query.queryFrom(monetaryAmount.add(Money.of(10, real)));
51 | fail();
52 | }
53 |
54 | @Test
55 | public void shouldReturnMajorPartPositive() {
56 | MonetaryAmount monetaryAmount = Money.parse("EUR 2.35");
57 | Long result = query.queryFrom(monetaryAmount);
58 | Long expected = 235L;
59 | assertEquals(result, expected );
60 | }
61 |
62 | @Test
63 | public void shouldReturnMajorPartNegative() {
64 | MonetaryAmount monetaryAmount = Money.parse("BHD -1.345");
65 | Long result = query.queryFrom(monetaryAmount);
66 | Long expected = -1345L;
67 | assertEquals(result, expected );
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/ExtractorMajorPartOperatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import javax.money.CurrencyUnit;
22 | import javax.money.Monetary;
23 | import javax.money.MonetaryAmount;
24 | import javax.money.MonetaryOperator;
25 |
26 | import org.javamoney.moneta.Money;
27 | import org.testng.annotations.BeforeMethod;
28 | import org.testng.annotations.Test;
29 |
30 | public class ExtractorMajorPartOperatorTest {
31 |
32 | private MonetaryOperator operator;
33 |
34 | @BeforeMethod
35 | public void setup() {
36 | operator = new ExtractorMajorPartOperator();
37 | }
38 |
39 | @Test
40 | public void shouldReturnPositiveValue() {
41 | CurrencyUnit currency = Monetary.getCurrency("EUR");
42 | MonetaryAmount money = Money.parse("EUR 2.35");
43 | MonetaryAmount result = operator.apply(money);
44 | assertEquals(result.getCurrency(), currency);
45 | assertEquals(result.getNumber().doubleValue(), 2.0);
46 |
47 | }
48 |
49 |
50 | @Test
51 | public void shouldReturnNegativeValue() {
52 | CurrencyUnit currency = Monetary.getCurrency("BHD");
53 | MonetaryAmount money = Money.parse("BHD -1.345");
54 | MonetaryAmount result = operator.apply(money);
55 | assertEquals(result.getCurrency(), currency);
56 | assertEquals(result.getNumber().doubleValue(), -1.0);
57 |
58 | }
59 |
60 | @Test(expectedExceptions = NullPointerException.class)
61 | public void shouldReturnErroWhenIsNull() {
62 | operator.apply(null);
63 | fail();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/ExtractorMajorPartQueryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import javax.money.CurrencyUnit;
22 | import javax.money.Monetary;
23 | import javax.money.MonetaryAmount;
24 | import javax.money.MonetaryQuery;
25 |
26 | import org.javamoney.moneta.Money;
27 | import org.testng.annotations.BeforeMethod;
28 | import org.testng.annotations.Test;
29 |
30 | public class ExtractorMajorPartQueryTest {
31 |
32 | private MonetaryQuery query;
33 |
34 | @BeforeMethod
35 | public void setup() {
36 | query = new ExtractorMajorPartQuery();
37 | }
38 |
39 |
40 | @Test(expectedExceptions = NullPointerException.class)
41 | public void shouldReturnNPEWhenTheMonetaryAmountIsNull() {
42 | query.queryFrom(null);
43 | fail();
44 | }
45 |
46 | @Test(expectedExceptions = ArithmeticException.class)
47 | public void shouldReturnWhenTheValueIsBiggerThanLong() {
48 | CurrencyUnit real = Monetary.getCurrency("BRL");
49 | MonetaryAmount monetaryAmount = Money.of(Long.MAX_VALUE, real);
50 | query.queryFrom(monetaryAmount.add(Money.of(10, real)));
51 | fail();
52 | }
53 |
54 | @Test
55 | public void shouldReturnMajorPartPositive() {
56 | MonetaryAmount monetaryAmount = Money.parse("EUR 2.35");
57 | Long result = query.queryFrom(monetaryAmount);
58 | Long expected = 2L;
59 | assertEquals(result, expected );
60 | }
61 |
62 | @Test
63 | public void shouldReturnMajorPartNegative() {
64 | MonetaryAmount monetaryAmount = Money.parse("BHD -1.345");
65 | Long result = query.queryFrom(monetaryAmount);
66 | Long expected = -1L;
67 | assertEquals(result, expected );
68 | }
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/ExtractorMinorPartOperatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import javax.money.CurrencyUnit;
22 | import javax.money.Monetary;
23 | import javax.money.MonetaryAmount;
24 | import javax.money.MonetaryOperator;
25 |
26 | import org.javamoney.moneta.Money;
27 | import org.testng.annotations.BeforeMethod;
28 | import org.testng.annotations.Test;
29 |
30 | public class ExtractorMinorPartOperatorTest {
31 |
32 | private MonetaryOperator operator;
33 |
34 | @BeforeMethod
35 | public void setup() {
36 | operator = new ExtractorMinorPartOperator();
37 | }
38 |
39 | @Test
40 | public void shouldReturnPositiveValue() {
41 | CurrencyUnit currency = Monetary.getCurrency("EUR");
42 | MonetaryAmount money = Money.parse("EUR 2.35");
43 | MonetaryAmount result = operator.apply(money);
44 | assertEquals(result.getCurrency(), currency);
45 | assertEquals(result.getNumber().doubleValue(), 0.35);
46 |
47 | }
48 |
49 |
50 | @Test
51 | public void shouldReturnNegativeValue() {
52 | CurrencyUnit currency = Monetary.getCurrency("BHD");
53 | MonetaryAmount money = Money.parse("BHD -1.345");
54 | MonetaryAmount result = operator.apply(money);
55 | assertEquals(result.getCurrency(), currency);
56 | assertEquals(result.getNumber().doubleValue(), -0.345);
57 |
58 | }
59 |
60 | @Test(expectedExceptions = NullPointerException.class)
61 | public void shouldReturnErroWhenIsNull() {
62 | operator.apply(null);
63 | fail();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/ExtractorMinorPartQueryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import javax.money.MonetaryAmount;
22 | import javax.money.MonetaryQuery;
23 |
24 | import org.javamoney.moneta.Money;
25 | import org.testng.annotations.BeforeMethod;
26 | import org.testng.annotations.Test;
27 |
28 | public class ExtractorMinorPartQueryTest {
29 |
30 | private MonetaryQuery query;
31 |
32 | @BeforeMethod
33 | public void setup() {
34 | query = new ExtractorMinorPartQuery();
35 | }
36 |
37 |
38 | @Test(expectedExceptions = NullPointerException.class)
39 | public void shouldReturnNPEWhenTheMonetaryAmountIsNull() {
40 | query.queryFrom(null);
41 | fail();
42 | }
43 |
44 | @Test
45 | public void shouldReturnMajorPartPositive() {
46 | MonetaryAmount monetaryAmount = Money.parse("EUR 2.35");
47 | Long result = query.queryFrom(monetaryAmount);
48 | Long expected = 35L;
49 | assertEquals(result, expected);
50 | }
51 |
52 | @Test
53 | public void shouldReturnMajorPartNegative() {
54 | MonetaryAmount monetaryAmount = Money.parse("BHD -1.345");
55 | Long result = query.queryFrom(monetaryAmount);
56 | Long expected = -345L;
57 | assertEquals(result, expected);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/FastMoneyProducerTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.assertTrue;
20 |
21 | import java.util.Locale;
22 |
23 | import javax.money.CurrencyUnit;
24 | import javax.money.Monetary;
25 | import javax.money.MonetaryAmount;
26 |
27 | import org.javamoney.moneta.FastMoney;
28 | import org.javamoney.moneta.function.FastMoneyProducer;
29 | import org.javamoney.moneta.function.MonetaryAmountProducer;
30 | import org.testng.annotations.BeforeMethod;
31 | import org.testng.annotations.Test;
32 |
33 | public class FastMoneyProducerTest {
34 |
35 | private MonetaryAmountProducer producer;
36 |
37 | private CurrencyUnit currency;
38 |
39 | @BeforeMethod
40 | public void setup() {
41 | producer = new FastMoneyProducer();
42 | currency = Monetary.getCurrency(Locale.getDefault());
43 | }
44 |
45 | @Test(expectedExceptions = NullPointerException.class)
46 | public void shouldReturnErrorWhenCurrencyIsNull() {
47 | producer.create(null, 10);
48 | }
49 |
50 | @Test(expectedExceptions = NullPointerException.class)
51 | public void shouldReturnErrorWhenNumberIsNull() {
52 | producer.create(currency, null);
53 | }
54 |
55 | @Test
56 | public void shouldCreateMonetaryAmount() {
57 | Long value = 10L;
58 | MonetaryAmount amount = producer.create(currency, value);
59 | assertEquals(amount.getCurrency(), currency);
60 | assertEquals(Long.valueOf(amount.getNumber().longValue()), value);
61 | }
62 |
63 | @Test
64 | public void shouldCreateUsingFastMoneyImplementation() {
65 | Long value = 10L;
66 | MonetaryAmount amount = producer.create(currency, value);
67 | assertTrue(FastMoney.class.isInstance(amount));
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/MonetaryQueriesTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 |
20 | import javax.money.MonetaryAmount;
21 |
22 | import org.javamoney.moneta.Money;
23 | import org.testng.annotations.Test;
24 |
25 | public class MonetaryQueriesTest {
26 |
27 |
28 | @Test
29 | public void shouldExtractMajorPart(){
30 | MonetaryAmount money = Money.parse("EUR 2.35");
31 | Long result = money.query(MonetaryQueries.extractMajorPart());
32 | assertEquals(result, Long.valueOf(2L));
33 | }
34 |
35 | @Test
36 | public void shouldConvertMinorPart(){
37 | MonetaryAmount money = Money.parse("EUR 2.35");
38 | Long result = money.query(MonetaryQueries.convertMinorPart());
39 | assertEquals(result, Long.valueOf(235L));
40 | }
41 |
42 | @Test
43 | public void shouldExtractMinorPart(){
44 | MonetaryAmount money = Money.parse("EUR 2.35");
45 | Long result = money.query(MonetaryQueries.extractMinorPart());
46 | assertEquals(result, Long.valueOf(35L));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/MoneyProducerTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.assertTrue;
20 |
21 | import java.util.Locale;
22 |
23 | import javax.money.CurrencyUnit;
24 | import javax.money.Monetary;
25 | import javax.money.MonetaryAmount;
26 |
27 | import org.javamoney.moneta.Money;
28 | import org.javamoney.moneta.function.MonetaryAmountProducer;
29 | import org.javamoney.moneta.function.MoneyProducer;
30 | import org.testng.annotations.BeforeMethod;
31 | import org.testng.annotations.Test;
32 |
33 | public class MoneyProducerTest {
34 |
35 | private MonetaryAmountProducer producer;
36 |
37 | private CurrencyUnit currency;
38 |
39 | @BeforeMethod
40 | public void setup() {
41 | producer = new MoneyProducer();
42 | currency = Monetary.getCurrency(Locale.getDefault());
43 | }
44 |
45 | @Test(expectedExceptions = NullPointerException.class)
46 | public void shouldReturnErrorWhenCurrencyIsNull() {
47 | producer.create(null, 10);
48 | }
49 |
50 | @Test(expectedExceptions = NullPointerException.class)
51 | public void shouldReturnErrorWhenNumberIsNull() {
52 | producer.create(currency, null);
53 | }
54 |
55 | @Test
56 | public void shouldCreateMonetaryAmount() {
57 | Long value = 10L;
58 | MonetaryAmount amount = producer.create(currency, value);
59 | assertEquals(amount.getCurrency(), currency);
60 | assertEquals(Long.valueOf(amount.getNumber().longValue()), value);
61 | }
62 |
63 | @Test
64 | public void shouldCreateUsingMoneyImplementation() {
65 | Long value = 10L;
66 | MonetaryAmount amount = producer.create(currency, value);
67 | assertTrue(Money.class.isInstance(amount));
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/PercentOperatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import java.math.BigDecimal;
22 |
23 | import javax.money.CurrencyUnit;
24 | import javax.money.Monetary;
25 | import javax.money.MonetaryAmount;
26 | import javax.money.MonetaryOperator;
27 |
28 | import org.javamoney.moneta.Money;
29 | import org.testng.annotations.BeforeMethod;
30 | import org.testng.annotations.Test;
31 |
32 | public class PercentOperatorTest {
33 |
34 | private MonetaryOperator operator;
35 |
36 | @BeforeMethod
37 | public void setup() {
38 | operator = new PercentOperator(BigDecimal.TEN);
39 | }
40 |
41 | @Test
42 | public void shouldReturnPositiveValue() {
43 | CurrencyUnit currency = Monetary.getCurrency("EUR");
44 | MonetaryAmount money = Money.parse("EUR 200.0");
45 | MonetaryAmount result = operator.apply(money);
46 | assertEquals(result.getCurrency(), currency);
47 | assertEquals(result.getNumber().doubleValue(), 20.0);
48 |
49 | }
50 |
51 | @Test
52 | public void shouldReturnNegativeValue() {
53 | CurrencyUnit currency = Monetary.getCurrency("BHD");
54 | MonetaryAmount money = Money.parse("BHD -200.0");
55 | MonetaryAmount result = operator.apply(money);
56 | assertEquals(result.getCurrency(), currency);
57 | assertEquals(result.getNumber().doubleValue(), -20.0);
58 | }
59 |
60 | @Test(expectedExceptions = NullPointerException.class)
61 | public void shouldReturnErroWhenIsNull() {
62 | operator.apply(null);
63 | fail();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/PermilOperatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 | import static org.testng.Assert.fail;
20 |
21 | import java.math.BigDecimal;
22 |
23 | import javax.money.CurrencyUnit;
24 | import javax.money.Monetary;
25 | import javax.money.MonetaryAmount;
26 | import javax.money.MonetaryOperator;
27 |
28 | import org.javamoney.moneta.Money;
29 | import org.testng.annotations.BeforeMethod;
30 | import org.testng.annotations.Test;
31 |
32 | public class PermilOperatorTest {
33 |
34 | private MonetaryOperator operator;
35 |
36 | @BeforeMethod
37 | public void setup() {
38 | operator = new PermilOperator(BigDecimal.TEN);
39 | }
40 |
41 | @Test
42 | public void shouldReturnPositiveValue() {
43 | CurrencyUnit currency = Monetary.getCurrency("EUR");
44 | MonetaryAmount money = Money.parse("EUR 2.35");
45 | MonetaryAmount result = operator.apply(money);
46 | assertEquals(result.getCurrency(), currency);
47 | assertEquals(result.getNumber().doubleValue(), 0.0235);
48 |
49 | }
50 |
51 |
52 | @Test
53 | public void shouldReturnNegativeValue() {
54 | CurrencyUnit currency = Monetary.getCurrency("EUR");
55 | MonetaryAmount money = Money.parse("EUR -2.35");
56 | MonetaryAmount result = operator.apply(money);
57 | assertEquals(result.getCurrency(), currency);
58 | assertEquals(result.getNumber().doubleValue(), -0.0235);
59 |
60 | }
61 |
62 | @Test(expectedExceptions = NullPointerException.class)
63 | public void shouldReturnErroWhenIsNull() {
64 | operator.apply(null);
65 | fail();
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/function/ReciprocalOperatorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.function;
17 |
18 | import static org.testng.Assert.assertEquals;
19 |
20 | import javax.money.CurrencyUnit;
21 | import javax.money.Monetary;
22 | import javax.money.MonetaryAmount;
23 | import javax.money.MonetaryOperator;
24 |
25 | import org.javamoney.moneta.Money;
26 | import org.testng.annotations.BeforeMethod;
27 | import org.testng.annotations.Test;
28 |
29 | public class ReciprocalOperatorTest {
30 |
31 | private MonetaryOperator operator;
32 |
33 | @BeforeMethod
34 | public void setup() {
35 | operator = new ReciprocalOperator();
36 | }
37 |
38 | @Test
39 | public void shouldReturnPositiveValue() {
40 | CurrencyUnit currency = Monetary.getCurrency("EUR");
41 | MonetaryAmount money = Money.parse("EUR 2.0");
42 | MonetaryAmount result = operator.apply(money);
43 | assertEquals(result.getCurrency(), currency);
44 | assertEquals(result.getNumber().doubleValue(), 0.5);
45 | }
46 |
47 | @Test
48 | public void shouldReturnNegativeValue() {
49 | CurrencyUnit currency = Monetary.getCurrency("EUR");
50 | MonetaryAmount money = Money.parse("EUR -2.0");
51 | MonetaryAmount result = operator.apply(money);
52 | assertEquals(result.getCurrency(), currency);
53 | assertEquals(result.getNumber().doubleValue(), -0.5);
54 | }
55 |
56 | @Test(expectedExceptions = NullPointerException.class)
57 | public void shouldReturnErrorWhenIsNull() {
58 | operator.apply(null);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/internal/JDKHelper.java:
--------------------------------------------------------------------------------
1 | package org.javamoney.moneta.internal;
2 |
3 | public class JDKHelper {
4 | public static int getVersion() {
5 | String version = System.getProperty("java.version");
6 | if(version.startsWith("1.")) {
7 | version = version.substring(2, 3);
8 | } else {
9 | int dot = version.indexOf(".");
10 | if(dot != -1) { version = version.substring(0, dot); }
11 | } return Integer.parseInt(version);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/spi/MonetaryConfigTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.javamoney.moneta.spi;
17 |
18 | import org.testng.annotations.Test;
19 |
20 | import static org.testng.Assert.*;
21 |
22 | /**
23 | * Test for the {@link org.javamoney.moneta.spi.MonetaryConfig} class.
24 | */
25 | public class MonetaryConfigTest {
26 |
27 | @Test
28 | public void testGetConfig() throws Exception {
29 | assertNotNull(MonetaryConfig.getConfig());
30 | assertFalse(MonetaryConfig.getConfig().isEmpty());
31 | }
32 |
33 | @Test
34 | public void testConfigOverride() throws Exception {
35 | assertEquals(MonetaryConfig.getConfig().get("theWinner1"), "theLooser2");
36 | assertEquals(MonetaryConfig.getConfig().get("theWinner2"), "theWinner2");
37 | assertEquals(MonetaryConfig.getConfig().get("theWinner3"), "theWinner2");
38 | }
39 |
40 | @Test
41 | public void testConfigNormal() throws Exception {
42 | assertEquals(MonetaryConfig.getConfig().get("myTestValue"), "myTestValue");
43 | }
44 | }
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/spi/MoneyUtilsTest.java:
--------------------------------------------------------------------------------
1 | package org.javamoney.moneta.spi;
2 |
3 | import org.javamoney.moneta.FastMoney;
4 | import org.testng.annotations.Test;
5 |
6 | import javax.money.CurrencyUnit;
7 | import javax.money.Monetary;
8 | import javax.money.MonetaryException;
9 | import java.math.BigDecimal;
10 |
11 | import static java.math.BigDecimal.TEN;
12 | import static org.javamoney.moneta.spi.MoneyUtils.*;
13 | import static org.testng.Assert.*;
14 |
15 | public class MoneyUtilsTest {
16 |
17 | @Test
18 | public void testGetBigDecimal_long() {
19 | assertEquals(getBigDecimal(10), TEN);
20 | }
21 |
22 | @Test
23 | public void testGetBigDecimal_double() {
24 | expectThrows(ArithmeticException.class, () -> getBigDecimal(Double.NaN));
25 | expectThrows(ArithmeticException.class, () -> getBigDecimal(Double.POSITIVE_INFINITY));
26 | expectThrows(ArithmeticException.class, () -> getBigDecimal(Double.NEGATIVE_INFINITY));
27 | assertEquals(getBigDecimal(0.24D), new BigDecimal("0.24"));
28 | assertEquals(getBigDecimal(0.25F), new BigDecimal("0.25"));
29 | }
30 |
31 | @Test
32 | public void testGetBigDecimal_Number() {
33 | expectThrows(ArithmeticException.class, () -> getBigDecimal(Float.valueOf(Float.NaN)));
34 | expectThrows(ArithmeticException.class, () -> getBigDecimal(Float.valueOf(Float.POSITIVE_INFINITY)));
35 | expectThrows(ArithmeticException.class, () -> getBigDecimal(Float.valueOf(Float.NEGATIVE_INFINITY)));
36 | assertEquals(getBigDecimal(Byte.valueOf((byte) 10)), TEN);
37 | assertEquals(getBigDecimal(Short.valueOf((short) 10)), TEN);
38 | assertEquals(getBigDecimal(Float.valueOf(0.24F)), new BigDecimal("0.24"));
39 | }
40 |
41 | @Test
42 | public void testCheckAmountParameter() {
43 | CurrencyUnit dollar = Monetary.getCurrency("USD");
44 | CurrencyUnit real = Monetary.getCurrency("BRL");
45 | checkAmountParameter(FastMoney.of(0, "USD"), dollar);
46 | expectThrows(MonetaryException.class, () -> checkAmountParameter(FastMoney.of(0, "USD"), real));
47 | }
48 |
49 | @Test
50 | public void testReplaceNbspWithSpace() {
51 | assertEquals(replaceNbspWithSpace("14\u202F000,12\u00A0EUR"), "14 000,12 EUR");
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/moneta-core/src/test/java/org/javamoney/moneta/spi/format/ParseContextTest.java:
--------------------------------------------------------------------------------
1 | package org.javamoney.moneta.spi.format;
2 |
3 | import org.javamoney.moneta.CurrencyUnitBuilder;
4 | import org.testng.annotations.Test;
5 |
6 | import javax.money.CurrencyUnit;
7 |
8 | import static org.testng.Assert.*;
9 |
10 | public class ParseContextTest {
11 | public static final CurrencyUnit EUR = CurrencyUnitBuilder.of("EUR", "test").build();
12 |
13 | @Test
14 | public void testSkip() {
15 | ParseContext context = new ParseContext(" \u00A0 \u202F \u2007 \u2060 EUR");
16 | context.skipWhitespace();
17 | assertEquals(context.getIndex(), " \u00A0 \u202F \u2007 ".length());
18 | }
19 |
20 | @Test
21 | public void testReset() {
22 | ParseContext context = new ParseContext(" EUR");
23 | context.skipWhitespace();
24 | assertEquals(context.getIndex(), 1);
25 | context.setError();
26 | context.setErrorIndex(2);
27 | context.setErrorMessage("Error");
28 | context.setParsedNumber(25);
29 | context.setParsedCurrency(EUR);
30 | context.reset();
31 | assertEquals(context.getOriginalInput(), " EUR");
32 | assertEquals(context.getIndex(), 0);
33 | assertEquals(context.getErrorIndex(), -1);
34 | assertNull(context.getParsedNumber());
35 | assertNull(context.getParsedCurrency());
36 | assertNull(context.getErrorMessage());
37 | }
38 |
39 | @Test
40 | public void testToString() {
41 | ParseContext context = new ParseContext(" EUR");
42 | context.skipWhitespace();
43 | assertEquals(context.getIndex(), 1);
44 | context.setError();
45 | context.setErrorIndex(2);
46 | context.setErrorMessage("Error");
47 | context.setParsedNumber(25);
48 | context.setParsedCurrency(EUR);
49 | assertEquals(context.toString(), "ParseContext [index=1, errorIndex=2, originalInput=' EUR', parsedNumber=25', parsedCurrency=BuildableCurrencyUnit(currencyCode=EUR, numericCode=-1, defaultFractionDigits=2, context=CurrencyContext (\n" +
50 | "{provider=test}))]");
51 | }
52 | }
--------------------------------------------------------------------------------
/moneta-core/src/test/resources/javamoney.properties:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | #Values to Test Override Mechanism
16 | theWinner1=theLooser2
17 | {1}theWinner2=theWinner2
18 | theWinner3=theWinner2
19 | myTestValue=myTestValue
--------------------------------------------------------------------------------
/moneta-test/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 |
2 | module org.javamoney.moneta.test {
3 | requires java.money;
4 | requires org.javamoney.moneta;
5 | provides javax.money.spi.RoundingProviderSpi with org.javamoney.moneta.test.TestRoundingProvider;
6 | }
7 |
--------------------------------------------------------------------------------
/moneta-test/src/main/resources/META-INF/services/javax.money.spi.RoundingProviderSpi:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | # use this file except in compliance with the License. You may obtain a copy of
5 | # the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | # License for the specific language governing permissions and limitations under
13 | # the License.
14 | #
15 | org.javamoney.moneta.test.TestRoundingProvider
16 |
--------------------------------------------------------------------------------
/moneta/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | test-output/
3 | /doc
4 | *.iml
5 | *.log
6 | .classpath
7 | -project
8 | /.resourceCache
9 | /.project
10 | /.idea
11 | .settings/
12 |
--------------------------------------------------------------------------------
/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ossrh
5 | ${env.CI_DEPLOY_USERNAME}
6 | ${env.CI_DEPLOY_PASSWORD}
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/etc/JVM_options.txt:
--------------------------------------------------------------------------------
1 | --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.regex=ALL-UNNAMED
--------------------------------------------------------------------------------
/src/etc/jsr354-ri clean install.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/etc/jsr354-ri test.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------