DeclaredStatements can contain default implementations
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / AbstractDeclaredStatement.java
index 081ed56967a58f5a0af14e4dbc4ce0f52d392cab..cd10de86ca09558d6de0ac9899f5c6fdfb2a5f8e 100644 (file)
@@ -8,10 +8,8 @@
 
 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.ImmutableList;
-import com.google.common.collect.Iterables;
 import java.util.Collection;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
@@ -43,8 +41,16 @@ public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<
             StmtContext::buildDeclared));
     }
 
+    /**
+     * Find first declared substatement of a particular type.
+     *
+     * @param type {@link DeclaredStatement} type
+     * @return First effective substatement, or null if no match is found.
+     * @deprecated Use {@link #findFirstDeclaredSubstatement(Class)} instead.
+     */
+    @Deprecated
     protected final <S extends DeclaredStatement<?>> S firstDeclared(final Class<S> type) {
-        return type.cast(Iterables.find(substatements, Predicates.instanceOf(type)));
+        return findFirstDeclaredSubstatement(type).orElse(null);
     }
 
     @Override
@@ -75,8 +81,17 @@ public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<
         return source;
     }
 
-    @SuppressWarnings("unchecked")
+    /**
+     * Returns collection of explicitly declared child statements, while preserving its original ordering from original
+     * source.
+     *
+     * @param type {@link DeclaredStatement} type
+     * @return Collection of statements, which were explicitly declared in source of model.
+     * @throws NullPointerException if {@code type} is null
+     * @deprecated Use {@link #declaredSubstatements(Class)} instead.
+     */
+    @Deprecated
     protected final <S extends DeclaredStatement<?>> Collection<? extends S> allDeclared(final Class<S> type) {
-        return Collection.class.cast(Collections2.filter(substatements, Predicates.instanceOf(type)));
+        return declaredSubstatements(type);
     }
 }