3232import java .util .Map ;
3333import java .util .Random ;
3434import java .util .Set ;
35- import java .util .TreeSet ;
3635
3736import java .util .concurrent .CompletableFuture ;
3837
3938import java .util .function .BiConsumer ;
4039import java .util .function .Consumer ;
4140import java .util .function .IntSupplier ;
4241
43- import java .util .stream .Collectors ;
44-
4542/**
4643 * Asynchronous {@link NamedCache}.
4744 *
@@ -106,7 +103,7 @@ public default CompletableFuture<Map<K, V>> getAll(Collection<? extends K> colKe
106103 * @return a {@link CompletableFuture} for a Map of keys to values for the
107104 * specified filter
108105 */
109- public default CompletableFuture <Map <K , V >> getAll (Filter <?> filter )
106+ public default CompletableFuture <Map <K , V >> getAll (Filter filter )
110107 {
111108 return invokeAll (filter , CacheProcessors .get ());
112109 }
@@ -234,7 +231,7 @@ public default CompletableFuture<Void> removeAll(Collection<? extends K> colKeys
234231 *
235232 * @return a {@link CompletableFuture}
236233 */
237- public default CompletableFuture <Void > removeAll (Filter <?> filter )
234+ public default CompletableFuture <Void > removeAll (Filter filter )
238235 {
239236 return invokeAll (filter , CacheProcessors .removeBlind ()).thenAccept (ANY );
240237 }
@@ -260,7 +257,7 @@ public default CompletableFuture<Set<K>> keySet()
260257 *
261258 * @return a set of keys for entries that satisfy the specified criteria
262259 */
263- public default CompletableFuture <Set <K >> keySet (Filter <?> filter )
260+ public default CompletableFuture <Set <K >> keySet (Filter filter )
264261 {
265262 return invokeAll (filter , CacheProcessors .nop ())
266263 .thenApply (Map ::keySet );
@@ -291,7 +288,7 @@ public default CompletableFuture<Void> keySet(Consumer<? super K> callback)
291288 * @return a {@link CompletableFuture} that can be used to determine whether
292289 * the operation completed
293290 */
294- public default CompletableFuture <Void > keySet (Filter <?> filter ,
291+ public default CompletableFuture <Void > keySet (Filter filter ,
295292 Consumer <? super K > callback )
296293 {
297294 return invokeAll (filter , CacheProcessors .nop (),
@@ -319,9 +316,9 @@ public default CompletableFuture<Set<Map.Entry<K, V>>> entrySet()
319316 *
320317 * @return a set of entries that satisfy the specified criteria
321318 */
322- public default CompletableFuture <Set <Map .Entry <K , V >>> entrySet (Filter <?> filter )
319+ public default CompletableFuture <Set <Map .Entry <K , V >>> entrySet (Filter filter )
323320 {
324- return invokeAll (filter , CacheProcessors .binaryGet ())
321+ return invokeAll (filter , CacheProcessors .get ())
325322 .thenApply (Map ::entrySet );
326323 }
327324
@@ -341,14 +338,13 @@ public default CompletableFuture<Set<Map.Entry<K, V>>> entrySet(Filter<?> filter
341338 *
342339 * @return a set of entries that satisfy the specified criteria
343340 */
344- @ SuppressWarnings ("unchecked" )
345- default CompletableFuture <Set <Map .Entry <K , V >>> entrySet (Filter <?> filter , Comparator <?> comparator )
341+ public default CompletableFuture <Set <Map .Entry <K , V >>> entrySet (Filter filter , Comparator comparator )
346342 {
347- return entrySet (filter )
348- .thenApply (setResult ->
343+ return invokeAll (filter , CacheProcessors . get () )
344+ .thenApply (mapResult ->
349345 {
350- int cEntries = setResult .size ();
351- Map .Entry < K , V > [] aEntries = setResult .toArray (new Map .Entry [cEntries ]);
346+ int cEntries = mapResult .size ();
347+ Map .Entry [] aEntries = mapResult . entrySet () .toArray (new Map .Entry [cEntries ]);
352348
353349 Arrays .sort (aEntries , new EntryComparator (
354350 comparator == null ? SafeComparator .INSTANCE : comparator ));
@@ -393,9 +389,10 @@ public default CompletableFuture<Void> entrySet(Consumer<? super Map.Entry<? ext
393389 * @return a {@link CompletableFuture} that can be used to determine whether
394390 * the operation completed
395391 */
396- public default CompletableFuture <Void > entrySet (Filter <?> filter , BiConsumer <? super K , ? super V > callback )
392+ public default CompletableFuture <Void > entrySet (Filter filter , BiConsumer <? super K , ? super V > callback )
397393 {
398- return entrySet (filter , entry -> callback .accept (entry .getKey (), entry .getValue ()));
394+ return invokeAll (filter , CacheProcessors .get (),
395+ entry -> callback .accept (entry .getKey (), entry .getValue ()));
399396 }
400397
401398 /**
@@ -409,10 +406,10 @@ public default CompletableFuture<Void> entrySet(Filter<?> filter, BiConsumer<? s
409406 * @return a {@link CompletableFuture} that can be used to determine whether
410407 * the operation completed
411408 */
412- public default CompletableFuture <Void > entrySet (Filter <?> filter ,
409+ public default CompletableFuture <Void > entrySet (Filter filter ,
413410 Consumer <? super Map .Entry <? extends K , ? extends V >> callback )
414411 {
415- return invokeAll (filter , CacheProcessors .binaryGet (), callback );
412+ return invokeAll (filter , CacheProcessors .get (), callback );
416413 }
417414
418415 /**
@@ -435,10 +432,10 @@ public default CompletableFuture<Collection<V>> values()
435432 * @return a collection of values for entries that satisfy the specified
436433 * criteria
437434 */
438- public default CompletableFuture <Collection <V >> values (Filter <?> filter )
435+ public default CompletableFuture <Collection <V >> values (Filter filter )
439436 {
440- return entrySet (filter )
441- .thenApply (entries -> entries . stream (). map ( Map . Entry :: getValue ). collect ( Collectors . toList ()) );
437+ return invokeAll (filter , CacheProcessors . get () )
438+ .thenApply (Map :: values );
442439 }
443440
444441 /**
@@ -454,10 +451,15 @@ public default CompletableFuture<Collection<V>> values(Filter<?> filter)
454451 * @return a collection of values for entries that satisfy the specified
455452 * criteria
456453 */
457- public default CompletableFuture <Collection <V >> values (Filter <?> filter , Comparator <? super V > comparator )
454+ public default CompletableFuture <Collection <V >> values (Filter filter , Comparator <? super V > comparator )
458455 {
459- return entrySet (filter )
460- .thenApply (entries -> entries .stream ().map (Map .Entry ::getValue ).collect (Collectors .toCollection (() -> new TreeSet <>(comparator ))));
456+ return values (filter )
457+ .thenApply (colValues ->
458+ {
459+ List <V > values = new ArrayList <>(colValues );
460+ values .sort (comparator );
461+ return values ;
462+ });
461463 }
462464
463465 /**
@@ -485,9 +487,10 @@ public default CompletableFuture<Void> values(Consumer<? super V> callback)
485487 * @return a {@link CompletableFuture} that can be used to determine whether
486488 * the operation completed
487489 */
488- public default CompletableFuture <Void > values (Filter <?> filter , Consumer <? super V > callback )
490+ public default CompletableFuture <Void > values (Filter filter , Consumer <? super V > callback )
489491 {
490- return entrySet (filter , entry -> callback .accept (entry .getValue ()));
492+ return invokeAll (filter , CacheProcessors .get (),
493+ entry -> callback .accept (entry .getValue ()));
491494 }
492495
493496 // ---- Asynchronous InvocableMap methods -------------------------------
@@ -553,7 +556,7 @@ public <R> CompletableFuture<Map<K, R>> invokeAll(Collection<? extends K> collKe
553556 * @return a {@link CompletableFuture} that can be used to obtain the result
554557 * of the invocation for each entry
555558 */
556- public <R > CompletableFuture <Map <K , R >> invokeAll (Filter <?> filter ,
559+ public <R > CompletableFuture <Map <K , R >> invokeAll (Filter filter ,
557560 InvocableMap .EntryProcessor <K , V , R > processor );
558561
559562 /**
@@ -672,7 +675,7 @@ public default <R> CompletableFuture<Void> invokeAll(Collection<? extends K> col
672675 * @return a {@link CompletableFuture} that can be used to determine if the
673676 * operation completed successfully
674677 */
675- public <R > CompletableFuture <Void > invokeAll (Filter <?> filter ,
678+ public <R > CompletableFuture <Void > invokeAll (Filter filter ,
676679 InvocableMap .EntryProcessor <K , V , R > processor ,
677680 Consumer <? super Map .Entry <? extends K ,? extends R >> callback );
678681
@@ -696,7 +699,7 @@ public <R> CompletableFuture<Void> invokeAll(Filter<?> filter,
696699 * @return a {@link CompletableFuture} that can be used to determine if the
697700 * operation completed successfully
698701 */
699- public default <R > CompletableFuture <Void > invokeAll (Filter <?> filter ,
702+ public default <R > CompletableFuture <Void > invokeAll (Filter filter ,
700703 InvocableMap .EntryProcessor <K , V , R > processor , BiConsumer <? super K ,? super R > callback )
701704 {
702705 return invokeAll (filter , processor ,
@@ -747,7 +750,7 @@ public <R> CompletableFuture<R> aggregate(Collection<? extends K> collKeys,
747750 * @return a {@link CompletableFuture} that can be used to obtain the result
748751 * of the aggregation
749752 */
750- public <R > CompletableFuture <R > aggregate (Filter <?> filter ,
753+ public <R > CompletableFuture <R > aggregate (Filter filter ,
751754 InvocableMap .EntryAggregator <? super K , ? super V , R > aggregator );
752755
753756 // ---- Asynchronous Map methods ----------------------------------------
@@ -1047,7 +1050,7 @@ public default CompletableFuture<Map<K, Void>> replaceAll(Collection<? extends K
10471050 * @param filter the filter that should be used to select entries
10481051 * @param function the function to apply to each entry
10491052 */
1050- public default CompletableFuture <Map <K , Void >> replaceAll (Filter <?> filter ,
1053+ public default CompletableFuture <Map <K , Void >> replaceAll (Filter filter ,
10511054 Remote .BiFunction <? super K , ? super V , ? extends V > function )
10521055 {
10531056 return invokeAll (filter , CacheProcessors .replace (function ));
0 commit comments