Simplify code using Java 8 features
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / sharding / DistributedShardedDOMDataTree.java
index 7f727fa36b4ab142ecb8d2cc37c53ce858b7ba8e..64c3f14dfb5dde59806c31dd3f92e92af745ebc7 100644 (file)
@@ -31,9 +31,9 @@ import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.AbstractMap.SimpleEntry;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.List;
@@ -363,19 +363,11 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat
 
     void resolveShardAdditions(final Set<DOMDataTreeIdentifier> additions) {
         LOG.debug("{}: Resolving additions : {}", memberName, additions);
-        final ArrayList<DOMDataTreeIdentifier> list = new ArrayList<>(additions);
         // we need to register the shards from top to bottom, so we need to atleast make sure the ordering reflects that
-        Collections.sort(list, (o1, o2) -> {
-            if (o1.getRootIdentifier().getPathArguments().size() < o2.getRootIdentifier().getPathArguments().size()) {
-                return -1;
-            } else if (o1.getRootIdentifier().getPathArguments().size()
-                    == o2.getRootIdentifier().getPathArguments().size()) {
-                return 0;
-            } else {
-                return 1;
-            }
-        });
-        list.forEach(this::createShardFrontend);
+        additions
+            .stream()
+            .sorted(Comparator.comparingInt(o -> o.getRootIdentifier().getPathArguments().size()))
+            .forEachOrdered(this::createShardFrontend);
     }
 
     void resolveShardRemovals(final Set<DOMDataTreeIdentifier> removals) {