Use lambdas instead of anonymous classes 68/45068/6
authorRobert Varga <rovarga@cisco.com>
Fri, 2 Sep 2016 13:14:34 +0000 (15:14 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 6 Sep 2016 09:59:15 +0000 (09:59 +0000)
This makes the code more concise.

Change-Id: I0ce9711d0cafcf4660b78d937e5e0c9fa072da5a
Signed-off-by: Robert Varga <rovarga@cisco.com>
27 files changed:
common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java
common/util/src/main/java/org/opendaylight/yangtools/util/Identifiables.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/NormalizedNodes.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeWriter.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/NormalizedNodeDataTreeCandidateNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/LazyContainerNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefPathErrorListener.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefPathParserListenerImpl.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/serializer/LeafSetNodeBaseSerializer.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/serializer/ListNodeBaseSerializer.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataTreeCandidateNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractModifiedNodeBasedCandidateNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractRecursiveCandidateNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModifiedNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OperationWithModification.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenXPath.java
yang/yang-data-jaxen/src/main/java/org/opendaylight/yangtools/yang/data/jaxen/YangFunctionContext.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSchemaContext.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/FilteringSchemaContextProxy.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/NumberUtil.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveSchemaContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java

index 1cabaf4e3f4168e9ecb54f489c4d2f037ba35a2d..45f4e0ce49dc92a29862a4dee18773c6c1ed1c62 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.util;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
@@ -143,22 +142,18 @@ public final class ClassLoaderUtils {
     }
 
     public static <S,G,P> Class<P> findFirstGenericArgument(final Class<S> scannedClass, final Class<G> genericType) {
-        return withClassLoader(scannedClass.getClassLoader(),
-                ClassLoaderUtils.findFirstGenericArgumentTask(scannedClass, genericType));
+        return withClassLoader(scannedClass.getClassLoader(), findFirstGenericArgumentTask(scannedClass, genericType));
     }
 
+    @SuppressWarnings("unchecked")
     private static <S, G, P> Supplier<Class<P>> findFirstGenericArgumentTask(final Class<S> scannedClass,
             final Class<G> genericType) {
-        return new Supplier<Class<P>>() {
-            @Override
-            @SuppressWarnings("unchecked")
-            public Class<P> get() {
-                final ParameterizedType augmentationGeneric = findParameterizedType(scannedClass, genericType);
-                if (augmentationGeneric != null) {
-                    return (Class<P>) augmentationGeneric.getActualTypeArguments()[0];
-                }
-                return null;
+        return () -> {
+            final ParameterizedType augmentationGeneric = findParameterizedType(scannedClass, genericType);
+            if (augmentationGeneric != null) {
+                return (Class<P>) augmentationGeneric.getActualTypeArguments()[0];
             }
+            return null;
         };
     }
 
index dbeee9bd2ea0b2338f5b3403ac7bba3a663c0837..abbac3b98daebf8f9e91ad926096dfcf67cb3b5b 100644 (file)
@@ -8,21 +8,10 @@
 package org.opendaylight.yangtools.util;
 
 import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.Identifiable;
 
+@Deprecated
 public final class Identifiables {
-
-    private static final Function<Identifiable<Object>, Object> EXTRACT_IDENTIFIER =
-            new Function<Identifiable<Object>, Object>() {
-        @Override
-        public Object apply(@Nonnull final Identifiable<Object> input) {
-            Preconditions.checkNotNull(input);
-            return input.getIdentifier();
-        }
-    };
-
     private Identifiables() {
         throw new UnsupportedOperationException("Utility class");
     }
@@ -31,16 +20,13 @@ public final class Identifiables {
      * Return the {@link Function} to extract the identifier from a particular
      * object implementing the {@link Identifiable} contract.
      *
-     * @return Identificator associated with the object
-     */
-    /*
-     * Suppressing warnings here allows us to fool the compiler enough
-     * such that we can reuse a single function for all applicable types
-     * and present it in a type-safe manner to our users.
+     * @return Identifier associated with the object
+     *
+     * @deprecated Use Identifiable::getIdentifier instead
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @Deprecated
     public static <V> Function<Identifiable<V>, V> identifierExtractor() {
-        return (Function) EXTRACT_IDENTIFIER;
+        return Identifiable::getIdentifier;
     }
 }
 
index 8cdbc2c41373827e5f26baab4fe544f2e87d7f9d..1d50b8af47ecf95c997e2a540ded75680f9289de 100644 (file)
@@ -121,29 +121,23 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis
     }
 
     private Runnable wrapRunnable(final Runnable task) {
-        return new Runnable() {
-            @Override
-            public void run() {
-                final SettableBoolean b = primeDetector();
-                try {
-                    task.run();
-                } finally {
-                    b.reset();
-                }
+        return () -> {
+            final SettableBoolean b = primeDetector();
+            try {
+                task.run();
+            } finally {
+                b.reset();
             }
         };
     }
 
     private <T> Callable<T> wrapCallable(final Callable<T> delagate) {
-        return new Callable<T>() {
-            @Override
-            public T call() throws Exception {
-                final SettableBoolean b = primeDetector();
-                try {
-                    return delagate.call();
-                } finally {
-                    b.reset();
-                }
+        return () -> {
+            final SettableBoolean b = primeDetector();
+            try {
+                return delagate.call();
+            } finally {
+                b.reset();
             }
         };
     }
index fb9b261e5df844465cc9f7f4269d27f4f4d3f7c1..fc0302ba4ff9c34076614f08dc171cd938193caa 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.data.api.schema;
 import static com.google.common.base.Preconditions.checkNotNull;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
 import com.google.common.base.Strings;
 import com.google.common.collect.Maps;
 import java.util.Arrays;
@@ -29,12 +28,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
 @Beta
 public final class NormalizedNodes {
     private static final int STRINGTREE_INDENT = 4;
-    private static final Predicate<DuplicateEntry> DUPLICATES_ONLY = new Predicate<DuplicateEntry>() {
-        @Override
-        public boolean apply(final DuplicateEntry input) {
-            return !input.getDuplicates().isEmpty();
-        }
-    };
 
     private NormalizedNodes() {
         throw new UnsupportedOperationException("Utility class should not be instantiated");
@@ -144,6 +137,6 @@ public final class NormalizedNodes {
      * @return A Map of NormalizedNode/DuplicateEntry relationships.
      */
     public static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(@Nonnull final NormalizedNode<?, ?> node) {
-        return Maps.filterValues(DuplicateFinder.findDuplicates(node), DUPLICATES_ONLY);
+        return Maps.filterValues(DuplicateFinder.findDuplicates(node), input -> !input.getDuplicates().isEmpty());
     }
 }
index be22c5091a1a7ef09b9f467b420cbe1e83d53fee..2d91bf34e6eb6f2af0314abfcc29b48b602c8a20 100644 (file)
@@ -8,11 +8,9 @@
 package org.opendaylight.yangtools.yang.data.api.schema.stream;
 
 import static org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter.UNKNOWN_SIZE;
-
 import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import java.io.Closeable;
 import java.io.Flushable;
@@ -281,19 +279,16 @@ public class NormalizedNodeWriter implements Closeable, Flushable {
             }
 
             // Write all the rest
-            return writeChildren(Iterables.filter(node.getValue(), new Predicate<NormalizedNode<?, ?>>() {
-                @Override
-                public boolean apply(final NormalizedNode<?, ?> input) {
-                    if (input instanceof AugmentationNode) {
-                        return true;
-                    }
-                    if (!qnames.contains(input.getNodeType())) {
-                        return true;
-                    }
-
-                    LOG.debug("Skipping key child {}", input);
-                    return false;
+            return writeChildren(Iterables.filter(node.getValue(), input -> {
+                if (input instanceof AugmentationNode) {
+                    return true;
                 }
+                if (!qnames.contains(input.getNodeType())) {
+                    return true;
+                }
+
+                LOG.debug("Skipping key child {}", input);
+                return false;
             }));
         }
     }
index f471e858ff8335bed1f2ad40fd030d845bf89e01..0b0bd7cbf5d7159242852f7d6016823b57184341 100644 (file)
@@ -27,12 +27,8 @@ final class NormalizedNodeDataTreeCandidateNode implements DataTreeCandidateNode
      * Convenience function for functional transformation of {@link NormalizedNode} into
      * a {@link DataTreeCandidateNode}.
      */
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> FACTORY_FUNCTION = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return input == null ? null : new NormalizedNodeDataTreeCandidateNode(input);
-        }
-    };
+    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> FACTORY_FUNCTION =
+        input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input);
     private final NormalizedNode<?, ?> data;
 
     /**
index 0a737f2e6698d5d4a686ab1489d8a53397cd2e8e..7bbe831d5b27c761227b4b529eb0009bcdb478e9 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import java.util.Map;
 import org.opendaylight.yangtools.util.MapAdaptor;
@@ -50,11 +49,6 @@ final class LazyContainerNode extends AbstractModifiedContainerNode {
     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
         // Modified children add added by superclass. Here we filter the other children.
         return super.addToStringAttributes(helper).add("untouched", Collections2.filter(castData().getValue(),
-            new Predicate<NormalizedNode<?, ?>>() {
-                @Override
-                public boolean apply(final NormalizedNode<?, ?> input) {
-                    return getModifiedChild(input.getIdentifier()) == null;
-                }
-        }));
+            input -> getModifiedChild(input.getIdentifier()) == null));
     }
 }
index c8098e25174804c1f8b3b53ecde1b82513f713e5..bbdbb35886a947fe95c0c8c0f2f7f99075004215 100644 (file)
@@ -17,9 +17,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 class LeafRefPathErrorListener extends BaseErrorListener {
-    private static final Logger LOG = LoggerFactory
-            .getLogger(LeafRefPathErrorListener.class);
-    private final List<LeafRefPathSyntaxErrorException> exceptions = new ArrayList<>();
+    private static final Logger LOG = LoggerFactory.getLogger(LeafRefPathErrorListener.class);
+
+    private final List<LeafRefPathSyntaxErrorException> exceptions = new ArrayList<>(1);
     private final Module module;
 
     public LeafRefPathErrorListener(final Module module) {
@@ -27,14 +27,11 @@ class LeafRefPathErrorListener extends BaseErrorListener {
     }
 
     @Override
-    public void syntaxError(final Recognizer<?, ?> recognizer,
-            final Object offendingSymbol, final int line,
-            final int charPositionInLine, final String msg,
-            final RecognitionException e) {
+    public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
+            final int charPositionInLine, final String msg, final RecognitionException e) {
         LOG.debug("Syntax error in module {} at {}:{}: {}", module.getName(), line, charPositionInLine, msg, e);
 
-        exceptions.add(new LeafRefPathSyntaxErrorException(module.getName(), line,
-                charPositionInLine, msg, e));
+        exceptions.add(new LeafRefPathSyntaxErrorException(module.getName(), line, charPositionInLine, msg, e));
     }
 
     public void validate() throws LeafRefPathSyntaxErrorException {
index 255181341c23d0e6f8c1114db085619834218904..9a199d18eaeb78d3404c7d69bda79cb49820f321 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.leafref;
 
-import com.google.common.base.Function;
 import com.google.common.collect.Lists;
 import java.net.URI;
 import java.util.Date;
@@ -30,8 +29,6 @@ import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
-
-
 final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
 
     private final SchemaContext schemaContext;
@@ -47,13 +44,6 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
     private final SchemaNode node; //FIXME use for identifier path completion
     private ParsingState currentParsingState;
 
-    Function<QNameWithPredicateBuilder, QNameWithPredicate> build = new Function<QNameWithPredicateBuilder, QNameWithPredicate>() {
-        @Override
-        public QNameWithPredicate apply(final QNameWithPredicateBuilder builder) {
-           return builder.build();
-        }
-     };
-
     private enum ParsingState {
         LEAF_REF_PATH, PATH_PREDICATE, PREDICATE_PATH_EQUALITY_EXPR, PATH_KEY_EXPR
     }
@@ -91,11 +81,11 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
         }
     }
 
-
     @Override
     public void exitRel_path_keyexpr(final Rel_path_keyexprContext ctx) {
 
-        final LeafRefPath pathKeyExpression = LeafRefPath.create(Lists.transform(predicatePathKeyQnameList, build), false);
+        final LeafRefPath pathKeyExpression = LeafRefPath.create(Lists.transform(predicatePathKeyQnameList,
+            QNameWithPredicateBuilder::build), false);
         currentPredicate.setPathKeyExpression(pathKeyExpression);
 
         currentParsingState=ParsingState.PREDICATE_PATH_EQUALITY_EXPR;
@@ -117,7 +107,6 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
         currentParsingState=ParsingState.PREDICATE_PATH_EQUALITY_EXPR;
     }
 
-
     @Override
     public void exitPath_equality_expr(final Path_equality_exprContext ctx) {
 
@@ -126,7 +115,6 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
 
     @Override
     public void enterPrefix(final PrefixContext ctx) {
-
         if (module.getPrefix().equals(ctx.getText())) {
             currentQnameModule = module.getQNameModule();
         } else {
@@ -136,10 +124,10 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
 
     @Override
     public void exitPath_arg(final Path_argContext ctx) {
-        leafRefPath = LeafRefPath.create(Lists.transform(leafRefPathQnameList,build), !relativePath);
+        leafRefPath = LeafRefPath.create(Lists.transform(leafRefPathQnameList, QNameWithPredicateBuilder::build),
+            !relativePath);
     }
 
-
     @Override
     public void enterIdentifier(final IdentifierContext ctx) {
         currentQNameLocalName = ctx.getText();
@@ -147,7 +135,6 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
 
     @Override
     public void exitNode_identifier(final Node_identifierContext ctx) {
-
         if (currentQnameModule == null) {
             currentQnameModule = module.getQNameModule();
         }
@@ -176,8 +163,7 @@ final class LeafRefPathParserListenerImpl extends LeafRefPathParserBaseListener{
         return leafRefPath;
     }
 
-
-    private URI getNamespaceForImportPrefix(final String prefix){
+    private URI getNamespaceForImportPrefix(final String prefix) {
         final ModuleImport moduleImport = getModuleImport(prefix);
         final Module findedModule = schemaContext.findModuleByName(moduleImport.getModuleName(), moduleImport.getRevision());
 
index 84f7284aeeb23860788f4fe87fb357d890a7ce01..4c9eb686c6adeb1b4b130ce04a3c8b792bc3bc6a 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
@@ -21,7 +20,6 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
@@ -39,14 +37,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 public final class SchemaUtils {
-
-    private static final Function<DataSchemaNode, QName> QNAME_FUNCTION = new Function<DataSchemaNode, QName>() {
-        @Override
-        public QName apply(@Nonnull final DataSchemaNode input) {
-            return input.getQName();
-        }
-    };
-
     private SchemaUtils() {
         throw new UnsupportedOperationException();
     }
@@ -141,14 +131,8 @@ public final class SchemaUtils {
 
     private static Optional<AugmentationSchema> findAugment(final AugmentationTarget schema, final Set<QName> qNames) {
         for (AugmentationSchema augment : schema.getAvailableAugmentations()) {
-
-            HashSet<QName> qNamesFromAugment = Sets.newHashSet(Collections2.transform(augment.getChildNodes(), new Function<DataSchemaNode, QName>() {
-                @Override
-                public QName apply(@Nonnull final DataSchemaNode input) {
-                    Preconditions.checkNotNull(input);
-                    return input.getQName();
-                }
-            }));
+            HashSet<QName> qNamesFromAugment = Sets.newHashSet(Collections2.transform(augment.getChildNodes(),
+                DataSchemaNode::getQName));
 
             if (qNamesFromAugment.equals(qNames)) {
                 return Optional.of(augment);
@@ -399,7 +383,7 @@ public final class SchemaUtils {
     }
 
     public static AugmentationIdentifier getNodeIdentifierForAugmentation(final AugmentationSchema schema) {
-        final Collection<QName> qnames = Collections2.transform(schema.getChildNodes(), QNAME_FUNCTION);
+        final Collection<QName> qnames = Collections2.transform(schema.getChildNodes(), DataSchemaNode::getQName);
         return new AugmentationIdentifier(ImmutableSet.copyOf(qnames));
     }
 
index 302ffbbd5840865c74511b56ef34b2b3f7534924..3a5b2693a9f9c5d23921083d8f503cc989e6c9fb 100644 (file)
@@ -7,15 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-
 /**
  * Abstract(base) serializer for LeafSetNodes, serializes elements of type E.
  *
@@ -26,16 +24,13 @@ public abstract class LeafSetNodeBaseSerializer<E> implements
 
     @Override
     public final Iterable<E> serialize(final LeafListSchemaNode schema, final LeafSetNode<?> node) {
-        return Iterables.concat(Iterables.transform(node.getValue(), new Function<LeafSetEntryNode<?>, Iterable<E>>() {
-            @Override
-            public Iterable<E> apply(final LeafSetEntryNode<?> input) {
-                final Iterable<E> serializedChild = getLeafSetEntryNodeSerializer().serialize(schema, input);
-                final int size = Iterables.size(serializedChild);
-                Preconditions.checkState(size == 1,
-                        "Unexpected count of elements for leaf-list entry serialized from: %s, should be 1, was: %s",
-                        input, size);
-                return serializedChild;
-            }
+        return Iterables.concat(Iterables.transform(node.getValue(), input -> {
+            final Iterable<E> serializedChild = getLeafSetEntryNodeSerializer().serialize(schema, input);
+            final int size = Iterables.size(serializedChild);
+            Preconditions.checkState(size == 1,
+                    "Unexpected count of elements for leaf-list entry serialized from: %s, should be 1, was: %s",
+                    input, size);
+            return serializedChild;
         }));
     }
 
index 42413be06bbf5571cd687f2ad9156ec4e855d464..bc5e55bb5671da5ece5845143403602e14b1a8e2 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer;
 
-import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 import java.util.Collection;
@@ -32,16 +31,13 @@ public abstract class ListNodeBaseSerializer<E, N extends DataContainerChild<Nod
 
     @Override
     public final Iterable<E> serialize(final ListSchemaNode schema, final N node) {
-        return Iterables.concat(Iterables.transform(node.getValue(), new Function<O, Iterable<E>>() {
-            @Override
-            public Iterable<E> apply(final O input) {
-                final Iterable<E> serializedChild = getListEntryNodeSerializer().serialize(schema, input);
-                final int size = Iterables.size(serializedChild);
+        return Iterables.concat(Iterables.transform(node.getValue(), input -> {
+            final Iterable<E> serializedChild = getListEntryNodeSerializer().serialize(schema, input);
+            final int size = Iterables.size(serializedChild);
 
-                Preconditions.checkState(size == 1,
-                        "Unexpected count of entries  for list serialized from: %s, should be 1, was: %s", input, size);
-                return serializedChild;
-            }
+            Preconditions.checkState(size == 1,
+                    "Unexpected count of entries  for list serialized from: %s, should be 1, was: %s", input, size);
+            return serializedChild;
         }));
     }
 
index 90ecd84b771f132b9b0bc3b370af2bb8a47be839..f7bea78824c56a9442a062d6b6be39ace089a542 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
@@ -21,20 +20,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 
 abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_DELETED_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return AbstractRecursiveCandidateNode.deleteNode(input);
-        }
-    };
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_WRITTEN_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return AbstractRecursiveCandidateNode.writeNode(input);
-        }
-    };
-
-    private static Optional<NormalizedNode<?, ?>> getChild(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container, final PathArgument identifier) {
+    private static Optional<NormalizedNode<?, ?>> getChild(
+            final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container,
+                    final PathArgument identifier) {
         if (container != null) {
             return container.getChild(identifier);
         } else {
@@ -53,11 +41,11 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
             if (maybeNewChild.isPresent()) {
                 return AbstractRecursiveCandidateNode.replaceNode(oldChild, maybeNewChild.get());
             } else {
-                return TO_DELETED_NODE.apply(oldChild);
+                return AbstractRecursiveCandidateNode.deleteNode(oldChild);
             }
         } else {
             if (maybeNewChild.isPresent()) {
-                return TO_WRITTEN_NODE.apply(maybeNewChild.get());
+                return AbstractRecursiveCandidateNode.writeNode(maybeNewChild.get());
             } else {
                 return null;
             }
@@ -69,10 +57,10 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
         Preconditions.checkArgument(newData != null || oldData != null,
                 "No old or new data, modification type should be NONE and deltaChildren() mustn't be called.");
         if (newData == null) {
-            return Collections2.transform(oldData.getValue(), TO_DELETED_NODE);
+            return Collections2.transform(oldData.getValue(), AbstractRecursiveCandidateNode::deleteNode);
         }
         if (oldData == null) {
-            return Collections2.transform(newData.getValue(), TO_WRITTEN_NODE);
+            return Collections2.transform(newData.getValue(), AbstractRecursiveCandidateNode::writeNode);
         }
 
         /*
index 92586972e9a132aa4f5617874605a5d0de42d330..aa1ae48ceed8183951807beb85c1459f0eb757a1 100644 (file)
@@ -6,7 +6,6 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
@@ -23,20 +22,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 
 abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandidateNode {
-
-    private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_UNMODIFIED_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
-        @Override
-        public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-            return AbstractRecursiveCandidateNode.unmodifiedNode(input);
-        }
-    };
-
     private final ModifiedNode mod;
     private final TreeNode newMeta;
     private final TreeNode oldMeta;
 
-    protected AbstractModifiedNodeBasedCandidateNode(final ModifiedNode mod,
-            final TreeNode oldMeta, final TreeNode newMeta) {
+    protected AbstractModifiedNodeBasedCandidateNode(final ModifiedNode mod, final TreeNode oldMeta,
+            final TreeNode newMeta) {
         this.newMeta = newMeta;
         this.oldMeta = oldMeta;
         this.mod = Preconditions.checkNotNull(mod);
@@ -89,17 +80,13 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
         case APPEARED:
         case DISAPPEARED:
         case SUBTREE_MODIFIED:
-            return Collections2.transform(mod.getChildren(), new Function<ModifiedNode, DataTreeCandidateNode>() {
-                @Override
-                public DataTreeCandidateNode apply(final ModifiedNode input) {
-                    return childNode(input);
-                }
-            });
+            return Collections2.transform(mod.getChildren(), this::childNode);
         case UNMODIFIED:
             // Unmodified node, but we still need to resolve potential children. canHaveChildren returns
             // false if both arguments are null.
             if (canHaveChildren(oldMeta, newMeta)) {
-                return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(), TO_UNMODIFIED_NODE);
+                return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
+                    AbstractRecursiveCandidateNode::unmodifiedNode);
             } else {
                 return Collections.emptyList();
             }
@@ -158,7 +145,7 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida
             if (canHaveChildren(oldMeta, newMeta)) {
                 final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta).getChild(identifier);
                 if (maybeChild.isPresent()) {
-                    return TO_UNMODIFIED_NODE.apply(maybeChild.get());
+                    return AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get());
                 } else {
                     return null;
                 }
index 00c215a48121fb91f4944ae8b079fdb5062bc1da..f8dd37d24dd458f57a4906c691339014fd319ec8 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.collect.Collections2;
 import java.util.Collection;
@@ -70,12 +69,7 @@ abstract class AbstractRecursiveCandidateNode extends AbstractDataTreeCandidateN
 
     @Override
     public final Collection<DataTreeCandidateNode> getChildNodes() {
-        return Collections2.transform(getData().getValue(), new Function<NormalizedNode<?,?>, DataTreeCandidateNode>() {
-            @Override
-            public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
-                return createChild(input);
-            }
-        });
+        return Collections2.transform(getData().getValue(), this::createChild);
     }
 
     @SuppressWarnings("unchecked")
index 7360e988d23c08003e6ec71817dda1eea4bfadaf..35da5d3650a4c87987b46679acb1625461e5c880 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.base.Predicate;
 import java.util.Collection;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -38,11 +37,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  */
 @NotThreadSafe
 final class ModifiedNode extends NodeModification implements StoreTreeNode<ModifiedNode> {
-    static final Predicate<ModifiedNode> IS_TERMINAL_PREDICATE = new Predicate<ModifiedNode>() {
-        @Override
-        public boolean apply(@Nullable final ModifiedNode input) {
-            Preconditions.checkNotNull(input);
-            switch (input.getOperation()) {
+    static final Predicate<ModifiedNode> IS_TERMINAL_PREDICATE = input -> {
+        Preconditions.checkNotNull(input);
+        switch (input.getOperation()) {
             case DELETE:
             case MERGE:
             case WRITE:
@@ -50,10 +47,9 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
             case TOUCH:
             case NONE:
                 return false;
-            }
-
-            throw new IllegalArgumentException(String.format("Unhandled modification type %s", input.getOperation()));
         }
+
+        throw new IllegalArgumentException(String.format("Unhandled modification type %s", input.getOperation()));
     };
 
     private final Map<PathArgument, ModifiedNode> children;
index d22854dc889b21d06e57ca11928dd74e9281badf..72221770cd0393c06223900b4a4313525bf2ac25 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -16,19 +15,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 
 final class OperationWithModification {
-    private static final Function<TreeNode, NormalizedNode<?, ?>> READ_DATA = new Function<TreeNode, NormalizedNode<?, ?>>() {
-        @Override
-        public NormalizedNode<?, ?> apply(final TreeNode input) {
-            return input.getData();
-        }
-    };
-
-    private final ModifiedNode modification;
     private final ModificationApplyOperation applyOperation;
+    private final ModifiedNode modification;
 
     private OperationWithModification(final ModificationApplyOperation op, final ModifiedNode mod) {
-        this.modification = Preconditions.checkNotNull(mod);
         this.applyOperation = Preconditions.checkNotNull(op);
+        this.modification = Preconditions.checkNotNull(mod);
     }
 
     void write(final NormalizedNode<?, ?> value) {
@@ -74,7 +66,7 @@ final class OperationWithModification {
                 snapshot = applyOperation.getChild(child).get().apply(childNode, childNode.getOriginal(), version);
             }
 
-            return snapshot.transform(READ_DATA);
+            return snapshot.transform(TreeNode::getData);
         }
 
         Optional<TreeNode> snapshot = modification.getSnapshot();
@@ -83,7 +75,7 @@ final class OperationWithModification {
         }
 
         if (snapshot.isPresent()) {
-            return snapshot.get().getChild(child).transform(READ_DATA);
+            return snapshot.get().getChild(child).transform(TreeNode::getData);
         }
 
         return Optional.absent();
index 563b69526b3e25cde9946488ae2617eca7be3287..663cd528f25b6f99b9dbf2d2639e94f01fd7c0fa 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.jaxen;
 
 import com.google.common.base.Converter;
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
@@ -35,13 +34,7 @@ import org.slf4j.LoggerFactory;
 
 final class JaxenXPath implements XPathExpression {
     private static final Logger LOG = LoggerFactory.getLogger(JaxenXPath.class);
-    protected static final Function<NormalizedNodeContext, NormalizedNode<?, ?>> EXTRACT_NODE =
-            new Function<NormalizedNodeContext, NormalizedNode<?, ?>>() {
-        @Override
-        public NormalizedNode<?, ?> apply(final NormalizedNodeContext input) {
-            return input.getNode();
-        }
-    };
+
     private final Converter<String, QNameModule> converter;
     private final SchemaPath schemaPath;
     private final BaseXPath xpath;
@@ -114,7 +107,7 @@ final class JaxenXPath implements XPathExpression {
                 @Override
                 public Collection<NormalizedNode<?, ?>> getValue() {
                     // XXX: Will this really work, or do we need to perform deep transformation?
-                    return Lists.transform((List<NormalizedNodeContext>) result, EXTRACT_NODE);
+                    return Lists.transform((List<NormalizedNodeContext>) result, NormalizedNodeContext::getNode);
                 }
             });
         } else {
index c2dae8995932b2220c4fdac69e68b1064775c40a..87c8976740f3adb903550427606ad91343f083ec 100644 (file)
@@ -8,8 +8,6 @@
 package org.opendaylight.yangtools.yang.data.jaxen;
 
 import com.google.common.base.Verify;
-import java.util.List;
-import org.jaxen.Context;
 import org.jaxen.Function;
 import org.jaxen.FunctionCallException;
 import org.jaxen.FunctionContext;
@@ -23,17 +21,13 @@ final class YangFunctionContext implements FunctionContext {
     // Core XPath functions, as per http://tools.ietf.org/html/rfc6020#section-6.4.1
     private static final FunctionContext XPATH_FUNCTION_CONTEXT = new XPathFunctionContext(false);
     // current() function, as per http://tools.ietf.org/html/rfc6020#section-6.4.1
-    private static final Function CURRENT_FUNCTION = new Function() {
-        @Override
-        public NormalizedNodeContext call(final Context context, @SuppressWarnings("rawtypes") final List args)
-                throws FunctionCallException {
-            if (!args.isEmpty()) {
-                throw new FunctionCallException("current() takes no arguments.");
-            }
-
-            Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass());
-            return ((NormalizedNodeContext) context);
+    private static final Function CURRENT_FUNCTION = (context, args) -> {
+        if (!args.isEmpty()) {
+            throw new FunctionCallException("current() takes no arguments.");
         }
+
+        Verify.verify(context instanceof NormalizedNodeContext, "Unhandled context %s", context.getClass());
+        return ((NormalizedNodeContext) context);
     };
 
     // Singleton instance of reuse
index b760620dcf6b971380c897deccfbc9cbfee50aed..737461b873a11cdc25c48928b4d7e9cd91916f3c 100644 (file)
@@ -41,25 +41,16 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
 
 public abstract class AbstractSchemaContext implements SchemaContext {
-
-    protected static final Supplier<TreeSet<Module>> MODULE_SET_SUPPLIER = new Supplier<TreeSet<Module>>() {
-        @Override
-        public TreeSet<Module> get() {
-            return new TreeSet<>(REVISION_COMPARATOR);
+    protected static final Comparator<Module> REVISION_COMPARATOR = (o1, o2) -> {
+        if (o2.getRevision() == null) {
+            return -1;
         }
-    };
-
-    protected static final Comparator<Module> REVISION_COMPARATOR = new Comparator<Module>() {
-        @Override
-        public int compare(final Module o1, final Module o2) {
-            if (o2.getRevision() == null) {
-                return -1;
-            }
 
-            return o2.getRevision().compareTo(o1.getRevision());
-        }
+        return o2.getRevision().compareTo(o1.getRevision());
     };
 
+    protected static final Supplier<TreeSet<Module>> MODULE_SET_SUPPLIER = () -> new TreeSet<>(REVISION_COMPARATOR);
+
     /**
      * @return yang sources where key is ModuleIdentifier
      */
index 2a5dd589f7ea3bded5afa849dc5faed651dd16ae..49a2e13ff092743b0fdbd5db6702bab88a037a78 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.model.util;
 
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
 import com.google.common.base.Strings;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableMap;
@@ -25,13 +24,11 @@ import com.google.common.collect.TreeMultimap;
 import java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
-import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
@@ -102,40 +99,23 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext {
     }
 
     private static TreeMultimap<String, Module> getStringModuleTreeMultimap() {
-        return TreeMultimap.create(new Comparator<String>() {
-                @Override
-                public int compare(final String o1, final String o2) {
-                    return o1.compareTo(o2);
-                }
-            }, REVISION_COMPARATOR);
+        return TreeMultimap.create((o1, o2) -> o1.compareTo(o2), REVISION_COMPARATOR);
     }
 
     private static void processForAdditionalModules(final SchemaContext delegate,
             final Set<ModuleId> additionalModuleIds, final Builder<Module> filteredModulesBuilder) {
-        filteredModulesBuilder.addAll(Collections2.filter(delegate.getModules(), new Predicate<Module>() {
-            @Override
-            public boolean apply(@Nullable final Module module) {
-                return selectAdditionalModules(module, additionalModuleIds);
-            }
-        }));
+        filteredModulesBuilder.addAll(Collections2.filter(delegate.getModules(),
+            module -> selectAdditionalModules(module, additionalModuleIds)));
     }
 
-    private void processForRootModules(final SchemaContext delegate, final Collection<ModuleId> rootModules, final Builder<Module> filteredModulesBuilder) {
-        filteredModulesBuilder.addAll(Collections2.filter(delegate.getModules(), new Predicate<Module>() {
-            @Override
-            public boolean apply(@Nullable final Module module) {
-                return checkModuleDependency(module, rootModules);
-            }
-        }));
+    private void processForRootModules(final SchemaContext delegate, final Collection<ModuleId> rootModules,
+            final Builder<Module> filteredModulesBuilder) {
+        filteredModulesBuilder.addAll(Collections2.filter(delegate.getModules(),
+            module -> checkModuleDependency(module, rootModules)));
     }
 
     private static Multimap<String, Module> getStringModuleMap(final SchemaContext delegate) {
-        return Multimaps.index(delegate.getModules(), new Function<Module, String>() {
-            @Override
-            public String apply(final Module input) {
-                return input.getName();
-            }
-        });
+        return Multimaps.index(delegate.getModules(), Module::getName);
     }
 
     //dealing with imported module other than root and directly importing root
@@ -242,12 +222,8 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext {
             return rev;
         }
 
-        public static final Function<Module, ModuleId> MODULE_TO_MODULE_ID = new Function<Module, ModuleId>() {
-            @Override
-            public ModuleId apply(final Module input) {
-                return new ModuleId(input.getName(), input.getRevision());
-            }
-        };
+        public static final Function<Module, ModuleId> MODULE_TO_MODULE_ID = input -> new ModuleId(input.getName(),
+            input.getRevision());
 
         @Override
         public boolean equals(final Object o) {
index 9328237aebab99a533f6c5fb7a6cb6f1b3fce37d..2a27a79c32de43c0be7e5b9eceecbcb84ee2f7eb 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.model.util;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
@@ -600,20 +599,12 @@ public final class SchemaContextUtil {
 
         if (Iterables.size(schemaNodePath) - colCount >= 0) {
             return Iterables.concat(Iterables.limit(schemaNodePath, Iterables.size(schemaNodePath) - colCount),
-                    Iterables.transform(Iterables.skip(xpaths, colCount), new Function<String, QName>() {
-                        @Override
-                        public QName apply(final String input) {
-                            return stringPathPartToQName(context, module, input);
-                        }
-                    }));
+                Iterables.transform(Iterables.skip(xpaths, colCount),
+                    input -> stringPathPartToQName(context, module, input)));
         }
         return Iterables.concat(schemaNodePath,
-                Iterables.transform(Iterables.skip(xpaths, colCount), new Function<String, QName>() {
-                    @Override
-                    public QName apply(final String input) {
-                        return stringPathPartToQName(context, module, input);
-                    }
-                }));
+                Iterables.transform(Iterables.skip(xpaths, colCount),
+                    input -> stringPathPartToQName(context, module, input)));
     }
 
     /**
index 2446ef0b82b71949dba336b2d4af1d891fe9c836..a0582855c2de3a99e7e37a8f5201b7ddc074121a 100644 (file)
@@ -16,46 +16,38 @@ import java.util.Comparator;
 import java.util.Map;
 
 final class NumberUtil {
-    private static final Comparator<Number> NUMBER_COMPARATOR = new Comparator<Number>() {
-        @Override
-        public int compare(final Number o1, final Number o2) {
-            Preconditions.checkArgument(o1.getClass().equals(o2.getClass()), "Incompatible Number classes %s and %s",
-                o1.getClass(), o2.getClass());
+    private static final Comparator<Number> NUMBER_COMPARATOR = (o1, o2) -> {
+        Preconditions.checkArgument(o1.getClass().equals(o2.getClass()), "Incompatible Number classes %s and %s",
+            o1.getClass(), o2.getClass());
 
-            if (o1 instanceof Byte) {
-                return ((Byte)o1).compareTo((Byte) o2);
-            } else if (o1 instanceof Short) {
-                return ((Short)o1).compareTo((Short) o2);
-            } else if (o1 instanceof Integer) {
-                return ((Integer)o1).compareTo((Integer) o2);
-            } else if (o1 instanceof Long) {
-                return ((Long)o1).compareTo((Long) o2);
-            } else if (o1 instanceof BigDecimal) {
-                return ((BigDecimal)o1).compareTo((BigDecimal) o2);
-            } else if (o1 instanceof BigInteger) {
-                return ((BigInteger)o1).compareTo((BigInteger) o2);
-            } else {
-                throw new IllegalArgumentException("Unsupported Number class " + o1.getClass());
-            }
+        if (o1 instanceof Byte) {
+            return ((Byte)o1).compareTo((Byte) o2);
+        } else if (o1 instanceof Short) {
+            return ((Short)o1).compareTo((Short) o2);
+        } else if (o1 instanceof Integer) {
+            return ((Integer)o1).compareTo((Integer) o2);
+        } else if (o1 instanceof Long) {
+            return ((Long)o1).compareTo((Long) o2);
+        } else if (o1 instanceof BigDecimal) {
+            return ((BigDecimal)o1).compareTo((BigDecimal) o2);
+        } else if (o1 instanceof BigInteger) {
+            return ((BigInteger)o1).compareTo((BigInteger) o2);
+        } else {
+            throw new IllegalArgumentException("Unsupported Number class " + o1.getClass());
         }
     };
 
     private static final Map<Class<? extends Number>, Function<Number, Number>> CONVERTERS;
     static {
         final ImmutableMap.Builder<Class<? extends Number>, Function<Number, Number>> b = ImmutableMap.builder();
-        b.put(Byte.class, new Function<Number, Number>() {
-            @Override
-            public Number apply(final Number input) {
-                if (input instanceof Byte) {
-                    return input;
-                }
-
-                return Byte.valueOf(input.toString());
+        b.put(Byte.class, input -> {
+            if (input instanceof Byte) {
+                return input;
             }
+
+            return Byte.valueOf(input.toString());
         });
-        b.put(Short.class, new Function<Number, Number>() {
-            @Override
-            public Number apply(final Number input) {
+        b.put(Short.class, input -> {
                 if (input instanceof Short) {
                     return input;
                 }
@@ -64,61 +56,48 @@ final class NumberUtil {
                 }
 
                 return Short.valueOf(input.toString());
-            }
         });
-        b.put(Integer.class, new Function<Number, Number>() {
-            @Override
-            public Number apply(final Number input) {
-                if (input instanceof Integer) {
-                    return input;
-                }
-                if (input instanceof Byte || input instanceof Short) {
-                    return input.intValue();
-                }
-
-                return Integer.valueOf(input.toString());
+        b.put(Integer.class, input -> {
+            if (input instanceof Integer) {
+                return input;
             }
-        });
-        b.put(Long.class, new Function<Number, Number>() {
-            @Override
-            public Number apply(final Number input) {
-                if (input instanceof Long) {
-                    return input;
-                }
-                if (input instanceof Byte || input instanceof Short || input instanceof Integer) {
-                    return input.longValue();
-                }
-
-                return Long.valueOf(input.toString());
+            if (input instanceof Byte || input instanceof Short) {
+                return input.intValue();
             }
-        });
-        b.put(BigDecimal.class, new Function<Number, Number>() {
-            @Override
-            public Number apply(final Number input) {
-                if (input instanceof BigDecimal) {
-                    return input;
-                }
-                if (input instanceof Byte || input instanceof Short ||
-                        input instanceof Integer || input instanceof Long) {
-                    return BigDecimal.valueOf(input.longValue());
-                }
 
-                return new BigDecimal(input.toString());
+            return Integer.valueOf(input.toString());
+        });
+        b.put(Long.class, input ->  {
+            if (input instanceof Long) {
+                return input;
+            }
+            if (input instanceof Byte || input instanceof Short || input instanceof Integer) {
+                return input.longValue();
             }
+
+            return Long.valueOf(input.toString());
         });
-        b.put(BigInteger.class, new Function<Number, Number>() {
-            @Override
-            public Number apply(final Number input) {
-                if (input instanceof BigInteger) {
-                    return input;
-                }
-                if (input instanceof Byte || input instanceof Short ||
-                        input instanceof Integer || input instanceof Long) {
-                    return BigInteger.valueOf(input.longValue());
-                }
+        b.put(BigDecimal.class, input -> {
+            if (input instanceof BigDecimal) {
+                return input;
+            }
+            if (input instanceof Byte || input instanceof Short ||
+                    input instanceof Integer || input instanceof Long) {
+                return BigDecimal.valueOf(input.longValue());
+            }
 
-                return new BigInteger(input.toString());
+            return new BigDecimal(input.toString());
+        });
+        b.put(BigInteger.class, input -> {
+            if (input instanceof BigInteger) {
+                return input;
+            }
+            if (input instanceof Byte || input instanceof Short ||
+                    input instanceof Integer || input instanceof Long) {
+                return BigInteger.valueOf(input.longValue());
             }
+
+            return new BigInteger(input.toString());
         });
         CONVERTERS = b.build();
     }
index fb83f5db5a6231ff57383c938e3487ac1777d5f2..eb8d977c89055eaa8b35570035fa7657cacec96b 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.parser.repo;
 
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.collect.Collections2;
@@ -28,7 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import javax.annotation.Nullable;
+import java.util.function.Predicate;
 import org.antlr.v4.runtime.ParserRuleContext;
 import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext;
 import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
@@ -54,12 +53,6 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
     private static final ExceptionMapper<SchemaResolutionException> MAPPER = ReflectiveExceptionMapper.create("resolve sources", SchemaResolutionException.class);
     private static final Logger LOG = LoggerFactory.getLogger(SharedSchemaContextFactory.class);
 
-    private final Function<SourceIdentifier, ListenableFuture<ASTSchemaSource>> requestSources = new Function<SourceIdentifier, ListenableFuture<ASTSchemaSource>>() {
-        @Override
-        public ListenableFuture<ASTSchemaSource> apply(final SourceIdentifier input) {
-            return repository.getSchemaSource(input, ASTSchemaSource.class);
-        }
-    };
     private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().weakValues().build();
     private final Cache<Collection<SourceIdentifier>, SchemaContext> semVerCache = CacheBuilder.newBuilder().weakValues().build();
     private final SharedSchemaRepository repository;
@@ -75,13 +68,20 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
     @Override
     public CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
             final Collection<SourceIdentifier> requiredSources, final StatementParserMode statementParserMode,
-            final java.util.function.Predicate<QName> isFeatureSupported) {
+            final Predicate<QName> isFeatureSupported) {
         return createSchemaContext(requiredSources,
                 statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache,
                 new AssembleSources(isFeatureSupported, statementParserMode));
     }
 
-    private CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(final Collection<SourceIdentifier> requiredSources, final Cache<Collection<SourceIdentifier>, SchemaContext> cache, final AsyncFunction<List<ASTSchemaSource>, SchemaContext> assembleSources) {
+    private ListenableFuture<ASTSchemaSource> requestSource(final SourceIdentifier identifier) {
+        return repository.getSchemaSource(identifier, ASTSchemaSource.class);
+    }
+
+    private CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
+            final Collection<SourceIdentifier> requiredSources,
+            final Cache<Collection<SourceIdentifier>, SchemaContext> cache,
+            final AsyncFunction<List<ASTSchemaSource>, SchemaContext> assembleSources) {
         // Make sources unique
         final List<SourceIdentifier> uniqueSourceIdentifiers = deDuplicateSources(requiredSources);
 
@@ -92,7 +92,8 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
         }
 
         // Request all sources be loaded
-        ListenableFuture<List<ASTSchemaSource>> sf = Futures.allAsList(Collections2.transform(uniqueSourceIdentifiers, requestSources));
+        ListenableFuture<List<ASTSchemaSource>> sf = Futures.allAsList(Collections2.transform(uniqueSourceIdentifiers,
+            this::requestSource));
 
         // Detect mismatch between requested Source IDs and IDs that are extracted from parsed source
         // Also remove duplicates if present
@@ -129,12 +130,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
         }
 
         LOG.warn("Duplicate sources requested for schema context, removed duplicate sources: {}",
-            Collections2.filter(uniqueSourceIdentifiers, new Predicate<SourceIdentifier>() {
-                @Override
-                public boolean apply(@Nullable final SourceIdentifier input) {
-                    return Iterables.frequency(requiredSources, input) > 1;
-                }
-            }));
+            Collections2.filter(uniqueSourceIdentifiers, input -> Iterables.frequency(requiredSources, input) > 1));
         return ImmutableList.copyOf(uniqueSourceIdentifiers);
     }
 
@@ -173,20 +169,20 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
 
     private static final class AssembleSources implements AsyncFunction<List<ASTSchemaSource>, SchemaContext> {
 
-        private final java.util.function.Predicate<QName> isFeatureSupported;
+        private final Predicate<QName> isFeatureSupported;
         private final StatementParserMode statementParserMode;
         private final Function<ASTSchemaSource, SourceIdentifier> getIdentifier;
 
-        private AssembleSources(final java.util.function.Predicate<QName> isFeatureSupported,
+        private AssembleSources(final Predicate<QName> isFeatureSupported,
                 final StatementParserMode statementParserMode) {
             this.isFeatureSupported = Preconditions.checkNotNull(isFeatureSupported);
             this.statementParserMode = Preconditions.checkNotNull(statementParserMode);
             switch (statementParserMode) {
             case SEMVER_MODE:
-                this.getIdentifier = ASTSchemaSource.GET_SEMVER_IDENTIFIER;
+                this.getIdentifier = ASTSchemaSource::getSemVerIdentifier;
                 break;
             default:
-                this.getIdentifier = ASTSchemaSource.GET_IDENTIFIER;
+                this.getIdentifier = ASTSchemaSource::getIdentifier;
             }
         }
 
@@ -195,7 +191,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
                 SourceException, ReactorException {
             final Map<SourceIdentifier, ASTSchemaSource> srcs = Maps.uniqueIndex(sources, getIdentifier);
             final Map<SourceIdentifier, YangModelDependencyInfo> deps =
-                    Maps.transformValues(srcs, ASTSchemaSource.GET_DEPINFO);
+                    Maps.transformValues(srcs, ASTSchemaSource::getDependencyInformation);
 
             LOG.debug("Resolving dependency reactor {}", deps);
 
@@ -207,7 +203,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
                         res.getResolvedSources(), res.getUnsatisfiedImports());
             }
 
-            final Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource.GET_AST);
+            final Map<SourceIdentifier, ParserRuleContext> asts = Maps.transformValues(srcs, ASTSchemaSource::getAST);
             final CrossSourceStatementReactor.BuildAction reactor =
                     YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, isFeatureSupported);
 
index cf1f208682e900a6aa9f6ece3b165550b3063f28..ec0390bead0e16f8961b38854418dd910c45dab1 100644 (file)
@@ -40,25 +40,16 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
 abstract class AbstractEffectiveSchemaContext implements SchemaContext {
-
-    protected static final Supplier<NavigableSet<Module>> MODULE_SET_SUPPLIER = new Supplier<NavigableSet<Module>>() {
-        @Override
-        public NavigableSet<Module> get() {
-            return new TreeSet<>(REVISION_COMPARATOR);
+    protected static final Comparator<Module> REVISION_COMPARATOR = (o1, o2) -> {
+        if (o2.getRevision() == null) {
+            return -1;
         }
-    };
-
-    protected static final Comparator<Module> REVISION_COMPARATOR = new Comparator<Module>() {
-        @Override
-        public int compare(final Module o1, final Module o2) {
-            if (o2.getRevision() == null) {
-                return -1;
-            }
 
-            return o2.getRevision().compareTo(o1.getRevision());
-        }
+        return o2.getRevision().compareTo(o1.getRevision());
     };
 
+    protected static final Supplier<NavigableSet<Module>> MODULE_SET_SUPPLIER = () -> new TreeSet<>(REVISION_COMPARATOR);
+
     /**
      * @return yang sources where key is ModuleIdentifier
      */
index 7794efefadc60191c081ef49ad22cccfbc66928e..7f55295465c586afec4228f49cc0ee55cf66480e 100644 (file)
@@ -28,27 +28,10 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
 public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
 
-    private static final Predicate<StmtContext<?, ?, ?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE = new Predicate<StmtContext<?, ?, ?>>() {
-        @Override
-        public boolean apply(final StmtContext<?, ?, ?> input) {
-            return input.isSupportedToBuildEffective();
-        }
-    };
-
-    private static final Predicate<StmtContext<?, ?, ?>> IS_UNKNOWN_STATEMENT_CONTEXT = new Predicate<StmtContext<?, ?, ?>>() {
-        @Override
-        public boolean apply(final StmtContext<?, ?, ?> input) {
-            return StmtContextUtils.isUnknownStatement(input);
-        }
-    };
-
-    private static final Predicate<StatementContextBase<?, ?, ?>> ARE_FEATURES_SUPPORTED = new Predicate<StatementContextBase<?, ?, ?>>() {
-
-        @Override
-        public boolean apply(final StatementContextBase<?, ?, ?> input) {
-            return StmtContextUtils.areFeaturesSupported(input);
-        }
-    };
+    private static final Predicate<StmtContext<?, ?, ?>> IS_UNKNOWN_STATEMENT_CONTEXT =
+            StmtContextUtils::isUnknownStatement;
+    private static final Predicate<StmtContext<?, ?, ?>> IS_NOT_UNKNOWN_STATEMENT_CONTEXT =
+            Predicates.not(IS_UNKNOWN_STATEMENT_CONTEXT);
 
     private final List<? extends EffectiveStatement<?, ?>> substatements;
     private final List<StatementContextBase<?, ?, ?>> unknownSubstatementsToBuild;
@@ -75,7 +58,7 @@ public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
         final Collection<StatementContextBase<?, ?, ?>> substatementsInit = new ArrayList<>();
 
         final Collection<StatementContextBase<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
-                ctx.declaredSubstatements(), ARE_FEATURES_SUPPORTED);
+                ctx.declaredSubstatements(), StmtContextUtils::areFeaturesSupported);
         for (final StatementContextBase<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
             if (declaredSubstatement.getPublicDefinition().equals(Rfc6020Mapping.USES)) {
                 substatementsInit.add(declaredSubstatement);
@@ -89,12 +72,11 @@ public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
         substatementsInit.addAll(effectiveSubstatements);
 
         Collection<StatementContextBase<?, ?, ?>> substatementsToBuild = Collections2.filter(substatementsInit,
-                IS_SUPPORTED_TO_BUILD_EFFECTIVE);
+            StmtContext::isSupportedToBuildEffective);
         if (!buildUnknownSubstatements) {
             this.unknownSubstatementsToBuild = ImmutableList.copyOf(Collections2.filter(substatementsToBuild,
                     IS_UNKNOWN_STATEMENT_CONTEXT));
-            substatementsToBuild = Collections2.filter(substatementsToBuild,
-                    Predicates.not(IS_UNKNOWN_STATEMENT_CONTEXT));
+            substatementsToBuild = Collections2.filter(substatementsToBuild, IS_NOT_UNKNOWN_STATEMENT_CONTEXT);
         } else {
             this.unknownSubstatementsToBuild = ImmutableList.of();
         }
index 277114de1ac45725a7fe892cf9c14cb1349e0367..5e3ab5eaabf926f71a22c701e1a682c394f15d54 100644 (file)
@@ -32,34 +32,14 @@ import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
  */
 @Beta
 public final class ASTSchemaSource implements SchemaSourceRepresentation {
-    public static final Function<ASTSchemaSource, SourceIdentifier> GET_IDENTIFIER = new Function<ASTSchemaSource, SourceIdentifier>() {
-        @Override
-        public SourceIdentifier apply(@Nonnull final ASTSchemaSource input) {
-            Preconditions.checkNotNull(input);
-            return input.getIdentifier();
-        }
-    };
-    public static final Function<ASTSchemaSource, SourceIdentifier> GET_SEMVER_IDENTIFIER = new Function<ASTSchemaSource, SourceIdentifier>() {
-        @Override
-        public SemVerSourceIdentifier apply(@Nonnull final ASTSchemaSource input) {
-            Preconditions.checkNotNull(input);
-            return input.getSemVerIdentifier();
-        }
-    };
-    public static final Function<ASTSchemaSource, YangModelDependencyInfo> GET_DEPINFO = new Function<ASTSchemaSource, YangModelDependencyInfo>() {
-        @Override
-        public YangModelDependencyInfo apply(@Nonnull final ASTSchemaSource input) {
-            Preconditions.checkNotNull(input);
-            return input.getDependencyInformation();
-        }
-    };
-    public static final Function<ASTSchemaSource, ParserRuleContext> GET_AST = new Function<ASTSchemaSource, ParserRuleContext>() {
-        @Override
-        public ParserRuleContext apply(@Nonnull final ASTSchemaSource input) {
-            Preconditions.checkNotNull(input);
-            return input.getAST();
-        }
-    };
+    @Deprecated
+    public static final Function<ASTSchemaSource, SourceIdentifier> GET_IDENTIFIER = ASTSchemaSource::getIdentifier;
+    @Deprecated
+    public static final Function<ASTSchemaSource, SourceIdentifier> GET_SEMVER_IDENTIFIER = ASTSchemaSource::getSemVerIdentifier;
+    @Deprecated
+    public static final Function<ASTSchemaSource, YangModelDependencyInfo> GET_DEPINFO = ASTSchemaSource::getDependencyInformation;
+    @Deprecated
+    public static final Function<ASTSchemaSource, ParserRuleContext> GET_AST = ASTSchemaSource::getAST;
 
     private final YangModelDependencyInfo depInfo;
     private final ParserRuleContext tree;