*/
package org.opendaylight.yangtools.yang.data.util;
-import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
-import java.util.HashSet;
+import com.google.common.collect.Iterables;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import javax.annotation.Nullable;
+import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
/**
* Schema derived data providing necessary information for mapping between
* Find a child node identifier by its {@link PathArgument}.
*
* @param child Child path argument
- * @return
+ * @return A child node, or null if not found
*/
- @Nullable public abstract DataSchemaContextNode<?> getChild(PathArgument child);
+ public abstract @Nullable DataSchemaContextNode<?> getChild(PathArgument child);
- @Nullable public abstract DataSchemaContextNode<?> getChild(QName child);
+ public abstract @Nullable DataSchemaContextNode<?> getChild(QName child);
- @Nullable public DataSchemaNode getDataSchemaNode() {
+ public @Nullable DataSchemaNode getDataSchemaNode() {
return dataSchemaNode;
}
}
static DataSchemaNode findChildSchemaNode(final DataNodeContainer parent, final QName child) {
- DataSchemaNode potential = parent.getDataChildByName(child);
- if (potential == null) {
- Iterable<ChoiceSchemaNode> choices = FluentIterable.from(
- parent.getChildNodes()).filter(ChoiceSchemaNode.class);
- potential = findChoice(choices, child);
- }
- return potential;
+ final DataSchemaNode potential = parent.getDataChildByName(child);
+ return potential == null ? findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child)
+ : potential;
}
static DataSchemaContextNode<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
- DataSchemaNode result = findChildSchemaNode(schema, child);
+ final DataSchemaNode result = findChildSchemaNode(schema, child);
// We try to look up if this node was added by augmentation
if (result != null && schema instanceof DataSchemaNode && result.isAugmenting()) {
return fromAugmentation(schema, (AugmentationTarget) schema, result);
return null;
}
- public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchemaNode augmentation) {
- ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder();
- for (DataSchemaNode child : augmentation.getChildNodes()) {
- potentialChildren.add(child.getQName());
- }
- return new AugmentationIdentifier(potentialChildren.build());
- }
-
- static DataNodeContainer augmentationProxy(final AugmentationSchemaNode augmentation,
- final DataNodeContainer schema) {
- Set<DataSchemaNode> children = new HashSet<>();
- for (DataSchemaNode augNode : augmentation.getChildNodes()) {
- children.add(schema.getDataChildByName(augNode.getQName()));
- }
- return new EffectiveAugmentationSchema(augmentation, children);
+ /**
+ * Create AugmentationIdentifier from an AugmentationSchemaNode.
+ *
+ * @param schema Augmentation schema
+ * @return AugmentationIdentifier for the schema
+ * @throws NullPointerException if {@code schema} is null
+ */
+ public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchemaNode schema) {
+ return new AugmentationIdentifier(schema.getChildNodes().stream().map(DataSchemaNode::getQName)
+ .collect(Collectors.toSet()));
}
/**
* DataContextNodeOperation for child as call for
* {@link #fromDataSchemaNode(DataSchemaNode)}.
*/
- @Nullable static DataSchemaContextNode<?> fromAugmentation(final DataNodeContainer parent,
+ static @Nullable DataSchemaContextNode<?> fromAugmentation(final DataNodeContainer parent,
final AugmentationTarget parentAug, final DataSchemaNode child) {
- AugmentationSchemaNode augmentation = null;
for (AugmentationSchemaNode aug : parentAug.getAvailableAugmentations()) {
- DataSchemaNode potential = aug.getDataChildByName(child.getQName());
- if (potential != null) {
- augmentation = aug;
- break;
+ if (aug.findDataChildByName(child.getQName()).isPresent()) {
+ return new AugmentationContextNode(aug, parent);
}
}
- if (augmentation != null) {
- return new AugmentationContextNode(augmentation, parent);
- }
return fromDataSchemaNode(child);
}
- @Nullable public static DataSchemaContextNode<?> fromDataSchemaNode(final DataSchemaNode potential) {
+ public static @Nullable DataSchemaContextNode<?> fromDataSchemaNode(final DataSchemaNode potential) {
if (potential instanceof ContainerSchemaNode) {
return new ContainerContextNode((ContainerSchemaNode) potential);
} else if (potential instanceof ListSchemaNode) {