diff --git a/src/main/java/javax/money/AbstractContext.java b/src/main/java/javax/money/AbstractContext.java index 9af5f23a..f57e676a 100644 --- a/src/main/java/javax/money/AbstractContext.java +++ b/src/main/java/javax/money/AbstractContext.java @@ -465,12 +465,7 @@ public boolean equals(Object obj){ public String toString(){ StringBuilder attrsBuilder = new StringBuilder(); for(Map.Entry,Map> en : this.data.entrySet()){ - Map sortedMap = new TreeMap<>(new Comparator(){ - @Override - public int compare(Object o1, Object o2){ - return o1.toString().compareTo(o2.toString()); - } - }); + Map sortedMap = new TreeMap<>((o1, o2) -> o1.toString().compareTo(o2.toString())); sortedMap.putAll(en.getValue()); for(Map.Entry entry : sortedMap.entrySet()){ Object key = entry.getKey(); diff --git a/src/main/java/javax/money/CurrencyUnit.java b/src/main/java/javax/money/CurrencyUnit.java index 1e6b162a..77ab64ed 100644 --- a/src/main/java/javax/money/CurrencyUnit.java +++ b/src/main/java/javax/money/CurrencyUnit.java @@ -57,7 +57,7 @@ public interface CurrencyUnit extends Comparable{ * about the formatting of alternate codes, despite the fact that * the currency codes must be unique. */ - public String getCurrencyCode(); + String getCurrencyCode(); /** * Gets a numeric currency code. within the ISO-4217 name space, this equals @@ -71,7 +71,7 @@ public interface CurrencyUnit extends Comparable{ * * @return the numeric currency code */ - public int getNumericCode(); + int getNumericCode(); /** * Gets the number of fractional digits typically used by this currency. @@ -87,7 +87,7 @@ public interface CurrencyUnit extends Comparable{ * pseudo-currencies. * */ - public int getDefaultFractionDigits(); + int getDefaultFractionDigits(); /** @@ -95,6 +95,6 @@ public interface CurrencyUnit extends Comparable{ * on the type and capabilities of a CurrencyUnit, e.g. its provider and more. * @return the currency's context, never null. */ - public CurrencyContext getCurrencyContext(); + CurrencyContext getCurrencyContext(); } diff --git a/src/main/java/javax/money/MonetaryAmount.java b/src/main/java/javax/money/MonetaryAmount.java index 195e93b6..c77e3c0d 100644 --- a/src/main/java/javax/money/MonetaryAmount.java +++ b/src/main/java/javax/money/MonetaryAmount.java @@ -100,7 +100,7 @@ public interface MonetaryAmount extends CurrencySupplier, NumberSupplier, Compar * * @return the currency, never {@code null} */ - public CurrencyUnit getCurrency(); + CurrencyUnit getCurrency(); /** * Returns the {@link MonetaryContext} of this {@code MonetaryAmount}. The @@ -111,7 +111,7 @@ public interface MonetaryAmount extends CurrencySupplier, NumberSupplier, Compar * * @return the {@link MonetaryContext} of this {@code MonetaryAmount}, never {@code null} . */ - public MonetaryContext getMonetaryContext(); + MonetaryContext getMonetaryContext(); /** * Simple accessor for the numeric part of a {@link MonetaryAmount}. The representation type @@ -121,7 +121,7 @@ public interface MonetaryAmount extends CurrencySupplier, NumberSupplier, Compar * * @return the numeric value of this {@link MonetaryAmount}, never {@code null}. */ - public NumberValue getNumber(); + NumberValue getNumber(); /** * Queries this monetary amount for a value. @@ -192,7 +192,7 @@ default R query(MonetaryQuery query){ * the operator to use, not null * @return an object of the same type with the specified conversion made, not null */ - public default MonetaryAmount with(MonetaryOperator operator){ + default MonetaryAmount with(MonetaryOperator operator){ return operator.apply(this); } @@ -207,7 +207,7 @@ public default MonetaryAmount with(MonetaryOperator operator){ * @return the new {@code MonetaryAmountFactory} with the given {@link MonetaryAmount} as its * default values. */ - public MonetaryAmountFactory getFactory(); + MonetaryAmountFactory getFactory(); /** * Compares two instances of {@link MonetaryAmount}, hereby ignoring non significant trailing @@ -219,7 +219,7 @@ public default MonetaryAmount with(MonetaryOperator operator){ * @throws MonetaryException * if the amount's currency is not equals to the currency of this instance. */ - public boolean isGreaterThan(MonetaryAmount amount); + boolean isGreaterThan(MonetaryAmount amount); /** * Compares two instances of {@link MonetaryAmount}, hereby ignoring non significant trailing @@ -231,7 +231,7 @@ public default MonetaryAmount with(MonetaryOperator operator){ * @throws MonetaryException * if the amount's currency is not equals to the currency of this instance. */ - public boolean isGreaterThanOrEqualTo(MonetaryAmount amount); + boolean isGreaterThanOrEqualTo(MonetaryAmount amount); /** * Compares two instances of {@link MonetaryAmount}, hereby ignoring non significant trailing @@ -243,7 +243,7 @@ public default MonetaryAmount with(MonetaryOperator operator){ * @throws MonetaryException * if the amount's currency is not equals to the currency of this instance. */ - public boolean isLessThan(MonetaryAmount amount); + boolean isLessThan(MonetaryAmount amount); /** * Compares two instances of {@link MonetaryAmount}, hereby ignoring non significant trailing @@ -255,7 +255,7 @@ public default MonetaryAmount with(MonetaryOperator operator){ * @throws MonetaryException * if the amount's currency is not equals to the currency of this instance. */ - public boolean isLessThanOrEqualTo(MonetaryAmount amt); + boolean isLessThanOrEqualTo(MonetaryAmount amt); /** * Compares two instances of {@link MonetaryAmount}, hereby ignoring non significant trailing @@ -267,14 +267,14 @@ public default MonetaryAmount with(MonetaryOperator operator){ * @throws MonetaryException * if the amount's currency is not equals to the currency of this instance. */ - public boolean isEqualTo(MonetaryAmount amount); + boolean isEqualTo(MonetaryAmount amount); /** * Checks if a {@code MonetaryAmount} is negative. * * @return {@code true} if {@link #signum()} < 0. */ - public default boolean isNegative(){ + default boolean isNegative(){ return signum() < 0; } @@ -283,7 +283,7 @@ public default boolean isNegative(){ * * @return {@code true} if {@link #signum()} <= 0. */ - public default boolean isNegativeOrZero(){ + default boolean isNegativeOrZero(){ return signum() <= 0; } @@ -292,7 +292,7 @@ public default boolean isNegativeOrZero(){ * * @return {@code true} if {@link #signum()} > 0. */ - public default boolean isPositive(){ + default boolean isPositive(){ return signum() > 0; } @@ -301,7 +301,7 @@ public default boolean isPositive(){ * * @return {@code true} if {@link #signum()} >= 0. */ - public default boolean isPositiveOrZero(){ + default boolean isPositiveOrZero(){ return signum() >= 0; } @@ -310,7 +310,7 @@ public default boolean isPositiveOrZero(){ * * @return {@code true} if {@link #signum()} == 0. */ - public default boolean isZero(){ + default boolean isZero(){ return signum() == 0; } @@ -320,7 +320,7 @@ public default boolean isZero(){ * @return -1, 0, or 1 as the value of this {@code MonetaryAmount} is negative, zero, or * positive. */ - public int signum(); + int signum(); /** * Returns a {@code MonetaryAmount} whose value is {@code (this + @@ -334,7 +334,7 @@ public default boolean isZero(){ * if the result exceeds the numeric capabilities of this implementation class, i.e. * the {@link MonetaryContext} cannot be adapted as required. */ - public MonetaryAmount add(MonetaryAmount amount); + MonetaryAmount add(MonetaryAmount amount); /** * Returns a {@code MonetaryAmount} whose value is {@code (this - @@ -348,7 +348,7 @@ public default boolean isZero(){ * if the result exceeds the numeric capabilities of this implementation class, i.e. * the {@link MonetaryContext} cannot be adapted as required. */ - public MonetaryAmount subtract(MonetaryAmount amount); + MonetaryAmount subtract(MonetaryAmount amount); /** * Returns a {@code MonetaryAmount} whose value is (this × @@ -362,7 +362,7 @@ public default boolean isZero(){ * if the result exceeds the numeric capabilities of this implementation class, i.e. * the {@link MonetaryContext} cannot be adapted as required. */ - public MonetaryAmount multiply(long multiplicand); + MonetaryAmount multiply(long multiplicand); /** * Returns a {@code MonetaryAmount} whose value is (this × @@ -376,7 +376,7 @@ public default boolean isZero(){ * if the result exceeds the numeric capabilities of this implementation class, i.e. * the {@link MonetaryContext} cannot be adapted as required. */ - public MonetaryAmount multiply(double multiplicand); + MonetaryAmount multiply(double multiplicand); /** * Returns a {@code MonetaryAmount} whose value is (this × @@ -390,7 +390,7 @@ public default boolean isZero(){ * if the result exceeds the numeric capabilities of this implementation class, i.e. * the {@link MonetaryContext} cannot be adapted as required. */ - public MonetaryAmount multiply(Number multiplicand); + MonetaryAmount multiply(Number multiplicand); /** * Returns a {@code MonetaryAmount} whose value is {@code (this / @@ -406,7 +406,7 @@ public default boolean isZero(){ * {@link MonetaryContext} cannot be adapted as required. * @return {@code this / divisor} */ - public MonetaryAmount divide(long divisor); + MonetaryAmount divide(long divisor); /** * Returns a {@code MonetaryAmount} whose value is {@code (this / @@ -422,7 +422,7 @@ public default boolean isZero(){ * {@link MonetaryContext} cannot be adapted as required. * @return {@code this / divisor} */ - public MonetaryAmount divide(double divisor); + MonetaryAmount divide(double divisor); /** * Returns a {@code MonetaryAmount} whose value is {@code (this / @@ -438,7 +438,7 @@ public default boolean isZero(){ * {@link MonetaryContext} cannot be adapted as required. * @return {@code this / divisor} */ - public MonetaryAmount divide(Number divisor); + MonetaryAmount divide(Number divisor); /** * Returns a {@code MonetaryAmount} whose value is {@code (this % divisor)}. @@ -456,7 +456,7 @@ public default boolean isZero(){ * implementation class, i.e. the {@link MonetaryContext} cannot be adapted as * required. */ - public MonetaryAmount remainder(long divisor); + MonetaryAmount remainder(long divisor); /** * Returns a {@code MonetaryAmount} whose value is {@code (this % divisor)}. @@ -474,7 +474,7 @@ public default boolean isZero(){ * implementation class, i.e. the {@link MonetaryContext} cannot be adapted as * required. */ - public MonetaryAmount remainder(double divisor); + MonetaryAmount remainder(double divisor); /** * Returns a {@code MonetaryAmount} whose value is {@code (this % divisor)}. @@ -492,7 +492,7 @@ public default boolean isZero(){ * implementation class, i.e. the {@link MonetaryContext} cannot be adapted as * required. */ - public MonetaryAmount remainder(Number divisor); + MonetaryAmount remainder(Number divisor); /** * Returns a two-element {@code MonetaryAmount} array containing the result of @@ -517,7 +517,7 @@ public default boolean isZero(){ * @see #divideToIntegralValue(long) * @see #remainder(long) */ - public MonetaryAmount[] divideAndRemainder(long divisor); + MonetaryAmount[] divideAndRemainder(long divisor); /** * Returns a two-element {@code MonetaryAmount} array containing the result of @@ -542,7 +542,7 @@ public default boolean isZero(){ * @see #divideToIntegralValue(double) * @see #remainder(double) */ - public MonetaryAmount[] divideAndRemainder(double divisor); + MonetaryAmount[] divideAndRemainder(double divisor); /** * Returns a two-element {@code MonetaryAmount} array containing the result of @@ -567,7 +567,7 @@ public default boolean isZero(){ * @see #divideToIntegralValue(Number) * @see #remainder(Number) */ - public MonetaryAmount[] divideAndRemainder(Number divisor); + MonetaryAmount[] divideAndRemainder(Number divisor); /** * Returns a {@code MonetaryAmount} whose value is the integer part of the quotient @@ -582,7 +582,7 @@ public default boolean isZero(){ * if {@code divisor==0} * @see java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal) */ - public MonetaryAmount divideToIntegralValue(long divisor); + MonetaryAmount divideToIntegralValue(long divisor); /** * Returns a {@code MonetaryAmount} whose value is the integer part of the quotient @@ -597,7 +597,7 @@ public default boolean isZero(){ * if {@code divisor==0} * @see java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal) */ - public MonetaryAmount divideToIntegralValue(double divisor); + MonetaryAmount divideToIntegralValue(double divisor); /** * Returns a {@code MonetaryAmount} whose value is the integer part of the quotient @@ -612,7 +612,7 @@ public default boolean isZero(){ * if {@code divisor==0} * @see java.math.BigDecimal#divideToIntegralValue(java.math.BigDecimal) */ - public MonetaryAmount divideToIntegralValue(Number divisor); + MonetaryAmount divideToIntegralValue(Number divisor); /** * Returns a {@code MonetaryAmount} whose numerical value is equal to ( {@code this} * @@ -626,7 +626,7 @@ public default boolean isZero(){ * exceeds the numeric capabilities of this implementation class, i.e. the * {@link MonetaryContext} cannot be adapted as required. */ - public MonetaryAmount scaleByPowerOfTen(int power); + MonetaryAmount scaleByPowerOfTen(int power); /** * Returns a {@code MonetaryAmount} whose value is the absolute value of this @@ -634,7 +634,7 @@ public default boolean isZero(){ * * @return {@code abs(this)} */ - public MonetaryAmount abs(); + MonetaryAmount abs(); /** * Returns a {@code MonetaryAmount} whose value is {@code (-this)}, and whose scale is @@ -642,7 +642,7 @@ public default boolean isZero(){ * * @return {@code -this}. */ - public MonetaryAmount negate(); + MonetaryAmount negate(); /** * Returns a {@code MonetaryAmount} whose value is {@code (+this)}, with rounding according to @@ -654,7 +654,7 @@ public default boolean isZero(){ * @throws ArithmeticException * if rounding fails. */ - public MonetaryAmount plus(); + MonetaryAmount plus(); /** * Returns a {@code MonetaryAmount} which is numerically equal to this one but with any trailing @@ -665,6 +665,6 @@ public default boolean isZero(){ * * @return a numerically equal {@code MonetaryAmount} with any trailing zeros removed. */ - public MonetaryAmount stripTrailingZeros(); + MonetaryAmount stripTrailingZeros(); } diff --git a/src/main/java/javax/money/MonetaryAmounts.java b/src/main/java/javax/money/MonetaryAmounts.java index 97df6346..4c9257ae 100644 --- a/src/main/java/javax/money/MonetaryAmounts.java +++ b/src/main/java/javax/money/MonetaryAmounts.java @@ -13,7 +13,6 @@ import javax.money.spi.MonetaryAmountsSingletonSpi; import java.util.Collection; import java.util.Optional; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/main/java/javax/money/MonetaryQuery.java b/src/main/java/javax/money/MonetaryQuery.java index 9675c2e9..5222d7b9 100644 --- a/src/main/java/javax/money/MonetaryQuery.java +++ b/src/main/java/javax/money/MonetaryQuery.java @@ -85,6 +85,6 @@ public interface MonetaryQuery{ * @throws ArithmeticException * if numeric overflow occurs */ - public R queryFrom(MonetaryAmount amount); + R queryFrom(MonetaryAmount amount); } \ No newline at end of file diff --git a/src/main/java/javax/money/MonetaryRoundings.java b/src/main/java/javax/money/MonetaryRoundings.java index 9a61500f..f8b94dde 100644 --- a/src/main/java/javax/money/MonetaryRoundings.java +++ b/src/main/java/javax/money/MonetaryRoundings.java @@ -305,20 +305,17 @@ public Collection getRoundings(RoundingQuery query){ providerNames = getDefaultProviderChain(); } for(String providerName : providerNames){ - for(RoundingProviderSpi prov : Bootstrap.getServices(RoundingProviderSpi.class)){ - if(providerName.equals(prov.getProviderName())){ - try{ - MonetaryRounding r = prov.getRounding(query); - if(r!=null){ - result.add(r); - } - } - catch(Exception e){ - Logger.getLogger(DefaultMonetaryRoundingsSingletonSpi.class.getName()) - .log(Level.SEVERE, "Error loading RoundingProviderSpi from provider: " + prov, e); + Bootstrap.getServices(RoundingProviderSpi.class).stream().filter(prov -> providerName.equals(prov.getProviderName())).forEach(prov -> { + try { + MonetaryRounding r = prov.getRounding(query); + if (r != null) { + result.add(r); } + } catch (Exception e) { + Logger.getLogger(DefaultMonetaryRoundingsSingletonSpi.class.getName()) + .log(Level.SEVERE, "Error loading RoundingProviderSpi from provider: " + prov, e); } - } + }); } return result; } diff --git a/src/main/java/javax/money/convert/ConversionContext.java b/src/main/java/javax/money/convert/ConversionContext.java index 9b705d8d..5b0d404c 100644 --- a/src/main/java/javax/money/convert/ConversionContext.java +++ b/src/main/java/javax/money/convert/ConversionContext.java @@ -9,10 +9,6 @@ package javax.money.convert; import javax.money.AbstractContext; -import java.time.Instant; -import java.time.temporal.ChronoField; -import java.time.temporal.TemporalAccessor; -import java.util.Objects; /** * This class models a context for which a {@link ExchangeRate} is valid. It allows to define diff --git a/src/main/java/javax/money/convert/ConversionQuery.java b/src/main/java/javax/money/convert/ConversionQuery.java index 8df804bf..117c9f1b 100644 --- a/src/main/java/javax/money/convert/ConversionQuery.java +++ b/src/main/java/javax/money/convert/ConversionQuery.java @@ -7,12 +7,8 @@ */ package javax.money.convert; -import javax.money.AbstractContext; import javax.money.AbstractQuery; import javax.money.CurrencyUnit; -import java.time.Instant; -import java.time.temporal.ChronoField; -import java.time.temporal.TemporalAccessor; import java.util.*; /** diff --git a/src/main/java/javax/money/convert/ConversionQueryBuilder.java b/src/main/java/javax/money/convert/ConversionQueryBuilder.java index 028a3b16..7c3b8e77 100644 --- a/src/main/java/javax/money/convert/ConversionQueryBuilder.java +++ b/src/main/java/javax/money/convert/ConversionQueryBuilder.java @@ -8,14 +8,11 @@ */ package javax.money.convert; -import javax.money.AbstractContextBuilder; import javax.money.AbstractQueryBuilder; import javax.money.CurrencyUnit; import javax.money.MonetaryCurrencies; -import java.time.temporal.TemporalUnit; import java.util.Arrays; import java.util.HashSet; -import java.util.List; import java.util.Set; /** diff --git a/src/main/java/javax/money/convert/CurrencyConversion.java b/src/main/java/javax/money/convert/CurrencyConversion.java index 0a1db072..c2eff096 100644 --- a/src/main/java/javax/money/convert/CurrencyConversion.java +++ b/src/main/java/javax/money/convert/CurrencyConversion.java @@ -44,14 +44,14 @@ public interface CurrencyConversion extends MonetaryOperator { * * @return the terminating {@link CurrencyUnit} , never {@code null}. */ - public CurrencyUnit getTermCurrency(); + CurrencyUnit getTermCurrency(); /** * Access the target {@link ConversionContext} of this conversion instance. * * @return the target {@link ConversionContext}. */ - public ConversionContext getConversionContext(); + ConversionContext getConversionContext(); /** * Get the {@link ExchangeRate} applied for the given {@link MonetaryAmount} @@ -63,6 +63,6 @@ public interface CurrencyConversion extends MonetaryOperator { * @throws MonetaryException * if the amount can not be converted. */ - public ExchangeRate getExchangeRate(MonetaryAmount sourceAmount); + ExchangeRate getExchangeRate(MonetaryAmount sourceAmount); } diff --git a/src/main/java/javax/money/convert/ExchangeRateProvider.java b/src/main/java/javax/money/convert/ExchangeRateProvider.java index c381e46b..7f93866a 100644 --- a/src/main/java/javax/money/convert/ExchangeRateProvider.java +++ b/src/main/java/javax/money/convert/ExchangeRateProvider.java @@ -87,10 +87,7 @@ public interface ExchangeRateProvider{ default boolean isAvailable(ConversionQuery conversionQuery){ Objects.requireNonNull(conversionQuery); try{ - if(!conversionQuery.getProviders().isEmpty()){ - return conversionQuery.getProviders().contains(getProviderContext().getProvider()); - } - return true; + return conversionQuery.getProviders().isEmpty() || conversionQuery.getProviders().contains(getProviderContext().getProvider()); } catch(Exception e){ return false; diff --git a/src/main/java/javax/money/spi/MonetaryAmountFactoryProviderSpi.java b/src/main/java/javax/money/spi/MonetaryAmountFactoryProviderSpi.java index aee2fe3c..dc8de03f 100644 --- a/src/main/java/javax/money/spi/MonetaryAmountFactoryProviderSpi.java +++ b/src/main/java/javax/money/spi/MonetaryAmountFactoryProviderSpi.java @@ -29,7 +29,7 @@ public interface MonetaryAmountFactoryProviderSpi { * * @see MonetaryAmounts#getAmountFactory(javax.money.MonetaryAmountFactoryQuery) */ - public static enum QueryInclusionPolicy { + enum QueryInclusionPolicy { /** * Always include this factory (and the corresponding amount type) within queries. This is * the default for normal {@link MonetaryAmount} implementation types. diff --git a/src/main/java/javax/money/spi/MonetaryConversionsSingletonSpi.java b/src/main/java/javax/money/spi/MonetaryConversionsSingletonSpi.java index a445176c..645ccfaf 100644 --- a/src/main/java/javax/money/spi/MonetaryConversionsSingletonSpi.java +++ b/src/main/java/javax/money/spi/MonetaryConversionsSingletonSpi.java @@ -14,7 +14,6 @@ import javax.money.CurrencyUnit; import javax.money.MonetaryException; import javax.money.convert.*; -import javax.money.convert.ConversionQueryBuilder; /** * SPI (conversoin) that implements the functionalities provided by the diff --git a/src/main/java/javax/money/spi/ServiceProvider.java b/src/main/java/javax/money/spi/ServiceProvider.java index ed201d8a..650f9e7d 100644 --- a/src/main/java/javax/money/spi/ServiceProvider.java +++ b/src/main/java/javax/money/spi/ServiceProvider.java @@ -32,7 +32,7 @@ public interface ServiceProvider { * @return The instance to be used, never {@code null} */ @SuppressWarnings("unchecked") - public default List getServices(Class serviceType){ + default List getServices(Class serviceType){ return getServices(serviceType, Collections.emptyList()); } @@ -47,7 +47,7 @@ public default List getServices(Class serviceType){ * the lis returned, if no services could be found. * @return The instance to be used, never {@code null} */ - public List getServices(Class serviceType, - List defaultList); + List getServices(Class serviceType, + List defaultList); } \ No newline at end of file diff --git a/src/test/java/javax/money/MonetaryCurrenciesTest.java b/src/test/java/javax/money/MonetaryCurrenciesTest.java index 3eedb51c..88f1865a 100644 --- a/src/test/java/javax/money/MonetaryCurrenciesTest.java +++ b/src/test/java/javax/money/MonetaryCurrenciesTest.java @@ -18,7 +18,6 @@ import java.util.Locale; import static org.testng.Assert.*; -import static org.testng.Assert.assertEquals; /** * Tests for the {@link MonetaryCurrencies} class.