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

Commit 639e5e9

Browse files
committed
Fixed several quality issues.
1 parent 6386b34 commit 639e5e9

File tree

119 files changed

+1522
-982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1522
-982
lines changed

bnd.bnd

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-buildpath: \
2+
osgi.annotation; version=6.0.0,\
3+
osgi.core; version=6.0,\
4+
osgi.cmpn; version=6.0
5+
6+
-testpath: \
7+
${junit}
8+
9+
javac.source: 1.7
10+
javac.target: 1.7
11+
12+
Automatic-Module-Name: org.javamoney.moneta
13+
Bundle-Version: ${version}.${tstamp}
14+
Bundle-Name: JavaMoney Moneta RI
15+
Bundle-SymbolicName: org.javamoney.moneta
16+
Bundle-Description:JavaMoney Moneta Reference Implementation (Backport)
17+
Bundle-Category: Implementation
18+
Bundle-Copyright: (C) Credit Suisse AG
19+
Bundle-License: JSR 354 Spec Evaluation/Implementation License
20+
Bundle-Vendor: Credit Suisse AG
21+
Bundle-DocURL: http://www.javamoney.org
22+
Bundle-Activator: org.javamoney.moneta.internal.OSGIActivator
23+
Export-Package: \
24+
org.javamoney.moneta,\
25+
org.javamoney.moneta.spi,\
26+
org.javamoney.moneta.spi.base,\
27+
org.javamoney.moneta.function,\
28+
org.javamoney.moneta.format,\
29+
org.javamoney.moneta.convert
30+
Import-Package: \
31+
javax.money,\
32+
javax.money.spi,\
33+
javax.money.convert,\
34+
javax.money.format
35+
Export-Service:\
36+
javax.money.spi.ExchangeRateProvider.class,\
37+
javax.money.spi.CurrencyProviderSpi.class,\
38+
javax.money.spi.MonetaryAmountFactoryProviderSpi.class,\
39+
javax.money.spi.MonetaryAmountFormatProviderSpi.class,\
40+
javax.money.spi.MonetaryAmountsSingletonQuerySpi.class,\
41+
javax.money.spi.MonetaryAmountsSingletonQuerySpi.class,\
42+
javax.money.spi.MonetaryAmountsSingletonSpi.class,\
43+
javax.money.spi.MonetaryConversionsSingletonSpi.class,\
44+
javax.money.spi.MonetaryCurrenciesSingletonSpi.class,\
45+
javax.money.spi.RoundingProviderSpi.class,\
46+
org.javamoney.moneta.spi.LoaderService
47+

pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
<!-- dependency versions -->
4747
<testng.version>6.9.12</testng.version>
4848
<revapi.version>0.5.2</revapi.version>
49+
<!-- OSGO support -->
50+
<osgi.version>5.0.0</osgi.version>
51+
<osgi.compendium.version>${osgi.version}</osgi.compendium.version>
52+
<osgi.annotation.version>6.0.0</osgi.annotation.version>
4953
</properties>
5054

5155
<ciManagement>
@@ -97,7 +101,53 @@
97101
</repository>
98102
</repositories>
99103

104+
<dependencyManagement>
105+
<dependencies>
106+
<!-- OSGI support -->
107+
<dependency>
108+
<groupId>org.osgi</groupId>
109+
<artifactId>org.osgi.annotation</artifactId>
110+
<scope>provided</scope>
111+
<version>${osgi.annotation.version}</version>
112+
<optional>true</optional>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.osgi</groupId>
116+
<artifactId>org.osgi.compendium</artifactId>
117+
<scope>provided</scope>
118+
<version>${osgi.compendium.version}</version>
119+
<optional>true</optional>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.osgi</groupId>
123+
<artifactId>org.osgi.core</artifactId>
124+
<version>${osgi.version}</version>
125+
<scope>provided</scope>
126+
<optional>true</optional>
127+
</dependency>
128+
</dependencies>
129+
</dependencyManagement>
130+
100131
<dependencies>
132+
<dependency>
133+
<groupId>org.osgi</groupId>
134+
<artifactId>org.osgi.compendium</artifactId>
135+
<scope>provided</scope>
136+
<optional>true</optional>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.osgi</groupId>
140+
<artifactId>org.osgi.core</artifactId>
141+
<scope>provided</scope>
142+
<optional>true</optional>
143+
</dependency>
144+
<dependency>
145+
<groupId>org.osgi</groupId>
146+
<artifactId>org.osgi.annotation</artifactId>
147+
<scope>provided</scope>
148+
<optional>true</optional>
149+
</dependency>
150+
101151
<dependency>
102152
<groupId>org.testng</groupId>
103153
<artifactId>testng</artifactId>

src/main/java/org/javamoney/moneta/ExchangeRateBuilder.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/**
2-
* Copyright (c) 2012, 2014, 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.
1+
/*
2+
Copyright (c) 2012, 2014, 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.
1515
*/
1616
package org.javamoney.moneta;
1717

@@ -193,13 +193,12 @@ public ExchangeRateBuilder setRate(ExchangeRate rate) {
193193

194194
@Override
195195
public String toString() {
196-
StringBuilder sb = new StringBuilder();
197-
sb.append("org.javamoney.moneta.ExchangeRateBuilder: ");
198-
sb.append("[conversionContext").append(conversionContext).append(',');
199-
sb.append("base").append(base).append(',');
200-
sb.append("term").append(term).append(',');
201-
sb.append("factor").append(factor).append(',');
202-
sb.append("rateChain").append(rateChain).append(']');
203-
return sb.toString();
196+
String sb = "org.javamoney.moneta.ExchangeRateBuilder: " +
197+
"[conversionContext" + conversionContext + ',' +
198+
"base" + base + ',' +
199+
"term" + term + ',' +
200+
"factor" + factor + ',' +
201+
"rateChain" + rateChain + ']';
202+
return sb;
204203
}
205204
}

src/main/java/org/javamoney/moneta/ExchangeRateType.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/**
2-
* Copyright (c) 2012, 2014, 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.
1+
/*
2+
Copyright (c) 2012, 2014, 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.
1515
*/
1616
package org.javamoney.moneta;
1717

src/main/java/org/javamoney/moneta/FastMoney.java

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
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.
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.
1515
*/
1616
package org.javamoney.moneta;
1717

@@ -263,8 +263,8 @@ public static FastMoney zero(CurrencyUnit currency) {
263263
* @param currency the currency, not null
264264
* @param amountMinor the amount of money in the minor division of the currency
265265
* @return the monetary amount from minor units
266-
* @see {@link CurrencyUnit#getDefaultFractionDigits()}
267-
* @see {@link FastMoney#ofMinor(CurrencyUnit, long, int)}
266+
* @see CurrencyUnit#getDefaultFractionDigits()
267+
* @see FastMoney#ofMinor(CurrencyUnit, long, int)
268268
* @throws NullPointerException when the currency is null
269269
* @throws IllegalArgumentException when {@link CurrencyUnit#getDefaultFractionDigits()} is lesser than zero.
270270
* @since 1.0.1
@@ -280,7 +280,7 @@ public static FastMoney ofMinor(CurrencyUnit currency, long amountMinor) {
280280
* @param amountMinor the amount of money in the minor division of the currency
281281
* @param factionDigits number of digits
282282
* @return the monetary amount from minor units
283-
* @see {@link CurrencyUnit#getDefaultFractionDigits()}
283+
* @see CurrencyUnit#getDefaultFractionDigits()
284284
* @throws NullPointerException when the currency is null
285285
* @throws IllegalArgumentException when the factionDigits is negative
286286
* @since 1.0.1
@@ -395,7 +395,7 @@ private void checkAmountParameter(MonetaryAmount amount) {
395395
*/
396396
@Override
397397
public FastMoney divide(Number divisor) {
398-
if (Money.isInfinityAndNotNaN(divisor)) {
398+
if (isInfinityAndNotNaN(divisor)) {
399399
return new FastMoney(0L, getCurrency());
400400
}
401401
checkNumber(divisor);
@@ -405,13 +405,28 @@ public FastMoney divide(Number divisor) {
405405
return new FastMoney(Math.round(this.number / divisor.doubleValue()), getCurrency());
406406
}
407407

408+
/**
409+
* Just to don't break the compatibility.
410+
* Don't use it
411+
* @param number
412+
*/
413+
private static boolean isInfinityAndNotNaN(Number number) {
414+
if (Double.class == number.getClass() || Float.class == number.getClass()) {
415+
double dValue = number.doubleValue();
416+
if (!Double.isNaN(dValue) && Double.isInfinite(dValue)) {
417+
return true;
418+
}
419+
}
420+
return false;
421+
}
422+
408423
/*
409424
* (non-Javadoc)
410425
* @see MonetaryAmount#divideAndRemainder(java.lang.Number)
411426
*/
412427
@Override
413428
public FastMoney[] divideAndRemainder(Number divisor) {
414-
if (Money.isInfinityAndNotNaN(divisor)) {
429+
if (isInfinityAndNotNaN(divisor)) {
415430
FastMoney zero = new FastMoney(0L, getCurrency());
416431
return new FastMoney[]{zero, zero};
417432
}
@@ -427,7 +442,7 @@ public FastMoney[] divideAndRemainder(Number divisor) {
427442
*/
428443
@Override
429444
public FastMoney divideToIntegralValue(Number divisor) {
430-
if (Money.isInfinityAndNotNaN(divisor)) {
445+
if (isInfinityAndNotNaN(divisor)) {
431446
return new FastMoney(0L, getCurrency());
432447
}
433448
checkNumber(divisor);
@@ -440,7 +455,7 @@ public FastMoney divideToIntegralValue(Number divisor) {
440455

441456
@Override
442457
public FastMoney multiply(Number multiplicand) {
443-
Money.checkNoInfinityOrNaN(multiplicand);
458+
checkNoInfinityOrNaN(multiplicand);
444459
checkNumber(multiplicand);
445460
if (isOne(multiplicand)) {
446461
return this;
@@ -449,6 +464,17 @@ public FastMoney multiply(Number multiplicand) {
449464
getCurrency());
450465
}
451466

467+
private static void checkNoInfinityOrNaN(Number number) {
468+
if (Double.class == number.getClass() || Float.class == number.getClass()) {
469+
double dValue = number.doubleValue();
470+
if (Double.isNaN(dValue)) {
471+
throw new ArithmeticException("Not a valid input: NaN.");
472+
} else if (Double.isInfinite(dValue)) {
473+
throw new ArithmeticException("Not a valid input: INFINITY: " + dValue);
474+
}
475+
}
476+
}
477+
452478
private long multiplyExact(long num1, long num2) {
453479
if(num1==0 || num2==0){
454480
return 0;
@@ -833,9 +859,8 @@ public static FastMoney from(MonetaryAmount amount) {
833859
*
834860
* @param text the text to parse not null
835861
* @return FastMoney instance
836-
* @throws NullPointerException
837-
* @throws NumberFormatException
838-
* @throws javax.money.UnknownCurrencyException
862+
* @throws NumberFormatException if the amount is not a number
863+
* @throws javax.money.UnknownCurrencyException if the currency is not resolvable
839864
*/
840865
public static FastMoney parse(CharSequence text) {
841866
return parse(text, DEFAULT_FORMATTER);

0 commit comments

Comments
 (0)