@@ -41,11 +41,16 @@ public interface Optionals {
41
41
* @param optionals must not be {@literal null}.
42
42
* @return
43
43
*/
44
- public static boolean isAnyPresent (Optional <?>... optionals ) {
44
+ static boolean isAnyPresent (Optional <?>... optionals ) {
45
45
46
46
Assert .notNull (optionals , "Optionals must not be null" );
47
47
48
- return Arrays .stream (optionals ).anyMatch (Optional ::isPresent );
48
+ for (Optional <?> optional : optionals ) {
49
+ if (optional .isPresent ()) {
50
+ return true ;
51
+ }
52
+ }
53
+ return false ;
49
54
}
50
55
51
56
/**
@@ -55,7 +60,7 @@ public static boolean isAnyPresent(Optional<?>... optionals) {
55
60
* @return
56
61
*/
57
62
@ SafeVarargs
58
- public static <T > Stream <T > toStream (Optional <? extends T >... optionals ) {
63
+ static <T > Stream <T > toStream (Optional <? extends T >... optionals ) {
59
64
60
65
Assert .notNull (optionals , "Optional must not be null" );
61
66
@@ -69,7 +74,7 @@ public static <T> Stream<T> toStream(Optional<? extends T>... optionals) {
69
74
* @param function must not be {@literal null}.
70
75
* @return
71
76
*/
72
- public static <S , T > Optional <T > firstNonEmpty (Iterable <S > source , Function <S , Optional <T >> function ) {
77
+ static <S , T > Optional <T > firstNonEmpty (Iterable <S > source , Function <S , Optional <T >> function ) {
73
78
74
79
Assert .notNull (source , "Source must not be null" );
75
80
Assert .notNull (function , "Function must not be null" );
@@ -87,7 +92,7 @@ public static <S, T> Optional<T> firstNonEmpty(Iterable<S> source, Function<S, O
87
92
* @param function must not be {@literal null}.
88
93
* @return
89
94
*/
90
- public static <S , T > T firstNonEmpty (Iterable <S > source , Function <S , T > function , T defaultValue ) {
95
+ static <S , T > T firstNonEmpty (Iterable <S > source , Function <S , T > function , T defaultValue ) {
91
96
92
97
Assert .notNull (source , "Source must not be null" );
93
98
Assert .notNull (function , "Function must not be null" );
@@ -105,7 +110,7 @@ public static <S, T> T firstNonEmpty(Iterable<S> source, Function<S, T> function
105
110
* @return
106
111
*/
107
112
@ SafeVarargs
108
- public static <T > Optional <T > firstNonEmpty (Supplier <Optional <T >>... suppliers ) {
113
+ static <T > Optional <T > firstNonEmpty (Supplier <Optional <T >>... suppliers ) {
109
114
110
115
Assert .notNull (suppliers , "Suppliers must not be null" );
111
116
@@ -118,7 +123,7 @@ public static <T> Optional<T> firstNonEmpty(Supplier<Optional<T>>... suppliers)
118
123
* @param suppliers must not be {@literal null}.
119
124
* @return
120
125
*/
121
- public static <T > Optional <T > firstNonEmpty (Iterable <Supplier <Optional <T >>> suppliers ) {
126
+ static <T > Optional <T > firstNonEmpty (Iterable <Supplier <Optional <T >>> suppliers ) {
122
127
123
128
Assert .notNull (suppliers , "Suppliers must not be null" );
124
129
@@ -135,7 +140,7 @@ public static <T> Optional<T> firstNonEmpty(Iterable<Supplier<Optional<T>>> supp
135
140
* @param iterator must not be {@literal null}.
136
141
* @return
137
142
*/
138
- public static <T > Optional <T > next (Iterator <T > iterator ) {
143
+ static <T > Optional <T > next (Iterator <T > iterator ) {
139
144
140
145
Assert .notNull (iterator , "Iterator must not be null" );
141
146
@@ -150,7 +155,7 @@ public static <T> Optional<T> next(Iterator<T> iterator) {
150
155
* @param right
151
156
* @return
152
157
*/
153
- public static <T , S > Optional <Pair <T , S >> withBoth (Optional <T > left , Optional <S > right ) {
158
+ static <T , S > Optional <Pair <T , S >> withBoth (Optional <T > left , Optional <S > right ) {
154
159
return left .flatMap (l -> right .map (r -> Pair .of (l , r )));
155
160
}
156
161
@@ -161,7 +166,7 @@ public static <T, S> Optional<Pair<T, S>> withBoth(Optional<T> left, Optional<S>
161
166
* @param right must not be {@literal null}.
162
167
* @param consumer must not be {@literal null}.
163
168
*/
164
- public static <T , S > void ifAllPresent (Optional <T > left , Optional <S > right , BiConsumer <T , S > consumer ) {
169
+ static <T , S > void ifAllPresent (Optional <T > left , Optional <S > right , BiConsumer <T , S > consumer ) {
165
170
166
171
Assert .notNull (left , "Optional must not be null" );
167
172
Assert .notNull (right , "Optional must not be null" );
@@ -181,7 +186,7 @@ public static <T, S> void ifAllPresent(Optional<T> left, Optional<S> right, BiCo
181
186
* @param function must not be {@literal null}.
182
187
* @return
183
188
*/
184
- public static <T , S , R > Optional <R > mapIfAllPresent (Optional <T > left , Optional <S > right ,
189
+ static <T , S , R > Optional <R > mapIfAllPresent (Optional <T > left , Optional <S > right ,
185
190
BiFunction <T , S , R > function ) {
186
191
187
192
Assert .notNull (left , "Optional must not be null" );
@@ -198,7 +203,7 @@ public static <T, S, R> Optional<R> mapIfAllPresent(Optional<T> left, Optional<S
198
203
* @param consumer must not be {@literal null}.
199
204
* @param runnable must not be {@literal null}.
200
205
*/
201
- public static <T > void ifPresentOrElse (Optional <T > optional , Consumer <? super T > consumer , Runnable runnable ) {
206
+ static <T > void ifPresentOrElse (Optional <T > optional , Consumer <? super T > consumer , Runnable runnable ) {
202
207
203
208
Assert .notNull (optional , "Optional must not be null" );
204
209
Assert .notNull (consumer , "Consumer must not be null" );
0 commit comments