Skip to content

Commit 978edbf

Browse files
author
otaviojava
committed
missing spell
1 parent b0ff272 commit 978edbf

File tree

2 files changed

+56
-35
lines changed

2 files changed

+56
-35
lines changed

src/main/java/org/javamoney/moneta/function/MonetaryFunctions.java

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
* This singleton class provides access to the predefined monetary functions.
2121
*
2222
* @author otaviojava
23+
* @author anatole
2324
*/
24-
public final class MonetaryFunctions{
25+
public final class MonetaryFunctions {
2526

2627

2728
/**
@@ -93,13 +94,28 @@ public static Comparator<MonetaryAmount> sortNumberDesc(){
9394
}
9495

9596
/**
96-
* Create predicate that filters by CurrencyUnit.
97-
*
98-
* @param currencyUnit the target {@link javax.money.CurrencyUnit}
99-
* @return the predicate from CurrencyUnit
100-
*/
101-
public static Predicate<MonetaryAmount> isCurrency(CurrencyUnit currencyUnit){
102-
return m -> m.getCurrency().equals(currencyUnit);
97+
* Create predicate that filters by CurrencyUnit.
98+
* @param currencies
99+
* the target {@link javax.money.CurrencyUnit}
100+
* @return the predicate from CurrencyUnit
101+
*/
102+
public static Predicate<MonetaryAmount> isCurrency(
103+
CurrencyUnit... currencies) {
104+
105+
if (Objects.isNull(currencies) || currencies.length == 0) {
106+
return m -> true;
107+
}
108+
Predicate<MonetaryAmount> predicate = null;
109+
110+
for (CurrencyUnit currencyUnit : currencies) {
111+
if (Objects.isNull(predicate)) {
112+
predicate = m -> m.getCurrency().equals(currencyUnit);
113+
} else {
114+
predicate = predicate.or(m -> m.getCurrency().equals(
115+
currencyUnit));
116+
}
117+
}
118+
return predicate;
103119
}
104120

105121
/**
@@ -108,23 +124,13 @@ public static Predicate<MonetaryAmount> isCurrency(CurrencyUnit currencyUnit){
108124
* @param currencyUnit the target {@link javax.money.CurrencyUnit}
109125
* @return the predicate from CurrencyUnit
110126
*/
111-
public static Predicate<MonetaryAmount> isNotCurrency(CurrencyUnit currencyUnit){
112-
return isCurrency(currencyUnit).negate();
113-
}
127+
public static Predicate<MonetaryAmount> fiterByExcludingCurrency(
128+
CurrencyUnit... currencies) {
114129

115-
/**
116-
* Creates a filtering predicate based on the given currencies.
117-
*
118-
* @param requiredUnit first CurrencyUnit, required.
119-
* @param otherUnits - any another units, not null.
120-
* @return the predicate filtering entries with one of the given currencies.
121-
*/
122-
public static Predicate<MonetaryAmount> containsCurrencies(CurrencyUnit requiredUnit, CurrencyUnit... otherUnits){
123-
Predicate<MonetaryAmount> inPredicate = isCurrency(requiredUnit);
124-
for(CurrencyUnit unit : otherUnits){
125-
inPredicate = inPredicate.or(isCurrency(unit));
126-
}
127-
return inPredicate;
130+
if (Objects.isNull(currencies) || currencies.length == 0) {
131+
return m -> true;
132+
}
133+
return isCurrency(currencies).negate();
128134
}
129135

130136
/**
@@ -228,19 +234,19 @@ public static BinaryOperator<MonetaryAmount> sum(){
228234
}
229235

230236
/**
231-
* Creates a BinaryOperator to calculate the mininum amount
232-
*
233-
* @return the min BinaryOperator, not null.
234-
*/
237+
* Creates a BinaryOperator to calculate the minimum amount
238+
*
239+
* @return the min BinaryOperator, not null.
240+
*/
235241
public static BinaryOperator<MonetaryAmount> min(){
236242
return MonetaryFunctions::min;
237243
}
238244

239245
/**
240-
* Creates a BinaryOperator to caclulate the maximum amount.
241-
*
242-
* @return the max BinaryOperator, not null.
243-
*/
246+
* Creates a BinaryOperator to calculate the maximum amount.
247+
*
248+
* @return the max BinaryOperator, not null.
249+
*/
244250
public static BinaryOperator<MonetaryAmount> max(){
245251
return MonetaryFunctions::max;
246252
}

src/test/java/org/javamoney/moneta/function/MonetaryFunctionsFilterTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,33 @@ public void isCurrencyTest() {
2626

2727
@Test
2828
public void isNotCurrencyTest() {
29-
List<MonetaryAmount> justRealList = currencies().filter(isNotCurrency(BRAZILIAN_REAL)).collect(
29+
List<MonetaryAmount> justRealList = currencies().filter(fiterByExcludingCurrency(BRAZILIAN_REAL)).collect(
3030
Collectors.toList());
3131
Assert.assertEquals(6, justRealList.size());
3232
}
3333

3434
@Test
35-
public void ContainsCurrenciesTest() {
36-
List<MonetaryAmount> justRealList = currencies().filter(containsCurrencies(BRAZILIAN_REAL, DOLLAR)).collect(
35+
public void containsCurrenciesTest() {
36+
List<MonetaryAmount> justRealList = currencies().filter(
37+
isCurrency(BRAZILIAN_REAL, DOLLAR))
38+
.collect(
3739
Collectors.toList());
3840
Assert.assertEquals(6, justRealList.size());
3941
}
4042

43+
@Test
44+
public void shouldReturnAllisCurrencyEmptyTest() {
45+
List<MonetaryAmount> justRealList = currencies().filter(isCurrency())
46+
.collect(Collectors.toList());
47+
Assert.assertEquals(9, justRealList.size());
48+
}
49+
50+
@Test
51+
public void shouldReturnAllfiterByExcludingCurrencyEmptyTest() {
52+
List<MonetaryAmount> justRealList = currencies().filter(
53+
fiterByExcludingCurrency()).collect(Collectors.toList());
54+
Assert.assertEquals(9, justRealList.size());
55+
}
4156
@Test
4257
public void isGreaterThanTest() {
4358
MonetaryAmount money = FastMoney.of(1, BRAZILIAN_REAL);

0 commit comments

Comments
 (0)