import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
/**
- * A simple capture of an {@link EffectiveModelContext} and a list of {@link EffectiveStatement}s. No further guarantees
- * are made.
+ * A simple capture of an {@link AbstractEffectiveModelContextProvider} and {@link EffectiveStatementInference}s.
*
* @param T constituent {@link EffectiveStatement} type
*/
@Beta
public abstract class AbstractEffectiveStatementInference<T extends EffectiveStatement<?, ?>>
extends AbstractEffectiveModelContextProvider implements EffectiveStatementInference {
- private final @NonNull List<T> path;
-
- protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext,
- final @NonNull ImmutableList<T> path) {
+ protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext) {
super(modelContext);
- this.path = requireNonNull(path);
- }
-
- protected AbstractEffectiveStatementInference(final @NonNull EffectiveModelContext modelContext,
- final @NonNull List<? extends T> path) {
- super(modelContext);
- this.path = ImmutableList.copyOf(path);
}
@Override
- public final List<T> statementPath() {
- return path;
- }
+ public abstract List<T> statementPath();
- @Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return super.addToStringAttributes(helper).add("statements", path);
+ /**
+ * A simple capture of an {@link AbstractEffectiveStatementInference} and a list of {@link EffectiveStatement}s. No
+ * further guarantees are made.
+ *
+ * @param T constituent {@link EffectiveStatement} type
+ */
+ @Beta
+ public abstract static class WithPath<T extends EffectiveStatement<?, ?>>
+ extends AbstractEffectiveStatementInference<T> {
+ private final @NonNull List<T> path;
+
+ protected WithPath(final @NonNull EffectiveModelContext modelContext, final @NonNull ImmutableList<T> path) {
+ super(modelContext);
+ this.path = requireNonNull(path);
+ }
+
+ protected WithPath(final @NonNull EffectiveModelContext modelContext, final @NonNull List<? extends T> path) {
+ super(modelContext);
+ this.path = ImmutableList.copyOf(path);
+ }
+
+ @Override
+ public final List<T> statementPath() {
+ return path;
+ }
+
+ @Override
+ protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ return super.addToStringAttributes(helper).add("path", path);
+ }
}
}
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.spi.AbstractEffectiveStatementInference.WithPath;
/**
* Default implementation of a a {@link SchemaTreeInference}. Guaranteed to be consistent with its
*/
@Beta
@NonNullByDefault
-public final class DefaultSchemaTreeInference
- extends AbstractEffectiveStatementInference<SchemaTreeEffectiveStatement<?>> implements SchemaTreeInference {
+public final class DefaultSchemaTreeInference extends WithPath<SchemaTreeEffectiveStatement<?>>
+ implements SchemaTreeInference {
private DefaultSchemaTreeInference(final EffectiveModelContext modelContext,
final ImmutableList<SchemaTreeEffectiveStatement<?>> path) {
super(modelContext, path);
*/
@Beta
public static final class Inference extends AbstractEffectiveStatementInference<EffectiveStatement<?, ?>> {
+ private final ArrayDeque<EffectiveStatement<?, ?>> deque;
private final ModuleEffectiveStatement currentModule;
private final int groupingDepth;
private final boolean clean;
- Inference(final @NonNull EffectiveModelContext modelContext,
- final Iterator<? extends EffectiveStatement<?, ?>> path,
+ Inference(final @NonNull EffectiveModelContext modelContext, final ArrayDeque<EffectiveStatement<?, ?>> deque,
final ModuleEffectiveStatement currentModule, final int groupingDepth, final boolean clean) {
- super(modelContext, ImmutableList.copyOf(path));
+ super(modelContext);
+ this.deque = requireNonNull(deque);
this.currentModule = currentModule;
this.groupingDepth = groupingDepth;
this.clean = clean;
}
+ @Override
+ public List<EffectiveStatement<?, ?>> statementPath() {
+ return ImmutableList.copyOf(deque.descendingIterator());
+ }
+
/**
* Convert this inference into a {@link SchemaInferenceStack}.
*
* @return A new stack
*/
public @NonNull SchemaInferenceStack toSchemaInferenceStack() {
- final List<EffectiveStatement<?, ?>> path = statementPath();
- final ArrayDeque<EffectiveStatement<?, ?>> deque = new ArrayDeque<>(path.size());
- path.forEach(deque::push);
-
return new SchemaInferenceStack(getEffectiveModelContext(), deque, currentModule, groupingDepth, clean);
}
}
final ArrayDeque<EffectiveStatement<?, ?>> deque, final ModuleEffectiveStatement currentModule,
final int groupingDepth, final boolean clean) {
this.effectiveModel = requireNonNull(effectiveModel);
- this.deque = requireNonNull(deque);
+ this.deque = deque.clone();
this.currentModule = currentModule;
this.groupingDepth = groupingDepth;
this.clean = clean;
* @return An {@link Inference}
*/
public @NonNull Inference toInference() {
- return new Inference(effectiveModel, deque.descendingIterator(), currentModule, groupingDepth, clean);
+ return new Inference(effectiveModel, deque.clone(), currentModule, groupingDepth, clean);
}
/**