Refactor InferenceAction
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / AbstractDeclaredStatement.java
index 01ca5602f583e2dfd4c43bad5384fa11109d0baf..f1316ddd15e2ca8f8b350cae6a7a46a4c64281ed 100644 (file)
@@ -5,14 +5,15 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.Collections2;
-import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.util.Collection;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
@@ -24,31 +25,26 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
  * @param <A> Argument type.
  */
 public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<A> {
-
-
     private final A argument;
     private final String rawArgument;
     private final ImmutableList<? extends DeclaredStatement<?>> substatements;
     private final StatementDefinition definition;
     private final StatementSource source;
 
-    protected AbstractDeclaredStatement(StmtContext<A,?,?> context) {
+    protected AbstractDeclaredStatement(final StmtContext<A,?,?> context) {
         rawArgument = context.rawStatementArgument();
         argument = context.getStatementArgument();
         source = context.getStatementSource();
         definition = context.getPublicDefinition();
         /*
-         *  Collections.transform could not be used here, since it is lazily
-         *  transformed and retains pointer to original collection, which may
-         *  contains references to mutable context.
-         *
-         *  FluentIterable.tranform().toList() - actually performs transformation
-         *  and creates immutable list from transformed results.
+         * Perform an explicit copy, because Collections2.transform() is lazily transformed and retains pointer to
+         * original collection, which may contains references to mutable context.
          */
-        substatements = FluentIterable.from(context.declaredSubstatements()).transform(StmtContextUtils.buildDeclared()).toList();
+        substatements = ImmutableList.copyOf(Collections2.transform(context.declaredSubstatements(),
+            StmtContext::buildDeclared));
     }
 
-    protected final <S extends DeclaredStatement<?>> S firstDeclared(Class<S> type) {
+    protected final <S extends DeclaredStatement<?>> S firstDeclared(final Class<S> type) {
         return type.cast(Iterables.find(substatements, Predicates.instanceOf(type)));
     }
 
@@ -62,23 +58,26 @@ public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<
         return argument;
     }
 
+    @Nonnull
     @Override
     public StatementDefinition statementDefinition() {
         return definition;
     }
 
+    @Nonnull
     @Override
     public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
         return substatements;
     }
 
+    @Nonnull
     @Override
     public StatementSource getStatementSource() {
         return source;
     }
 
     @SuppressWarnings("unchecked")
-    protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(Class<S> type) {
-        return Collection.class.cast(Collections2.filter(substatements,Predicates.instanceOf(type)));
+    protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(final Class<S> type) {
+        return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type)));
     }
 }