From: Stephen Kitt Date: Tue, 16 May 2017 15:49:03 +0000 (+0200) Subject: config-util: use lambdas X-Git-Tag: release/nitrogen~228 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=d39e199c168d9161dc9a0153722cb9b6324befbd config-util: use lambdas 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 --- diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java index 1ebb0047eb..f7ecde687c 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java @@ -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 getChildElements() { - return getChildElementsInternal(new ElementFilteringStrategy() { - @Override - public boolean accept(final Element e) { - return true; - } - }); + return getChildElementsInternal(e -> true); } public List getChildElementsWithinNamespace(final String childName, final String namespace) { return Lists.newArrayList(Collections2.filter(getChildElementsWithinNamespace(namespace), - new Predicate() { - @Override - public boolean apply(final XmlElement xmlElement) { - return xmlElement.getName().equals(childName); - } - })); + xmlElement -> xmlElement.getName().equals(childName))); } public List 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 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 getOnlyChildElementOptionally(final String childName, final String namespace) { List children = getChildElementsWithinNamespace(namespace); - children = Lists.newArrayList(Collections2.filter(children, new Predicate() { - @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 namespace = getNamespaceOptionally(); if (namespace.isPresent()) { List children = getChildElementsWithinNamespace(namespace.get()); - children = Lists.newArrayList(Collections2.filter(children, new Predicate() { - @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 children = getChildElementsWithinNamespace(namespace); - children = Lists.newArrayList(Collections2.filter(children, new Predicate() { - @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 getChildElementsWithSameNamespace(final String childName) throws MissingNameSpaceException { List children = getChildElementsWithinNamespace(getNamespace()); - return Lists.newArrayList(Collections2.filter(children, new Predicate() { - @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 recognisedElements,