22
33import  com .javaquery .util .Assert ;
44import  com .javaquery .util .Objects ;
5+ import  com .javaquery .util .collection .function .ExecutableFunction ;
56
67import  java .util .Collection ;
78import  java .util .HashMap ;
89import  java .util .List ;
910import  java .util .Map ;
11+ import  java .util .Set ;
1012import  java .util .stream .IntStream ;
1113import  java .util .stream .Stream ;
1214
15+ import  static  java .util .Collections .*;
16+ 
1317/** 
1418 * @author vicky.thakor 
1519 * @since 1.0 
@@ -18,6 +22,72 @@ public final class Collections {
1822
1923  private  Collections () {}
2024
25+   /** 
26+    * Provide access to {@link java.util.Collections} method singleton.<br/> 
27+    * 
28+    * Returns an immutable set containing only the specified object. The returned set is serializable. 
29+    * 
30+    * @param o the sole object to be stored in the returned set. 
31+    * @param <T> the class of the objects in the set 
32+    * @return an immutable set containing only the specified object. 
33+    */ 
34+   public  static  <T > Set <T > singleton (T  o ) {
35+     return  java .util .Collections .singleton (o );
36+   }
37+ 
38+   /** 
39+    * Provide access to {@link java.util.Collections} method singletonList.<br/> 
40+    * Returns an immutable list containing only the specified object. The returned list is serializable. 
41+    * @param o the class of the objects in the list 
42+    * @param <T> the class of the objects in the list 
43+    * @return an immutable list containing only the specified object. 
44+    */ 
45+   public  static  <T > List <T > singletonList (T  o ) {
46+     return  java .util .Collections .singletonList (o );
47+   }
48+ 
49+   /** 
50+    * Provide access to {@link java.util.Collections} method singletonMap.<br/> 
51+    * Returns an immutable map, mapping only the specified key to the specified value. The returned map is serializable. 
52+    * 
53+    * @param key the sole key to be stored in the returned map. 
54+    * @param value the value to which the returned map maps key. 
55+    * @param <K> the class of the map keys 
56+    * @param <V> the class of the map value 
57+    * @return an immutable map containing only the specified key-value mapping. 
58+    */ 
59+   public  static  <K , V > Map <K , V > singletonMap (K  key , V  value ) {
60+     return  java .util .Collections .singletonMap (key , value );
61+   }
62+ 
63+   /** 
64+    * Provide access to {@link java.util.Collections} method emptySet.<br/> 
65+    * Returns an empty set (immutable). This set is serializable. Unlike the like-named field, this method is parameterized. 
66+    * @param <T> the class of the objects in the set 
67+    * @return the empty set 
68+    */ 
69+   public  static  <T > Set <T > emptySet () {
70+     return  EMPTY_SET ;
71+   }
72+ 
73+   /** 
74+    * Provide access to {@link java.util.Collections} method emptyList.<br/> 
75+    * @param <T> type of elements, if there were any, in the list 
76+    * @return an empty immutable list 
77+    */ 
78+   public  static  <T > List <T > emptyList () {return  EMPTY_LIST ;  }
79+ 
80+   /** 
81+    * Provide access to {@link java.util.Collections} method emptyMap.<br/> 
82+    * Returns an empty map (immutable). This map is serializable. 
83+    * @param <K> the class of the map keys 
84+    * @param <V> the class of the map values 
85+    * @return an empty map 
86+    */ 
87+   public  static  <K , V > Map <K , V > emptyMap () {
88+     return  EMPTY_MAP ;
89+   }
90+ 
2191  /** 
2292   * Returns {@code true} if the provided Collection [List, Set] is {@code null} or empty otherwise 
2393   * returns {@code false}. 
@@ -30,6 +100,17 @@ public static boolean nullOrEmpty(Collection<?> collection) {
30100    return  Objects .isNull (collection ) || collection .isEmpty ();
31101  }
32102
103+   /** 
104+    * Execute code if the provided Collection [List, Set] is {@code null} or empty. 
105+    * @param collection a Collection [List, Set] to be checked against {@code null} or empty 
106+    * @param executableFunction lambda function given executed if the provided Collection [List, Set] is {@code null} or empty. 
107+    */ 
108+   public  static  void  nullOrEmpty (Collection <?> collection , ExecutableFunction  executableFunction ) {
109+     if (nullOrEmpty (collection )){
110+       executableFunction .execute ();
111+     }
112+   }
113+ 
33114  /** 
34115   * Returns {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty 
35116   * otherwise returns {@code false}. 
@@ -43,7 +124,18 @@ public static boolean nonNullNonEmpty(Collection<?> collection) {
43124  }
44125
45126  /** 
46-    * Returns {@code true} if the provided Map is {@code null} and empty otherwise returns {@code 
127+    * Execute code if the provided Collection [List, Set] is non-{@code null} and non-empty. 
128+    * @param collection collection a Collection [List, Set] to be checked against non-{@code null} and non-empty 
129+    * @param executableFunction lambda function given executed if the provided Collection [List, Set] is non-{@code null} and non-empty. 
130+    */ 
131+   public  static  void   nonNullNonEmpty (Collection <?> collection , ExecutableFunction  executableFunction ){
132+     if (nonNullNonEmpty (collection )){
133+       executableFunction .execute ();
134+     }
135+   }
136+ 
137+   /** 
138+    * Returns {@code true} if the provided Map is {@code null} or empty otherwise returns {@code 
47139   * false}. 
48140   * 
49141   * @param map a Map to be checked against {@code null} or empty 
@@ -54,6 +146,17 @@ public static boolean nullOrEmpty(Map<?, ?> map) {
54146    return  Objects .isNull (map ) || map .isEmpty ();
55147  }
56148
149+   /** 
150+    * Execute code if the provided Map is {@code null} or empty 
151+    * @param map a Map to be checked against {@code null} or empty 
152+    * @param executableFunction lambda function given executed if the provided Map is {@code null} or empty 
153+    */ 
154+   public  static  void  nullOrEmpty (Map <?, ?> map , ExecutableFunction  executableFunction ){
155+     if (nullOrEmpty (map )){
156+       executableFunction .execute ();
157+     }
158+   }
159+ 
57160  /** 
58161   * Returns {@code true} if the provided Map is non-{@code null} and non-empty otherwise returns 
59162   * {@code false}. 
@@ -66,6 +169,17 @@ public static boolean nonNullNonEmpty(Map<?, ?> map) {
66169    return  Objects .nonNull (map ) && !map .isEmpty ();
67170  }
68171
172+   /** 
173+    * Execute code if the provided Map is non-{@code null} and non-empty 
174+    * @param map  a Map to be checked against non-{@code null} and non-empty 
175+    * @param executableFunction lambda function given executed if the provided Map is non-{@code null} and non-empty 
176+    */ 
177+   public  static  void  nonNullNonEmpty (Map <?, ?> map , ExecutableFunction  executableFunction ){
178+     if (nonNullNonEmpty (map )){
179+       executableFunction .execute ();
180+     }
181+   }
182+ 
69183  /** 
70184   * Returns stream of batched List from original List by given batch size. 
71185   * 
0 commit comments