Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Update Release
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Jul 21, 2020
1 parent 479e628 commit c0140ee
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 207 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<artifactId>moneta-bp</artifactId>
<packaging>bundle</packaging>
<version>1.4.1-SNAPSHOT</version>
<version>1.4.1</version>
<name>Moneta (JSR 354 RI) for Java 7</name>

<description>JSR 354 provides an API for representing, transporting, and performing comprehensive calculations with
Expand Down Expand Up @@ -53,7 +53,7 @@

<ciManagement>
<system>Travis-CI</system>
<url>https://travis-ci.org/JavaMoney/javamoney-moneta-bp</url>
<url>https://travis-ci.org/JavaMoney/jsr354-ri-bp</url>
</ciManagement>

<issueManagement>
Expand All @@ -62,10 +62,10 @@
</issueManagement>

<scm>
<connection>scm:git:https://github.com/JavaMoney/javamoney-moneta-bp.git</connection>
<connection>scm:git:https://github.com/JavaMoney/jsr354-ri-bp.git</connection>
<tag>master</tag>
<developerConnection>scm:git:https://github.com/JavaMoney/javamoney-moneta-bp.git</developerConnection>
<url>https://github.com/JavaMoney/javamoney-moneta-bp</url>
<developerConnection>scm:git:https://github.com/JavaMoney/jsr354-ri-bp.git</developerConnection>
<url>https://github.com/JavaMoney/jsr354-ri-bp</url>
</scm>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
* Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* The default date is yesterday or the most recent day of week. To uses exchange rate from a specific date, you can use this way:
* <code>CurrencyUnit termCurrency = ...;</code>
* <code>LocalDate localDate = ...;</code>
* <code>ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(euro).set(localDate).build();</code>v
* <code>ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(euro).setTimestamp(localDate).build();</code>v
* <code>CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);</code>
* <code>MonetaryAmount money = ...;</code>
* <code>MonetaryAmount result = currencyConversion.apply(money);</code>
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/org/javamoney/moneta/internal/JDKObjects.java

This file was deleted.

57 changes: 19 additions & 38 deletions src/main/java/org/javamoney/moneta/spi/MoneyUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2012, 2020, Werner Keil, Otavio Santana and others by the @author tag.
Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
Expand All @@ -15,22 +15,16 @@
*/
package org.javamoney.moneta.spi;

import org.javamoney.moneta.internal.JDKObjects;

import javax.money.CurrencyUnit;
import javax.money.MonetaryAmount;
import javax.money.MonetaryContext;
import javax.money.MonetaryException;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Objects;
import java.util.logging.Logger;

import static java.math.RoundingMode.HALF_EVEN;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.FINEST;

/**
* Platform RI: This utility class simplifies implementing {@link MonetaryAmount},
* by providing the common functionality. The different explicitly typed methods
Expand All @@ -40,17 +34,13 @@
* implement {@link MonetaryAmount} directly.
*
* @author Anatole Tresch
* @author Werner Keil
*/
public final class MoneyUtils {

/**
* The logger used.
*/
private static final Logger LOG = Logger.getLogger(MoneyUtils.class.getName());

public static final String NBSP_STRING = "\u00A0";
public static final String NNBSP_STRING = "\u202F";
public static final char NBSP = NBSP_STRING.charAt(0);
public static final char NNBSP = NNBSP_STRING.charAt(0);

private MoneyUtils() {
}

Expand Down Expand Up @@ -104,18 +94,13 @@ public static BigDecimal getBigDecimal(Number num) {
* @return the corresponding {@link BigDecimal}
*/
public static BigDecimal getBigDecimal(Number num, MonetaryContext moneyContext) {
BigDecimal bd = getBigDecimal(num);
if (JDKObjects.nonNull(moneyContext)) {
MathContext mc = getMathContext(moneyContext, HALF_EVEN);
BigDecimal bd = getBigDecimal(num);
if (moneyContext!=null) {
MathContext mc = getMathContext(moneyContext, RoundingMode.HALF_EVEN);
bd = new BigDecimal(bd.toString(), mc);
int maxScale = moneyContext.getMaxScale();
if (maxScale > 0) {
if (bd.scale() > maxScale) {
if (LOG.isLoggable(FINEST)) {
LOG.log(FINEST, "The number scale is " + bd.scale() + " but Max Scale is " + maxScale);
}
bd = bd.setScale(maxScale, mc.getRoundingMode());
}
if (moneyContext.getMaxScale() > 0) {
LOG.fine(String.format("Got Max Scale %s", moneyContext.getMaxScale()));
bd = bd.setScale(moneyContext.getMaxScale(), mc.getRoundingMode());
}
}
return bd;
Expand All @@ -131,12 +116,15 @@ public static BigDecimal getBigDecimal(Number num, MonetaryContext moneyContext)
*/
public static MathContext getMathContext(MonetaryContext monetaryContext, RoundingMode defaultMode) {
MathContext ctx = monetaryContext.get(MathContext.class);
if (JDKObjects.nonNull(ctx)) {
if (ctx!=null) {
return ctx;
}
RoundingMode roundingMode = monetaryContext.get(RoundingMode.class);
if (roundingMode == null) {
roundingMode = HALF_EVEN;
roundingMode = defaultMode;
}
if (roundingMode == null) {
roundingMode = RoundingMode.HALF_EVEN;
}
return new MathContext(monetaryContext.getPrecision(), roundingMode);
}
Expand All @@ -151,9 +139,9 @@ public static MathContext getMathContext(MonetaryContext monetaryContext, Roundi
* {@link CurrencyUnit#getCurrencyCode()}).
*/
public static void checkAmountParameter(MonetaryAmount amount, CurrencyUnit currencyUnit) {
requireNonNull(amount, "Amount must not be null.");
Objects.requireNonNull(amount, "Amount must not be null.");
final CurrencyUnit amountCurrency = amount.getCurrency();
if (!currencyUnit.getCurrencyCode().equals(amountCurrency.getCurrencyCode())) {
if (!(currencyUnit.getCurrencyCode().equals(amountCurrency.getCurrencyCode()))) {
throw new MonetaryException("Currency mismatch: " + currencyUnit + '/' + amountCurrency);
}
}
Expand All @@ -165,14 +153,7 @@ public static void checkAmountParameter(MonetaryAmount amount, CurrencyUnit curr
* @throws IllegalArgumentException If the number is null
*/
public static void checkNumberParameter(Number number) {
requireNonNull(number, "Number is required.");
Objects.requireNonNull(number, "Number is required.");
}

/**
* Replaces the non-breaking space character U+00A0 and Narrow non-breaking space U+202F from the string with usual space.
* https://en.wikipedia.org/wiki/Non-breaking_space}
*/
public static String replaceNbspWithSpace(String s) {
return s.replace(NBSP, ' ').replace(NNBSP, ' ');
}
}
Loading

0 comments on commit c0140ee

Please sign in to comment.