├── .circleci └── config.yml ├── .github └── FUNDING.yml ├── .gitignore ├── .run └── moneta-parent [clean install].run.xml ├── LICENSE.txt ├── README.md ├── checkstyle-suppressions.xml ├── checkstyle.xml ├── moneta-convert ├── .gitignore ├── moneta-convert-base │ ├── .gitignore │ ├── bnd.bnd │ ├── pom.xml │ └── src │ │ ├── etc │ │ └── header.txt │ │ ├── main │ │ ├── asciidoc │ │ │ ├── images │ │ │ │ ├── highlighter.png │ │ │ │ ├── icons │ │ │ │ │ ├── README │ │ │ │ │ ├── callouts │ │ │ │ │ │ ├── 1.png │ │ │ │ │ │ ├── 10.png │ │ │ │ │ │ ├── 11.png │ │ │ │ │ │ ├── 12.png │ │ │ │ │ │ ├── 13.png │ │ │ │ │ │ ├── 14.png │ │ │ │ │ │ ├── 15.png │ │ │ │ │ │ ├── 2.png │ │ │ │ │ │ ├── 3.png │ │ │ │ │ │ ├── 4.png │ │ │ │ │ │ ├── 5.png │ │ │ │ │ │ ├── 6.png │ │ │ │ │ │ ├── 7.png │ │ │ │ │ │ ├── 8.png │ │ │ │ │ │ └── 9.png │ │ │ │ │ ├── caution.png │ │ │ │ │ ├── example.png │ │ │ │ │ ├── home.png │ │ │ │ │ ├── important.png │ │ │ │ │ ├── next.png │ │ │ │ │ ├── note.png │ │ │ │ │ ├── prev.png │ │ │ │ │ ├── tip.png │ │ │ │ │ ├── up.png │ │ │ │ │ └── warning.png │ │ │ │ ├── smallnew.png │ │ │ │ └── tiger.png │ │ │ └── userguide.adoc │ │ ├── java │ │ │ ├── module-info.java │ │ │ └── org │ │ │ │ └── javamoney │ │ │ │ └── moneta │ │ │ │ ├── convert │ │ │ │ ├── ConversionOperators.java │ │ │ │ ├── DefaultExchangeRate.java │ │ │ │ ├── DefaultMonetaryConversionsSingletonSpi.java │ │ │ │ ├── ExchangeCurrencyOperator.java │ │ │ │ ├── ExchangeRateBuilder.java │ │ │ │ ├── ExchangeRateMonetarySummaryStatistics.java │ │ │ │ ├── ExchangeRateType.java │ │ │ │ ├── IdentityRateProvider.java │ │ │ │ └── internal │ │ │ │ │ ├── OSGIActivator.java │ │ │ │ │ └── package-info.java │ │ │ │ └── spi │ │ │ │ └── convert │ │ │ │ └── DefaultMonetaryConversionsSingletonSpi.java │ │ └── resources │ │ │ ├── META-INF │ │ │ └── services │ │ │ │ ├── javax.money.convert.ExchangeRateProvider │ │ │ │ ├── javax.money.convert.ExchangeRateProvider~ │ │ │ │ └── javax.money.spi.MonetaryConversionsSingletonSpi │ │ │ └── javamoney.properties~ │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── javamoney │ │ │ └── moneta │ │ │ └── convert │ │ │ ├── ConversionAggregatorTest.java │ │ │ ├── ConversionConstants.java │ │ │ ├── ConversionOperatorsTest.java │ │ │ ├── CurrencyConversionMock.java │ │ │ ├── ExchangeCurrencyOperatorTest.java │ │ │ ├── ExchangeRateBuilderTest.java │ │ │ ├── ExchangeRateMonetarySummaryStatisticsTest.java │ │ │ ├── ExchangeRateProviderMock.java │ │ │ ├── ExchangeRateSimpleTest.java │ │ │ └── StreamFactory.java │ │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── javax.money.spi.RoundingProviderSpi │ │ └── javamoney.properties ├── moneta-convert-ecb │ ├── .gitignore │ ├── bnd.bnd │ ├── pom.xml │ ├── src │ │ ├── etc │ │ │ └── header.txt │ │ ├── main │ │ │ ├── java │ │ │ │ ├── module-info.java │ │ │ │ └── org │ │ │ │ │ └── javamoney │ │ │ │ │ └── moneta │ │ │ │ │ └── convert │ │ │ │ │ └── ecb │ │ │ │ │ ├── ECBAbstractRateProvider.java │ │ │ │ │ ├── ECBCurrentRateProvider.java │ │ │ │ │ ├── ECBHistoric90RateProvider.java │ │ │ │ │ ├── ECBHistoricRateProvider.java │ │ │ │ │ ├── ECBRateReadingHandler.java │ │ │ │ │ ├── OSGIActivator.java │ │ │ │ │ ├── defaults │ │ │ │ │ └── Defaults.java │ │ │ │ │ └── package-info.java │ │ │ └── resources │ │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ ├── javax.money.convert.ExchangeRateProvider │ │ │ │ │ └── javax.money.convert.ExchangeRateProvider~ │ │ │ │ ├── javamoney.properties │ │ │ │ └── org │ │ │ │ └── javamoney │ │ │ │ └── moneta │ │ │ │ └── convert │ │ │ │ └── ecb │ │ │ │ └── defaults │ │ │ │ ├── eurofxref-daily.xml │ │ │ │ ├── eurofxref-hist-90d.xml │ │ │ │ └── eurofxref-hist.xml │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── javamoney │ │ │ │ └── moneta │ │ │ │ └── convert │ │ │ │ └── ecb │ │ │ │ ├── ConversionConstants.java │ │ │ │ ├── ECBCurrentRateProviderTest.java │ │ │ │ ├── ECBHistoric90RateProviderTest.java │ │ │ │ ├── ECBHistoricRateProviderTest.java │ │ │ │ ├── ExchangeRateTypeTest.java │ │ │ │ ├── MonetaryConversionTest.java │ │ │ │ ├── ProviderTest.java │ │ │ │ └── TestRoundingProvider.java │ │ │ └── resources │ │ │ ├── META-INF │ │ │ └── services │ │ │ │ └── javax.money.spi.RoundingProviderSpi │ │ │ └── javamoney.properties │ └── update_ecb.sh ├── moneta-convert-imf │ ├── .gitignore │ ├── bnd.bnd │ ├── pom.xml │ ├── src │ │ ├── etc │ │ │ ├── download.sh │ │ │ └── header.txt │ │ ├── main │ │ │ ├── java │ │ │ │ ├── module-info.java │ │ │ │ └── org │ │ │ │ │ └── javamoney │ │ │ │ │ └── moneta │ │ │ │ │ └── convert │ │ │ │ │ └── imf │ │ │ │ │ ├── IMFAbstractRateProvider.java │ │ │ │ │ ├── IMFHistoricRateProvider.java │ │ │ │ │ ├── IMFHistoricalType.java │ │ │ │ │ ├── IMFRateProvider.java │ │ │ │ │ ├── IMFRateReadingHandler.java │ │ │ │ │ ├── IMFRemoteSearch.java │ │ │ │ │ ├── IMFRemoteSearchCallable.java │ │ │ │ │ ├── OSGIActivator.java │ │ │ │ │ ├── defaults │ │ │ │ │ └── Defaults.java │ │ │ │ │ └── package-info.java │ │ │ └── resources │ │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── javax.money.convert.ExchangeRateProvider │ │ │ │ ├── javamoney.properties │ │ │ │ └── org │ │ │ │ └── javamoney │ │ │ │ └── moneta │ │ │ │ └── convert │ │ │ │ └── imf │ │ │ │ └── defaults │ │ │ │ └── rms_five.tsv │ │ └── test │ │ │ ├── java │ │ │ └── org │ │ │ │ └── javamoney │ │ │ │ └── moneta │ │ │ │ └── convert │ │ │ │ └── imf │ │ │ │ ├── ConversionConstants.java │ │ │ │ ├── ExchangeRateTypeTest.java │ │ │ │ ├── IMFHistoricRateProviderTest.java │ │ │ │ ├── IMFHistoricalTypeTest.java │ │ │ │ ├── IMFRateProviderTest.java │ │ │ │ ├── IMFRemoteSearchCallableTest.java │ │ │ │ ├── IMFRemoteSearchTest.java │ │ │ │ ├── MonetaryConversionTest.java │ │ │ │ ├── ProviderTest.java │ │ │ │ └── TestRoundingProvider.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── javax.money.spi.RoundingProviderSpi │ └── update_imf.sh └── pom.xml ├── moneta-core ├── .gitignore ├── bnd.bnd ├── pom.xml └── src │ ├── etc │ └── header.txt │ ├── main │ ├── asciidoc │ │ ├── images │ │ │ ├── highlighter.png │ │ │ ├── icons │ │ │ │ ├── README │ │ │ │ ├── callouts │ │ │ │ │ ├── 1.png │ │ │ │ │ ├── 10.png │ │ │ │ │ ├── 11.png │ │ │ │ │ ├── 12.png │ │ │ │ │ ├── 13.png │ │ │ │ │ ├── 14.png │ │ │ │ │ ├── 15.png │ │ │ │ │ ├── 2.png │ │ │ │ │ ├── 3.png │ │ │ │ │ ├── 4.png │ │ │ │ │ ├── 5.png │ │ │ │ │ ├── 6.png │ │ │ │ │ ├── 7.png │ │ │ │ │ ├── 8.png │ │ │ │ │ └── 9.png │ │ │ │ ├── caution.png │ │ │ │ ├── example.png │ │ │ │ ├── home.png │ │ │ │ ├── important.png │ │ │ │ ├── next.png │ │ │ │ ├── note.png │ │ │ │ ├── prev.png │ │ │ │ ├── tip.png │ │ │ │ ├── up.png │ │ │ │ └── warning.png │ │ │ ├── smallnew.png │ │ │ └── tiger.png │ │ └── userguide.adoc │ ├── java │ │ ├── module-info.java │ │ └── org │ │ │ └── javamoney │ │ │ └── moneta │ │ │ ├── BuildableCurrencyUnit.java │ │ │ ├── CurrencyUnitBuilder.java │ │ │ ├── DefaultMonetaryContextFactory.java │ │ │ ├── FastMoney.java │ │ │ ├── Money.java │ │ │ ├── NumberVerifier.java │ │ │ ├── OSGIServiceHelper.java │ │ │ ├── RoundedMoney.java │ │ │ ├── RoundedMoneyMonetaryOperatorFactory.java │ │ │ ├── format │ │ │ ├── AmountFormatParams.java │ │ │ ├── CurrencyStyle.java │ │ │ ├── MonetaryAmountDecimalFormat.java │ │ │ ├── MonetaryAmountDecimalFormatBuilder.java │ │ │ ├── ToStringMonetaryAmountFormat.java │ │ │ └── package-info.java │ │ │ ├── function │ │ │ ├── ConvertMinorPartQuery.java │ │ │ ├── DefaultMonetaryRoundedFactory.java │ │ │ ├── DefaultMonetarySummaryStatistics.java │ │ │ ├── ExtractorMajorPartOperator.java │ │ │ ├── ExtractorMajorPartQuery.java │ │ │ ├── ExtractorMinorPartOperator.java │ │ │ ├── ExtractorMinorPartQuery.java │ │ │ ├── FastMoneyProducer.java │ │ │ ├── GroupMonetarySummaryStatistics.java │ │ │ ├── MonetaryAmountProducer.java │ │ │ ├── MonetaryFunctions.java │ │ │ ├── MonetaryOperators.java │ │ │ ├── MonetaryQueries.java │ │ │ ├── MonetaryRoundedFactory.java │ │ │ ├── MonetaryRoundedFactoryBuilder.java │ │ │ ├── MonetarySummaryMap.java │ │ │ ├── MonetarySummaryStatistics.java │ │ │ ├── MoneyProducer.java │ │ │ ├── PercentOperator.java │ │ │ ├── PermilOperator.java │ │ │ ├── PrecisionContextRoundedOperator.java │ │ │ ├── PrecisionScaleRoundedOperator.java │ │ │ ├── ReciprocalOperator.java │ │ │ ├── RoundedMoneyProducer.java │ │ │ ├── RoundingMonetaryAmountOperator.java │ │ │ ├── ScaleRoundedOperator.java │ │ │ └── package-info.java │ │ │ ├── internal │ │ │ ├── OSGIActivator.java │ │ │ ├── OSGIServiceComparator.java │ │ │ ├── OSGIServiceProvider.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── spi │ │ │ ├── AbstractAmountFactory.java │ │ │ ├── AbstractCurrencyConversion.java │ │ │ ├── AbstractRateProvider.java │ │ │ ├── CompoundRateProvider.java │ │ │ ├── ConfigurableCurrencyUnitProvider.java │ │ │ ├── ConvertBigDecimal.java │ │ │ ├── ConvertNumberValue.java │ │ │ ├── DefaultCashRounding.java │ │ │ ├── DefaultConfigProvider.java │ │ │ ├── DefaultMonetaryAmountsSingletonQuerySpi.java │ │ │ ├── DefaultMonetaryAmountsSingletonSpi.java │ │ │ ├── DefaultMonetaryCurrenciesSingletonSpi.java │ │ │ ├── DefaultNumberValue.java │ │ │ ├── DefaultRounding.java │ │ │ ├── DefaultRoundingProvider.java │ │ │ ├── FastMoneyAmountFactory.java │ │ │ ├── FastMoneyAmountFactoryProvider.java │ │ │ ├── FastMoneyProducer.java │ │ │ ├── JDKCurrencyAdapter.java │ │ │ ├── JDKCurrencyProvider.java │ │ │ ├── LazyBoundCurrencyConversion.java │ │ │ ├── MonetaryAmountProducer.java │ │ │ ├── MonetaryConfig.java │ │ │ ├── MonetaryConfigProvider.java │ │ │ ├── MoneyAmountFactory.java │ │ │ ├── MoneyAmountFactoryProvider.java │ │ │ ├── MoneyProducer.java │ │ │ ├── MoneyUtils.java │ │ │ ├── PriorityAwareServiceProvider.java │ │ │ ├── PriorityServiceComparator.java │ │ │ ├── RoundedMoneyAmountFactory.java │ │ │ ├── RoundedMoneyAmountFactoryProvider.java │ │ │ ├── RoundedMoneyProducer.java │ │ │ ├── format │ │ │ ├── AmountNumberToken.java │ │ │ ├── CurrencyToken.java │ │ │ ├── DefaultAmountFormatProviderSpi.java │ │ │ ├── DefaultMonetaryAmountFormat.java │ │ │ ├── FormatToken.java │ │ │ ├── LiteralToken.java │ │ │ ├── ParseContext.java │ │ │ ├── StringGrouper.java │ │ │ └── package-info.java │ │ │ ├── loader │ │ │ ├── DaemonThreadFactory.java │ │ │ ├── DataStreamFactory.java │ │ │ ├── LoadDataInformation.java │ │ │ ├── LoadDataInformationBuilder.java │ │ │ ├── LoaderConfigurator.java │ │ │ ├── LoaderListener.java │ │ │ ├── LoaderService.java │ │ │ ├── ResourceCache.java │ │ │ ├── okhttp │ │ │ │ ├── HttpLoadDataService.java │ │ │ │ ├── HttpLoadLocalDataService.java │ │ │ │ ├── HttpLoadRemoteDataService.java │ │ │ │ ├── LoadableHttpResource.java │ │ │ │ ├── LoadableHttpResourceBuilder.java │ │ │ │ ├── OkHttpLoaderService.java │ │ │ │ ├── OkHttpLoaderServiceFacade.java │ │ │ │ ├── OkHttpResourceCache.java │ │ │ │ └── OkHttpScheduler.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ ├── javax.money.spi.CurrencyProviderSpi │ │ │ ├── javax.money.spi.MonetaryAmountFactoryProviderSpi │ │ │ ├── javax.money.spi.MonetaryAmountFormatProviderSpi │ │ │ ├── javax.money.spi.MonetaryAmountsSingletonQuerySpi │ │ │ ├── javax.money.spi.MonetaryAmountsSingletonSpi │ │ │ ├── javax.money.spi.MonetaryCurrenciesSingletonSpi │ │ │ ├── javax.money.spi.RoundingProviderSpi │ │ │ ├── javax.money.spi.ServiceProvider │ │ │ ├── org.javamoney.moneta.spi.MonetaryConfigProvider │ │ │ └── org.javamoney.moneta.spi.loader.LoaderService │ │ ├── javamoney.properties │ │ └── javamoney.properties~ │ └── test │ ├── java │ └── org │ │ └── javamoney │ │ └── moneta │ │ ├── BuildableCurrencyUnitTest.java │ │ ├── CurrenciesTest.java │ │ ├── CurrencyQueryTest.java │ │ ├── FastMoneyTest.java │ │ ├── InvalidCurrency.java │ │ ├── MonetaryAmountsRegistrationTest.java │ │ ├── MonetaryTest.java │ │ ├── MoneyTest.java │ │ ├── NumberVerifierTest.java │ │ ├── PerformanceTest.java │ │ ├── RoundedMoneyTest.java │ │ ├── TestCurrency.java │ │ ├── format │ │ ├── MonetaryAmountDecimalFormatBuilderTest.java │ │ ├── MonetaryAmountDecimalFormatTest.java │ │ ├── MonetaryFormatsParseBySymbolTest.java │ │ ├── MonetaryFormatsTest.java │ │ ├── ToStringMonetaryAmountFormatDefaultTest.java │ │ └── ToStringMonetaryAmountFormatSuffixTest.java │ │ ├── function │ │ ├── ConvertMinorPartQueryTest.java │ │ ├── DefaultMonetaryRoundedFactoryTest.java │ │ ├── DefaultMonetarySummaryStatisticsTest.java │ │ ├── ExtractorMajorPartOperatorTest.java │ │ ├── ExtractorMajorPartQueryTest.java │ │ ├── ExtractorMinorPartOperatorTest.java │ │ ├── ExtractorMinorPartQueryTest.java │ │ ├── FastMoneyProducerTest.java │ │ ├── GroupMonetarySummaryStatisticsTest.java │ │ ├── MonetaryFunctionsAggregatorTest.java │ │ ├── MonetaryFunctionsFilterTest.java │ │ ├── MonetaryFunctionsOrderTest.java │ │ ├── MonetaryOperatorsTest.java │ │ ├── MonetaryQueriesTest.java │ │ ├── MonetaryRoundedFactoryBuilderTest.java │ │ ├── MoneyProducerTest.java │ │ ├── PercentOperatorTest.java │ │ ├── PermilOperatorTest.java │ │ ├── PrecisionContextRoundedOperatorTest.java │ │ ├── PrecisionScaleRoundedOperatorTest.java │ │ ├── ReciprocalOperatorTest.java │ │ ├── RoundedMoneyProducerTest.java │ │ ├── RoundingMonetaryAmountOperatorTest.java │ │ ├── ScaleRoundedOperatorTest.java │ │ └── StreamFactory.java │ │ ├── internal │ │ └── JDKHelper.java │ │ └── spi │ │ ├── CompoundRateProviderTest.java │ │ ├── ConfigurableCurrencyUnitProviderTest.java │ │ ├── ConvertBigDecimalTest.java │ │ ├── ConvertNumberValueTest.java │ │ ├── CurrencyConversionTest.java │ │ ├── DefaultNumberValueTest.java │ │ ├── MonetaryConfigTest.java │ │ ├── MoneyUtilsTest.java │ │ ├── format │ │ ├── AmountNumberTokenTest.java │ │ ├── CurrencyTokenTest.java │ │ ├── DefaultMonetaryAmountFormatTest.java │ │ ├── LiteralTokenTest.java │ │ ├── MonetaryAmountFormatTest.java │ │ └── ParseContextTest.java │ │ └── loader │ │ ├── LoadDataInformationBuilderTest.java │ │ └── okhttp │ │ └── LoadableHttpResourceBuilderTest.java │ └── resources │ └── javamoney.properties ├── moneta-test ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── module-info.java │ │ └── org │ │ │ └── javamoney │ │ │ └── moneta │ │ │ └── test │ │ │ └── TestRoundingProvider.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.money.spi.RoundingProviderSpi │ └── test │ └── java │ └── org │ └── javamoney │ └── moneta │ └── test │ └── MonetaryRoundingsTest.java ├── moneta ├── .gitignore └── pom.xml ├── pom.xml ├── settings.xml └── src └── etc ├── JVM_options.txt ├── jsr354-ri clean install.launch └── jsr354-ri test.launch /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [keilw] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.run/moneta-parent [clean install].run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /moneta-convert/.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 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/.gitignore: -------------------------------------------------------------------------------- 1 | /.project 2 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/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.convert 14 | 15 | # Bundle description 16 | Bundle-Version: ${project.version}.${tstamp} 17 | Bundle-Name: JavaMoney Moneta Conversion 18 | Bundle-Activator: org.javamoney.moneta.convert.internal.OSGIActivator 19 | Bundle-SymbolicName: org.javamoney.moneta.convert 20 | Bundle-Description: JavaMoney - Moneta Reference Implementation - Conversion Base 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.convert.ExchangeRateProvider,\ 32 | javax.money.spi.MonetaryConversionsSingletonSpi 33 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, 2020, 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. -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/highlighter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/highlighter.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/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-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/1.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/10.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/11.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/12.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/13.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/14.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/15.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/2.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/3.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/4.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/5.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/6.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/7.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/8.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/callouts/9.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/caution.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/example.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/home.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/important.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/next.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/note.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/prev.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/tip.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/up.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/icons/warning.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/smallnew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/smallnew.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/asciidoc/images/tiger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaMoney/jsr354-ri/dd0e4bf3b5ff60ce6c2db384711cd01bbcbd22a3/moneta-convert/moneta-convert-base/src/main/asciidoc/images/tiger.png -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | import org.javamoney.moneta.convert.DefaultMonetaryConversionsSingletonSpi; 2 | import org.javamoney.moneta.convert.IdentityRateProvider; 3 | 4 | /* 5 | Copyright (c) 2012, 2023, Werner Keil and others by the @author tag. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | use this file except in compliance with the License. You may obtain a copy of 9 | the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | License for the specific language governing permissions and limitations under 17 | the License. 18 | */ 19 | module org.javamoney.moneta.convert { 20 | exports org.javamoney.moneta.convert; 21 | requires transitive org.javamoney.moneta; 22 | requires static osgi.core; 23 | requires static osgi.annotation; 24 | provides javax.money.spi.MonetaryConversionsSingletonSpi with DefaultMonetaryConversionsSingletonSpi; 25 | provides javax.money.convert.ExchangeRateProvider with IdentityRateProvider; 26 | uses org.javamoney.moneta.spi.MonetaryAmountProducer; 27 | uses javax.money.convert.ExchangeRateProvider; 28 | } -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/java/org/javamoney/moneta/convert/ExchangeCurrencyOperator.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.convert; 17 | 18 | import java.util.Objects; 19 | 20 | import javax.money.CurrencyUnit; 21 | import javax.money.MonetaryAmount; 22 | import javax.money.MonetaryOperator; 23 | 24 | /** 25 | * MonetaryOperator class that applies an exchange rate to an amount. 26 | */ 27 | public class ExchangeCurrencyOperator implements MonetaryOperator { 28 | /** The target currency. */ 29 | private final CurrencyUnit currency; 30 | 31 | /** 32 | * Constructor. 33 | * @param currency the target currency, not null. 34 | */ 35 | ExchangeCurrencyOperator(CurrencyUnit currency) { 36 | this.currency = Objects.requireNonNull(currency); 37 | } 38 | 39 | @Override 40 | public MonetaryAmount apply(MonetaryAmount amount) { 41 | Objects.requireNonNull(amount, "Amount required."); 42 | return amount.getFactory().setCurrency(currency).create(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/java/org/javamoney/moneta/convert/internal/OSGIActivator.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.convert.internal; 17 | 18 | import org.javamoney.moneta.OSGIServiceHelper; 19 | import org.javamoney.moneta.convert.DefaultMonetaryConversionsSingletonSpi; 20 | import org.javamoney.moneta.convert.IdentityRateProvider; 21 | import org.osgi.framework.BundleActivator; 22 | import org.osgi.framework.BundleContext; 23 | 24 | import javax.money.convert.ExchangeRateProvider; 25 | import java.util.logging.Logger; 26 | 27 | /** 28 | * A bundle activator that registers the OSGI services. 29 | */ 30 | public class OSGIActivator implements BundleActivator { 31 | 32 | private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName()); 33 | 34 | @Override 35 | public void start(BundleContext context) { 36 | LOG.config("Registering JavaMoney services..."); 37 | OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, IdentityRateProvider.class); 38 | OSGIServiceHelper.registerService(context.getBundle(), javax.money.spi.MonetaryConversionsSingletonSpi.class, DefaultMonetaryConversionsSingletonSpi.class); 39 | LOG.config("Registered JavaMoney services..."); 40 | } 41 | 42 | @Override 43 | public void stop(BundleContext context) { 44 | LOG.config("Unregistering JavaMoney services..."); 45 | OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, IdentityRateProvider.class); 46 | OSGIServiceHelper.unregisterService(context.getBundle(), javax.money.spi.MonetaryConversionsSingletonSpi.class, DefaultMonetaryConversionsSingletonSpi.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/java/org/javamoney/moneta/convert/internal/package-info.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 | /** 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.convert.internal; -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/resources/META-INF/services/javax.money.convert.ExchangeRateProvider: -------------------------------------------------------------------------------- 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.IdentityRateProvider 16 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/resources/META-INF/services/javax.money.convert.ExchangeRateProvider~: -------------------------------------------------------------------------------- 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.internal.convert.ECBCurrentRateProvider 16 | org.javamoney.moneta.internal.convert.ECBHistoricRateProvider 17 | org.javamoney.moneta.internal.convert.ECBHistoric90RateProvider 18 | org.javamoney.moneta.internal.convert.IMFRateProvider 19 | org.javamoney.moneta.internal.convert.IMFHistoricRateProvider 20 | org.javamoney.moneta.internal.convert.IdentityRateProvider -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/main/resources/META-INF/services/javax.money.spi.MonetaryConversionsSingletonSpi: -------------------------------------------------------------------------------- 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.DefaultMonetaryConversionsSingletonSpi 16 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/test/java/org/javamoney/moneta/convert/ConversionConstants.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.convert; 17 | 18 | import javax.money.CurrencyUnit; 19 | import javax.money.Monetary; 20 | 21 | class ConversionConstants { 22 | static final CurrencyUnit EURO = Monetary.getCurrency("EUR"); 23 | static final CurrencyUnit DOLLAR = Monetary.getCurrency("USD"); 24 | static final CurrencyUnit BRAZILIAN_REAL = Monetary 25 | .getCurrency("BRL"); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/test/java/org/javamoney/moneta/convert/ConversionOperatorsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012, 2015, 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.convert; 17 | 18 | import static org.testng.Assert.assertEquals; 19 | import static org.testng.Assert.assertNotNull; 20 | import javax.money.CurrencyUnit; 21 | import javax.money.Monetary; 22 | import javax.money.MonetaryAmount; 23 | 24 | import org.javamoney.moneta.Money; 25 | import org.testng.annotations.Test; 26 | 27 | /** 28 | * @author Werner 29 | * 30 | */ 31 | public class ConversionOperatorsTest { 32 | 33 | // 34 | @Test(expectedExceptions = NullPointerException.class) 35 | public void shouldReturnErrorWhenExchangeCurrencyIsNull() { 36 | ConversionOperators.exchange(null); 37 | } 38 | 39 | @Test 40 | public void shouldExchangeCurrencyPositiveValue() { 41 | CurrencyUnit real = Monetary.getCurrency("BRL"); 42 | MonetaryAmount money = Money.parse("EUR 2.35"); 43 | MonetaryAmount result = ConversionOperators.exchange(real).apply(money); 44 | assertNotNull(result); 45 | assertEquals(result.getCurrency(), real); 46 | assertEquals(2.35d, result.getNumber().doubleValue()); 47 | } 48 | 49 | @Test 50 | public void shouldExchangeCurrencyNegativeValue() { 51 | CurrencyUnit real = Monetary.getCurrency("BRL"); 52 | MonetaryAmount money = Money.parse("BHD -1.345"); 53 | MonetaryAmount result = ConversionOperators.exchange(real).apply(money); 54 | assertNotNull(result); 55 | assertEquals(result.getCurrency(), real); 56 | assertEquals(-1.345d, result.getNumber().doubleValue()); 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/test/java/org/javamoney/moneta/convert/ExchangeCurrencyOperatorTest.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.convert; 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 ExchangeCurrencyOperatorTest { 31 | 32 | private MonetaryOperator operator; 33 | 34 | private CurrencyUnit real; 35 | 36 | @BeforeMethod 37 | public void setup() { 38 | real = Monetary.getCurrency("BRL"); 39 | operator = new ExchangeCurrencyOperator(real); 40 | } 41 | 42 | @Test 43 | public void shouldReturnPositiveValue() { 44 | MonetaryAmount money = Money.parse("EUR 2.35"); 45 | MonetaryAmount result = operator.apply(money); 46 | assertEquals(result.getCurrency(), this.real); 47 | assertEquals(result.getNumber().doubleValue(), 2.35); 48 | } 49 | 50 | 51 | @Test 52 | public void shouldReturnNegativeValue() { 53 | MonetaryAmount money = Money.parse("BHD -1.345"); 54 | MonetaryAmount result = operator.apply(money); 55 | assertEquals(result.getCurrency(), real); 56 | assertEquals(result.getNumber().doubleValue(), -1.345); 57 | 58 | } 59 | 60 | @Test(expectedExceptions = NullPointerException.class) 61 | public void shouldReturnErroWhenIsNull() { 62 | operator.apply(null); 63 | fail(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/src/test/java/org/javamoney/moneta/convert/ExchangeRateProviderMock.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.convert; 17 | 18 | import javax.money.CurrencyUnit; 19 | import javax.money.convert.ConversionQuery; 20 | import javax.money.convert.CurrencyConversion; 21 | import javax.money.convert.ExchangeRate; 22 | import javax.money.convert.ExchangeRateProvider; 23 | import javax.money.convert.ProviderContext; 24 | 25 | import org.javamoney.moneta.function.MonetaryFunctions; 26 | 27 | /** 28 | * This class mock the exchange rate to test some {@link MonetaryFunctions} that 29 | * needs an exchange provider 30 | * 31 | * @author otaviojava 32 | */ 33 | class ExchangeRateProviderMock implements ExchangeRateProvider { 34 | 35 | @Override 36 | public ProviderContext getContext() { 37 | // TODO Auto-generated method stub 38 | return null; 39 | } 40 | 41 | @Override 42 | public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) { 43 | // TODO Auto-generated method stub 44 | return null; 45 | } 46 | 47 | @Override 48 | public CurrencyConversion getCurrencyConversion( 49 | ConversionQuery conversionQuery) { 50 | CurrencyUnit currencyUnit = conversionQuery.get("Query.termCurrency", 51 | CurrencyUnit.class); 52 | return new CurrencyConversionMock(currencyUnit); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/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.ecb.TestRoundingProvider 16 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-base/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-convert/moneta-convert-ecb/.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 | /target/ 13 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/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 | -testpath: \ 13 | ${junit} 14 | 15 | # JPMS 16 | Automatic-Module-Name: org.javamoney.moneta.convert.ecb 17 | 18 | # Bundle description 19 | Bundle-Version: ${project.version}.${tstamp} 20 | Bundle-Name: JavaMoney Moneta ECB Conversion 21 | Bundle-Activator: org.javamoney.moneta.convert.ecb.OSGIActivator 22 | Bundle-SymbolicName: org.javamoney.moneta.convert.ecb 23 | Bundle-Description: JavaMoney - Moneta Reference Implementation - ECB Conversion 24 | Bundle-Category: Implementation 25 | Bundle-Copyright: (C) 2012, 2018 Anatole Tresch, Werner Keil and others 26 | Bundle-License: Apache License, Version 2.0 27 | Bundle-Vendor: JavaMoney Project 28 | Bundle-DocURL: http://www.javamoney.org 29 | 30 | # Bundle capabilities and requirements 31 | Import-Package: * 32 | Export-Service: \ 33 | javax.money.convert.ExchangeRateProvider 34 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, 2020, 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. -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | import org.javamoney.moneta.spi.loader.LoaderService; 2 | 3 | /* 4 | Copyright (c) 2012, 2025, Werner Keil and others by the @author tag. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | use this file except in compliance with the License. You may obtain a copy of 8 | the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | License for the specific language governing permissions and limitations under 16 | the License. 17 | */ 18 | module org.javamoney.moneta.convert.ecb { 19 | exports org.javamoney.moneta.convert.ecb; 20 | exports org.javamoney.moneta.convert.ecb.defaults; 21 | 22 | opens org.javamoney.moneta.convert.ecb; 23 | opens org.javamoney.moneta.convert.ecb.defaults; 24 | requires java.xml; 25 | requires org.javamoney.moneta.convert; 26 | requires static osgi.core; 27 | requires static osgi.annotation; 28 | provides javax.money.convert.ExchangeRateProvider with 29 | org.javamoney.moneta.convert.ecb.ECBCurrentRateProvider, org.javamoney.moneta.convert.ecb.ECBHistoric90RateProvider, org.javamoney.moneta.convert.ecb.ECBHistoricRateProvider; 30 | uses LoaderService; 31 | uses org.javamoney.moneta.spi.MonetaryAmountProducer; 32 | } -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/OSGIActivator.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.convert.ecb; 17 | 18 | import org.javamoney.moneta.OSGIServiceHelper; 19 | import org.osgi.framework.BundleActivator; 20 | import org.osgi.framework.BundleContext; 21 | 22 | import javax.money.convert.ExchangeRateProvider; 23 | import java.util.logging.Logger; 24 | 25 | /** 26 | * A bundle activator that registers the OSGI services. 27 | */ 28 | public class OSGIActivator implements BundleActivator { 29 | 30 | private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName()); 31 | 32 | @Override 33 | public void start(BundleContext context) { 34 | LOG.config("Registering JavaMoney services..."); 35 | OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, ECBCurrentRateProvider.class); 36 | OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, ECBHistoricRateProvider.class); 37 | OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, ECBHistoric90RateProvider.class); 38 | LOG.config("Registered JavaMoney services..."); 39 | } 40 | 41 | @Override 42 | public void stop(BundleContext context) { 43 | LOG.config("Unregistering JavaMoney services..."); 44 | OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, ECBCurrentRateProvider.class); 45 | OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, ECBHistoricRateProvider.class); 46 | OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, ECBHistoric90RateProvider.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/defaults/Defaults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-2025, 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.convert.ecb.defaults; 17 | /** This class is necessary to declare the "defaults" package using just for resources, 18 | * it also serves as constant collection for default strings */ 19 | public final class Defaults { 20 | private Defaults() {} 21 | 22 | public static final String ECB_CURRENT_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; 23 | public static final String ECB_CURRENT_FALLBACK_PATH = "/org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml"; 24 | 25 | public static final String ECB_HIST90_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"; 26 | public static final String ECB_HIST90_FALLBACK_PATH = "/org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist-90d.xml"; 27 | 28 | public static final String ECB_HIST_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"; 29 | public static final String ECB_HIST_FALLBACK_PATH = "/org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist.xml"; 30 | } 31 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/java/org/javamoney/moneta/convert/ecb/package-info.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 | /** 17 | * Contains {@link javax.money.convert.ExchangeRateProvider} implementations. 18 | */ 19 | package org.javamoney.moneta.convert.ecb; -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/resources/META-INF/services/javax.money.convert.ExchangeRateProvider: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012, 2020, 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.ecb.ECBCurrentRateProvider 16 | org.javamoney.moneta.convert.ecb.ECBHistoricRateProvider 17 | org.javamoney.moneta.convert.ecb.ECBHistoric90RateProvider 18 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/resources/META-INF/services/javax.money.convert.ExchangeRateProvider~: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012, 2020, 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.internal.convert.ECBCurrentRateProvider 16 | org.javamoney.moneta.internal.convert.ECBHistoricRateProvider 17 | org.javamoney.moneta.internal.convert.ECBHistoric90RateProvider 18 | org.javamoney.moneta.internal.convert.IMFRateProvider 19 | org.javamoney.moneta.internal.convert.IMFHistoricRateProvider 20 | org.javamoney.moneta.internal.convert.IdentityRateProvider -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/resources/javamoney.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012, 2023, 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 | 18 | {-1}ecb.digit.fraction=6 19 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Reference rates 4 | 5 | European Central Bank 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/test/java/org/javamoney/moneta/convert/ecb/ConversionConstants.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.convert.ecb; 17 | 18 | import javax.money.CurrencyUnit; 19 | import javax.money.Monetary; 20 | 21 | class ConversionConstants { 22 | static final CurrencyUnit EURO = Monetary.getCurrency("EUR"); 23 | static final CurrencyUnit DOLLAR = Monetary.getCurrency("USD"); 24 | static final CurrencyUnit BRAZILIAN_REAL = Monetary 25 | .getCurrency("BRL"); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/src/test/java/org/javamoney/moneta/convert/ecb/ExchangeRateTypeTest.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.convert.ecb; 17 | 18 | import static org.testng.Assert.assertEquals; 19 | import static org.testng.Assert.assertTrue; 20 | 21 | import java.util.Objects; 22 | 23 | import javax.money.convert.ExchangeRateProvider; 24 | import javax.money.convert.MonetaryConversions; 25 | 26 | import org.javamoney.moneta.convert.ExchangeRateType; 27 | import org.javamoney.moneta.convert.ecb.ECBCurrentRateProvider; 28 | import org.javamoney.moneta.convert.ecb.ECBHistoric90RateProvider; 29 | import org.javamoney.moneta.convert.ecb.ECBHistoricRateProvider; 30 | import org.testng.annotations.Test; 31 | 32 | public class ExchangeRateTypeTest { 33 | 34 | @Test 35 | public void shouldReturnsECBCurrentRateProvider() { 36 | ExchangeRateProvider prov = MonetaryConversions 37 | .getExchangeRateProvider(ExchangeRateType.ECB); 38 | assertTrue(Objects.nonNull(prov)); 39 | assertEquals(ECBCurrentRateProvider.class, prov.getClass()); 40 | } 41 | 42 | @Test 43 | public void shouldReturnsECBHistoricRateProvider() { 44 | ExchangeRateProvider prov = MonetaryConversions 45 | .getExchangeRateProvider(ExchangeRateType.ECB_HIST); 46 | assertTrue(Objects.nonNull(prov)); 47 | assertEquals(ECBHistoricRateProvider.class, prov.getClass()); 48 | } 49 | 50 | @Test 51 | public void shouldReturnsECBHistoric90RateProvider() { 52 | ExchangeRateProvider prov = MonetaryConversions 53 | .getExchangeRateProvider(ExchangeRateType.ECB_HIST90); 54 | assertTrue(Objects.nonNull(prov)); 55 | assertEquals(ECBHistoric90RateProvider.class, prov.getClass()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/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.ecb.TestRoundingProvider 16 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/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 | {1}theWinner3=theWinner2 19 | myTestValue=myTestValue -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-ecb/update_ecb.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | printf "\n Downloading the ECB daily resource. \n" 3 | # wget https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml 4 | #mv eurofxref-daily.xml src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml 5 | curl --fail "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml" \ 6 | --output src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-daily.xml 7 | printf "\n Done. Downloading the ECB-90 resource. \n" 8 | # wget https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml 9 | # mv eurofxref-hist-90d.xml src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist-90d.xml 10 | curl --fail "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml" \ 11 | --output src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist-90d.xml 12 | printf "\n Done. Downloading the ECB-hist resource. \n" 13 | wget https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml 14 | mv eurofxref-hist.xml src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist.xml 15 | # curl --fail "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml" \ 16 | # --output src/main/resources/org/javamoney/moneta/convert/ecb/defaults/eurofxref-hist.xml 17 | printf "\n Done." -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/.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 | /target/ 13 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/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.convert.imf 14 | 15 | # Bundle description 16 | Bundle-Version: ${project.version}.${tstamp} 17 | Bundle-Name: JavaMoney Moneta IMF Conversion 18 | Bundle-Activator: org.javamoney.moneta.convert.imf.OSGIActivator 19 | Bundle-SymbolicName: org.javamoney.moneta.convert.imf 20 | Bundle-Description: JavaMoney - Moneta Reference Implementation - IMF Conversion 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-Service: \ 30 | javax.money.convert.ExchangeRateProvider 31 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/etc/download.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eu 3 | yearmonths="$@" 4 | first=true 5 | for yearmonth in $yearmonths 6 | do 7 | $first || sleep 2 8 | first=false 9 | date=$(date --date="$yearmonth-01 +1 month -1 day" +%Y-%m-%d) 10 | curl --fail "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=${date}&reportType=CVSDR&tsvflag=Y" \ 11 | --output ../../target/$yearmonth.tsv \ 12 | || break 13 | done 14 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, 2020, 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. -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | import org.javamoney.moneta.spi.loader.LoaderService; 2 | 3 | /* 4 | Copyright (c) 2012, 2025, Werner Keil and others by the @author tag. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | use this file except in compliance with the License. You may obtain a copy of 8 | the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | License for the specific language governing permissions and limitations under 16 | the License. 17 | */ 18 | module org.javamoney.moneta.convert.imf { 19 | exports org.javamoney.moneta.convert.imf; 20 | exports org.javamoney.moneta.convert.imf.defaults; 21 | 22 | opens org.javamoney.moneta.convert.imf; 23 | opens org.javamoney.moneta.convert.imf.defaults; 24 | requires org.javamoney.moneta.convert; 25 | requires static osgi.core; 26 | requires static osgi.annotation; 27 | requires okhttp3; 28 | provides javax.money.convert.ExchangeRateProvider with 29 | org.javamoney.moneta.convert.imf.IMFRateProvider, org.javamoney.moneta.convert.imf.IMFHistoricRateProvider; 30 | uses LoaderService; 31 | uses org.javamoney.moneta.spi.MonetaryAmountProducer; 32 | } -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/IMFHistoricalType.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.convert.imf; 17 | 18 | import java.time.YearMonth; 19 | import java.util.Objects; 20 | 21 | import static org.javamoney.moneta.convert.imf.defaults.Defaults.*; 22 | 23 | enum IMFHistoricalType { 24 | SDR_Currency(SCRCV), Currency_SDR(CVSDR); 25 | 26 | private final String type; 27 | 28 | IMFHistoricalType(String type) { 29 | this.type = type; 30 | } 31 | 32 | public String getType() { 33 | return type; 34 | } 35 | 36 | public String getUrl(YearMonth yearMonth) { 37 | return String.format(HOST, Objects.requireNonNull(yearMonth), type); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/OSGIActivator.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.convert.imf; 17 | 18 | import org.javamoney.moneta.OSGIServiceHelper; 19 | import org.osgi.framework.BundleActivator; 20 | import org.osgi.framework.BundleContext; 21 | 22 | import javax.money.convert.ExchangeRateProvider; 23 | import java.util.logging.Logger; 24 | 25 | /** 26 | * A bundle activator that registers the OSGI services. 27 | */ 28 | public class OSGIActivator implements BundleActivator { 29 | 30 | private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName()); 31 | 32 | @Override 33 | public void start(BundleContext context) { 34 | LOG.config("Registering JavaMoney services..."); 35 | OSGIServiceHelper.registerService(context.getBundle(), ExchangeRateProvider.class, IMFRateProvider.class); 36 | LOG.config("Registered JavaMoney services..."); 37 | } 38 | 39 | @Override 40 | public void stop(BundleContext context) { 41 | LOG.config("Unregistering JavaMoney services..."); 42 | OSGIServiceHelper.unregisterService(context.getBundle(), ExchangeRateProvider.class, IMFRateProvider.class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/defaults/Defaults.java: -------------------------------------------------------------------------------- 1 | package org.javamoney.moneta.convert.imf.defaults; 2 | /** This class is necessary to declare the "defaults" package using just for resources */ 3 | public final class Defaults { 4 | private Defaults() {} 5 | 6 | public static final String HOST = "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=%s&reportType=%s&tsvflag=Y"; 7 | 8 | public static final String CVSDR = "CVSDR"; 9 | 10 | public static final String SCRCV = "SDRCV"; 11 | } 12 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/java/org/javamoney/moneta/convert/imf/package-info.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 | /** 17 | * Contains {@link javax.money.convert.ExchangeRateProvider} implementations. 18 | */ 19 | package org.javamoney.moneta.convert.imf; -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/resources/META-INF/services/javax.money.convert.ExchangeRateProvider: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012, 2020, 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.IMFRateProvider 16 | org.javamoney.moneta.convert.imf.IMFHistoricRateProvider 17 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/main/resources/javamoney.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012, 2023, 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 | 18 | # IMF Rates 19 | {-1}load.IMFRateProvider.type=SCHEDULED 20 | {-1}load.IMFRateProvider.period=06:00 21 | #{-1}load.IMFRateProvider.delay=12:00 22 | #{-1}load.IMFRateProvider.at=12:00 23 | {-1}load.IMFRateProvider.resource=org/javamoney/moneta/convert/imf/defaults/rms_five.tsv 24 | {-1}load.IMFRateProvider.urls=https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y 25 | {-1}load.IMFRateProvider.startRemote=false 26 | {-1}load.IMFRateProvider.useragent=Chrome/51.0.2704.103 27 | {-1}load.IMFRateProvider.connection.read.timeout=40 28 | {-1}load.IMFRateProvider.connection.connect.timeout=40 29 | 30 | {-1}load.IMFHistoricRateProvider.type=LAZY 31 | {-1}load.IMFHistoricRateProvider.resource=org/javamoney/moneta/convert/imf/defaults/rms_five.tsv 32 | {-1}load.IMFHistoricRateProvider.urls=https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y 33 | {-1}load.IMFHistoricRateProvider.startRemote=false 34 | {-1}load.IMFHistoricRateProvider.useragent=Chrome/51.0.2704.103 35 | {-1}load.IMFHistoricRateProvider.connection.read.timeout=40 36 | {-1}load.IMFHistoricRateProvider.connection.connect.timeout=40 37 | 38 | {-1}imf.digit.fraction=6 39 | 40 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/test/java/org/javamoney/moneta/convert/imf/ConversionConstants.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.convert.imf; 17 | 18 | import javax.money.CurrencyUnit; 19 | import javax.money.Monetary; 20 | 21 | class ConversionConstants { 22 | static final CurrencyUnit EURO = Monetary.getCurrency("EUR"); 23 | static final CurrencyUnit DOLLAR = Monetary.getCurrency("USD"); 24 | static final CurrencyUnit BRAZILIAN_REAL = Monetary 25 | .getCurrency("BRL"); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/test/java/org/javamoney/moneta/convert/imf/ExchangeRateTypeTest.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.convert.imf; 17 | 18 | import org.javamoney.moneta.convert.ExchangeRateType; 19 | import org.testng.annotations.Test; 20 | 21 | import javax.money.convert.ExchangeRateProvider; 22 | import javax.money.convert.MonetaryConversions; 23 | import java.util.Objects; 24 | 25 | import static org.testng.Assert.assertEquals; 26 | import static org.testng.Assert.assertTrue; 27 | 28 | public class ExchangeRateTypeTest { 29 | 30 | @Test 31 | public void shouldReturnsIMFRateProvider() { 32 | ExchangeRateProvider prov = MonetaryConversions 33 | .getExchangeRateProvider(ExchangeRateType.IMF); 34 | assertTrue(Objects.nonNull(prov)); 35 | assertEquals(IMFRateProvider.class, prov.getClass()); 36 | } 37 | 38 | @Test 39 | public void shouldReturnsIMFHistoricRateProvider() { 40 | ExchangeRateProvider prov = MonetaryConversions 41 | .getExchangeRateProvider(ExchangeRateType.IMF_HIST); 42 | assertTrue(Objects.nonNull(prov)); 43 | assertEquals(IMFHistoricRateProvider.class, prov.getClass()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/test/java/org/javamoney/moneta/convert/imf/IMFHistoricalTypeTest.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.convert.imf; 17 | 18 | import static org.testng.Assert.assertEquals; 19 | import static org.testng.Assert.assertNotNull; 20 | 21 | import java.time.Month; 22 | import java.time.YearMonth; 23 | 24 | import org.testng.annotations.Test; 25 | 26 | public class IMFHistoricalTypeTest { 27 | 28 | @Test 29 | public void shouldReturnSDRCurrencyType() { 30 | String result = IMFHistoricalType.SDR_Currency.getType(); 31 | assertEquals(result, "SDRCV"); 32 | } 33 | 34 | @Test 35 | public void shouldReturnCurrencySDR() { 36 | String result = IMFHistoricalType.Currency_SDR.getType(); 37 | assertEquals(result, "CVSDR"); 38 | } 39 | 40 | @Test(expectedExceptions = NullPointerException.class) 41 | public void shouldReturnErrorWhenYearMonthIsNull() { 42 | IMFHistoricalType.Currency_SDR.getUrl(null); 43 | } 44 | 45 | @Test 46 | public void shouldReturnUrlSDRCurrency() { 47 | YearMonth yearMonth = YearMonth.of(2015, Month.APRIL); 48 | String url = IMFHistoricalType.Currency_SDR.getUrl(yearMonth); 49 | assertNotNull(url); 50 | assertEquals(url, "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=2015-04&reportType=CVSDR&tsvflag=Y"); 51 | } 52 | 53 | @Test 54 | public void shouldReturnUrlCurrencySDR() { 55 | YearMonth yearMonth = YearMonth.of(2015, Month.APRIL); 56 | String url = IMFHistoricalType.SDR_Currency.getUrl(yearMonth); 57 | assertNotNull(url); 58 | assertEquals(url, "https://www.imf.org/external/np/fin/data/rms_mth.aspx?SelectDate=2015-04&reportType=SDRCV&tsvflag=Y"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /moneta-convert/moneta-convert-imf/src/test/java/org/javamoney/moneta/convert/imf/IMFRemoteSearchTest.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.convert.imf; 17 | 18 | import static org.testng.Assert.assertNotNull; 19 | 20 | import java.io.InputStream; 21 | import java.time.Month; 22 | import java.time.YearMonth; 23 | import java.util.Map; 24 | 25 | import org.testng.annotations.Test; 26 | 27 | public class IMFRemoteSearchTest { 28 | 29 | @Test(expectedExceptions = NullPointerException.class) 30 | public void shouldReturnErrorWhenYearMonthIsNull(){ 31 | IMFRemoteSearch.INSTANCE.getResources(null, null); 32 | } 33 | 34 | @Test 35 | public void shouldReturnStream(){ 36 | Map 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 | --------------------------------------------------------------------------------