config-util: use lambdas 71/57171/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 May 2017 15:49:03 +0000 (17:49 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 16 May 2017 23:24:23 +0000 (23:24 +0000)
This series of patches uses lambdas instead of anonymous classes for
functional interfaces when possible. Lambdas are replaced with method
references when appropriate.

Change-Id: Iac5970f81ff50b5b9358eecfc1529d8102f1b22e
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java

index 1ebb004..f7ecde6 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.controller.config.util.xml;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
 import com.google.common.base.Strings;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
@@ -199,35 +198,21 @@ public final class XmlElement {
     }
 
     public List<XmlElement> getChildElements() {
-        return getChildElementsInternal(new ElementFilteringStrategy() {
-            @Override
-            public boolean accept(final Element e) {
-                return true;
-            }
-        });
+        return getChildElementsInternal(e -> true);
     }
 
     public List<XmlElement> getChildElementsWithinNamespace(final String childName, final String namespace) {
         return Lists.newArrayList(Collections2.filter(getChildElementsWithinNamespace(namespace),
-                new Predicate<XmlElement>() {
-                    @Override
-                    public boolean apply(final XmlElement xmlElement) {
-                        return xmlElement.getName().equals(childName);
-                    }
-                }));
+                xmlElement -> xmlElement.getName().equals(childName)));
     }
 
     public List<XmlElement> getChildElementsWithinNamespace(final String namespace) {
-        return getChildElementsInternal(new ElementFilteringStrategy() {
-            @Override
-            public boolean accept(final Element e) {
-                try {
-                    return XmlElement.fromDomElement(e).getNamespace().equals(namespace);
-                } catch (final MissingNameSpaceException e1) {
-                    return false;
-                }
+        return getChildElementsInternal(e -> {
+            try {
+                return XmlElement.fromDomElement(e).getNamespace().equals(namespace);
+            } catch (final MissingNameSpaceException e1) {
+                return false;
             }
-
         });
     }
 
@@ -237,12 +222,9 @@ public final class XmlElement {
      * @return List of child elements
      */
     public List<XmlElement> getChildElements(final String tagName) {
-        return getChildElementsInternal(new ElementFilteringStrategy() {
-            @Override
-            public boolean accept(final Element e) {
-                // localName returns pure localName without prefix
-                return e.getLocalName().equals(tagName);
-            }
+        return getChildElementsInternal(e -> {
+            // localName returns pure localName without prefix
+            return e.getLocalName().equals(tagName);
         });
     }
 
@@ -267,12 +249,8 @@ public final class XmlElement {
 
     public Optional<XmlElement> getOnlyChildElementOptionally(final String childName, final String namespace) {
         List<XmlElement> children = getChildElementsWithinNamespace(namespace);
-        children = Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
-            @Override
-            public boolean apply(final XmlElement xmlElement) {
-                return xmlElement.getName().equals(childName);
-            }
-        }));
+        children = Lists.newArrayList(Collections2.filter(children,
+                xmlElement -> xmlElement.getName().equals(childName)));
         if (children.size() != 1){
             return Optional.absent();
         }
@@ -287,12 +265,8 @@ public final class XmlElement {
         Optional<String> namespace = getNamespaceOptionally();
         if (namespace.isPresent()) {
             List<XmlElement> children = getChildElementsWithinNamespace(namespace.get());
-            children = Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
-                @Override
-                public boolean apply(final XmlElement xmlElement) {
-                    return xmlElement.getName().equals(childName);
-                }
-            }));
+            children = Lists.newArrayList(Collections2.filter(children,
+                    xmlElement -> xmlElement.getName().equals(childName)));
             if (children.size() != 1){
                 return Optional.absent();
             }
@@ -320,12 +294,8 @@ public final class XmlElement {
 
     public XmlElement getOnlyChildElement(final String childName, final String namespace) throws DocumentedException {
         List<XmlElement> children = getChildElementsWithinNamespace(namespace);
-        children = Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
-            @Override
-            public boolean apply(final XmlElement xmlElement) {
-                return xmlElement.getName().equals(childName);
-            }
-        }));
+        children = Lists.newArrayList(Collections2.filter(children,
+                xmlElement -> xmlElement.getName().equals(childName)));
         if (children.size() != 1){
             throw new DocumentedException(String.format("One element %s:%s expected in %s but was %s", namespace,
                     childName, toString(), children.size()),
@@ -474,12 +444,7 @@ public final class XmlElement {
 
     public List<XmlElement> getChildElementsWithSameNamespace(final String childName) throws MissingNameSpaceException {
         List<XmlElement> children = getChildElementsWithinNamespace(getNamespace());
-        return Lists.newArrayList(Collections2.filter(children, new Predicate<XmlElement>() {
-            @Override
-            public boolean apply(final XmlElement xmlElement) {
-                return xmlElement.getName().equals(childName);
-            }
-        }));
+        return Lists.newArrayList(Collections2.filter(children, xmlElement -> xmlElement.getName().equals(childName)));
     }
 
     public void checkUnrecognisedElements(final List<XmlElement> recognisedElements,

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.