X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=model%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Futil%2FEffectiveAugmentationSchema.java;h=30f54f7c07609a092b1a5d2b17034ced5802cf4d;hb=5fdd7a708740b9eea3a888bf86b979a75829c1a7;hp=5c4a8598a165e23b78dafbc7f999df6c32e00c2f;hpb=81f38342831f259f93e0d35f3f1ddc6f0e90b91f;p=yangtools.git diff --git a/model/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java b/model/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java index 5c4a8598a1..30f54f7c07 100644 --- a/model/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java +++ b/model/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java @@ -10,13 +10,8 @@ package org.opendaylight.yangtools.yang.model.util; import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import java.util.Optional; -import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ActionDefinition; import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; @@ -56,43 +51,24 @@ import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBo */ // FIXME: YANGTOOLS-1403: this functionality should be integrated into EffectiveAugmentStatement/AugmentationSchemaNode public final class EffectiveAugmentationSchema implements AugmentationSchemaNode { + private final ImmutableMap children; private final AugmentationSchemaNode delegate; - private final ImmutableSet realChildSchemas; - private final ImmutableMap mappedChildSchemas; - public EffectiveAugmentationSchema(final AugmentationSchemaNode augmentSchema, - final Collection realChildSchemas) { - delegate = requireNonNull(augmentSchema); - this.realChildSchemas = ImmutableSet.copyOf(realChildSchemas); + public EffectiveAugmentationSchema(final AugmentationSchemaNode augment, final DataNodeContainer target) { + delegate = requireNonNull(augment); - final Map m = new HashMap<>(realChildSchemas.size()); - for (DataSchemaNode realChildSchema : realChildSchemas) { - m.put(realChildSchema.getQName(), realChildSchema); - } - - mappedChildSchemas = ImmutableMap.copyOf(m); - } - - /** - * Returns an AugmentationSchemaNode as effective in a parent node. - * - * @param schema Augmentation schema - * @param parent Parent schema - * @return Adjusted Augmentation schema - * @throws NullPointerException if any of the arguments is null - */ - // FIXME: 8.0.0: integrate this method into the constructor - public static AugmentationSchemaNode create(final AugmentationSchemaNode schema, final DataNodeContainer parent) { - final Set children = new HashSet<>(); - for (DataSchemaNode augNode : schema.getChildNodes()) { + final var augmentChildren = augment.getChildNodes(); + final var builder = ImmutableMap.builderWithExpectedSize(augmentChildren.size()); + for (var augChild : augmentChildren) { // parent may have the corresponding child removed via 'deviate unsupported', i.e. the child is effectively // not present at the target site - final DataSchemaNode child = parent.dataChildByName(augNode.getQName()); - if (child != null) { - children.add(child); + final var qname = augChild.getQName(); + final var targetChild = target.dataChildByName(qname); + if (targetChild != null) { + builder.put(qname, targetChild); } } - return new EffectiveAugmentationSchema(schema, children); + children = builder.build(); } @Override @@ -127,7 +103,7 @@ public final class EffectiveAugmentationSchema implements AugmentationSchemaNode @Override public Collection getChildNodes() { - return realChildSchemas; + return children.values(); } @Override @@ -137,7 +113,7 @@ public final class EffectiveAugmentationSchema implements AugmentationSchemaNode @Override public DataSchemaNode dataChildByName(final QName name) { - return mappedChildSchemas.get(requireNonNull(name)); + return children.get(requireNonNull(name)); } @Override