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    }
0 commit comments