private static Optional<NormalizedNode<?, ?>> getChild( final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container, final PathArgument identifier) { return container == null ? Optional.empty() : container.getChild(identifier); }
private static Optional<NormalizedNode<?, ?>> getChild( final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container, final PathArgument identifier) { return container == null ? Optional.empty() : container.getChild(identifier); }
static TreeNode getChildFromData(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data, final PathArgument childId, final Version version) { final Optional<NormalizedNode<?, ?>> child = data.getChild(childId); return child.isPresent() ? TreeNodeFactory.createTreeNode(child.get(), version) : null; } }
@Override public DataTreeCandidateNode getModifiedChild(final PathArgument childIdentifier) { if (data instanceof NormalizedNodeContainer) { @SuppressWarnings({ "rawtypes", "unchecked" }) final Optional<? extends NormalizedNode<?, ?>> child = ((NormalizedNodeContainer)data).getChild(childIdentifier); return child.map(input -> new NormalizedNodeDataTreeCandidateNode(input)).orElse(null); } return null; }
static TreeNode getChildFromData(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data, final PathArgument childId, final Version version) { final Optional<NormalizedNode<?, ?>> child = data.getChild(childId); return child.isPresent() ? TreeNodeFactory.createTreeNode(child.get(), version) : null; } }
@Override public DataTreeCandidateNode getModifiedChild(final PathArgument childIdentifier) { if (data instanceof NormalizedNodeContainer) { @SuppressWarnings({ "rawtypes", "unchecked" }) final Optional<? extends NormalizedNode<?, ?>> child = ((NormalizedNodeContainer)data).getChild(childIdentifier); return child.map(input -> new NormalizedNodeDataTreeCandidateNode(input)).orElse(null); } return null; }
@Override public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) { final Optional<NormalizedNode<?, ?>> potential = getData().getChild(identifier); if (potential.isPresent()) { return createChild(potential.get()); } return null; }
@Override public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) { final Optional<NormalizedNode<?, ?>> potential = getData().getChild(identifier); if (potential.isPresent()) { return createChild(potential.get()); } return null; }
private Object getAugmentationImpl(final Class<?> cls) { final ImmutableMap<Class<? extends Augmentation<?>>, Augmentation<?>> aug = cachedAugmentations; if (aug != null) { return aug.get(cls); } Preconditions.checkNotNull(cls,"Supplied augmentation must not be null."); @SuppressWarnings({"unchecked","rawtypes"}) final Optional<DataContainerCodecContext<?,?>> augCtx = context.possibleStreamChild((Class) cls); if (augCtx.isPresent()) { final Optional<NormalizedNode<?, ?>> augData = data.getChild(augCtx.get().getDomPathArgument()); if (augData.isPresent()) { return augCtx.get().deserialize(augData.get()); } } return null; }
@SuppressWarnings("rawtypes") @Nullable Object getBindingChildValue(final String method, final NormalizedNodeContainer domData) { final NodeCodecContext<?> childContext = verifyNotNull(byMethod.get(method), "Cannot find data handler for method %s", method).get(); @SuppressWarnings("unchecked") final Optional<NormalizedNode<?, ?>> domChild = domData.getChild(childContext.getDomPathArgument()); // We do not want to use Optional.map() here because we do not want to invoke defaultObject() when we have // normal value because defaultObject() may end up throwing an exception intentionally. return domChild.isPresent() ? childContext.deserializeObject(domChild.get()) : childContext.defaultObject(); }
private Object getAugmentationImpl(final Class<?> cls) { requireNonNull(cls, "Supplied augmentation must not be null."); final ImmutableMap<Class<? extends Augmentation<?>>, Augmentation<?>> aug = cachedAugmentations; if (aug != null) { return aug.get(cls); } @SuppressWarnings({"unchecked","rawtypes"}) final Optional<DataContainerCodecContext<?, ?>> optAugCtx = context.possibleStreamChild((Class) cls); if (optAugCtx.isPresent()) { final DataContainerCodecContext<?, ?> augCtx = optAugCtx.get(); // Due to binding specification not representing grouping instantiations we can end up having the same // augmentation applied to a grouping multiple times. While these augmentations have the same shape, they // are still represented by distinct binding classes and therefore we need to make sure the result matches // the augmentation the user is requesting -- otherwise a strict receiver would end up with a cryptic // ClassCastException. if (cls.isAssignableFrom(augCtx.getBindingClass())) { final Optional<NormalizedNode<?, ?>> augData = data.getChild(augCtx.getDomPathArgument()); if (augData.isPresent()) { return augCtx.deserialize(augData.get()); } } } return null; }
@SuppressWarnings("rawtypes") public Object getBindingChildValue(final Method method, final NormalizedNodeContainer domData) { final NodeCodecContext<?> childContext = byMethod.get(method).get(); @SuppressWarnings("unchecked") final Optional<NormalizedNode<?, ?>> domChild = domData.getChild(childContext.getDomPathArgument()); if (domChild.isPresent()) { return childContext.deserializeObject(domChild.get()); } else if (childContext instanceof LeafNodeCodecContext) { return ((LeafNodeCodecContext)childContext).defaultObject(); } else { return null; } }
for (NormalizedNode<?, ?> child : newData.getValue()) { final DataTreeCandidateNode node; final Optional<NormalizedNode<?, ?>> maybeOldChild = oldData.getChild(child.getIdentifier()); if (!newData.getChild(child.getIdentifier()).isPresent()) { result.add(AbstractRecursiveCandidateNode.deleteNode(child));
final Optional<NormalizedNode<?, ?>> childData = ((NormalizedNodeContainer)value).getChild(child); if (childData.isPresent()) { childOper.mergeIntoModifiedNode(newlyCreated, childData.get(), modVersion);
final Optional<NormalizedNode<?, ?>> childData = ((NormalizedNodeContainer)value).getChild(child); if (childData.isPresent()) { childOper.mergeIntoModifiedNode(newlyCreated, childData.get(), modVersion);
@Override @SuppressWarnings("rawtypes") public final void writeToCurrent(final NormalizedNodeContainer<?, ?, ?> data) { // write the entire thing into the cursor write(data.getIdentifier(), data); // write the children with subshard check and subshard write if we are going into subshard cursor.enter(data.getIdentifier()); for (NormalizedNode<?, ?> writtenChild : data.getValue()) { write(writtenChild.getIdentifier(), writtenChild); } // Delete step - remove subshard data that was written into current shard // delete from current node.getChildrenWithSubshards().entrySet() .stream().filter(entry -> entry.getValue() instanceof WriteableSubshardBoundaryNode).forEach(entry -> { @SuppressWarnings("unchecked") Optional<NormalizedNode<?, ?>> writtenValue = ((NormalizedNodeContainer) data).getChild(entry.getKey()); if (writtenValue.isPresent()) { // delete from current cursor.delete(entry.getKey()); } }); cursor.exit(); } }
@SuppressWarnings("unchecked") public Map<Class<? extends Augmentation<?>>, Augmentation<?>> getAllAugmentationsFrom( final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) { @SuppressWarnings("rawtypes") final Map map = new HashMap<>(); for (final NormalizedNode<?, ?> childValue : data.getValue()) { if (childValue instanceof AugmentationNode) { final AugmentationNode augDomNode = (AugmentationNode) childValue; final DataContainerCodecPrototype<?> codecProto = yangAugmentationChild(augDomNode.getIdentifier()); if (codecProto != null) { final DataContainerCodecContext<?, ?> codec = codecProto.get(); map.put(codec.getBindingClass(), codec.deserializeObject(augDomNode)); } } } for (final DataContainerCodecPrototype<?> value : byStreamAugmented.values()) { final Optional<NormalizedNode<?, ?>> augData = data.getChild(value.getYangArg()); if (augData.isPresent()) { map.put(value.getBindingClass(), value.get().deserializeObject(augData.get())); } } return map; }
@SuppressWarnings("unchecked") Map<Class<? extends Augmentation<?>>, Augmentation<?>> getAllAugmentationsFrom( final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) { @SuppressWarnings("rawtypes") final Map map = new HashMap<>(); for (final NormalizedNode<?, ?> childValue : data.getValue()) { if (childValue instanceof AugmentationNode) { final AugmentationNode augDomNode = (AugmentationNode) childValue; final DataContainerCodecPrototype<?> codecProto = yangAugmentationChild(augDomNode.getIdentifier()); if (codecProto != null) { final DataContainerCodecContext<?, ?> codec = codecProto.get(); map.put(codec.getBindingClass(), codec.deserializeObject(augDomNode)); } } } for (final DataContainerCodecPrototype<?> value : augmentations.byStream.values()) { final Optional<NormalizedNode<?, ?>> augData = data.getChild(value.getYangArg()); if (augData.isPresent()) { map.put(value.getBindingClass(), value.get().deserializeObject(augData.get())); } } return map; }
@Override public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) { switch (mod.getModificationType()) { case APPEARED: case DISAPPEARED: case SUBTREE_MODIFIED: final Optional<ModifiedNode> childMod = mod.getChild(identifier); if (childMod.isPresent()) { return childNode(childMod.get()); } return null; case UNMODIFIED: if (!canHaveChildren(oldMeta, newMeta)) { return null; } final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta) .getChild(identifier); return maybeChild.isPresent() ? AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get()) : null; case DELETE: case WRITE: if (!canHaveChildren(oldMeta, newMeta)) { return null; } return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta), identifier); default: throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); } }
@Override public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) { switch (mod.getModificationType()) { case APPEARED: case DISAPPEARED: case SUBTREE_MODIFIED: final Optional<ModifiedNode> childMod = mod.getChild(identifier); if (childMod.isPresent()) { return childNode(childMod.get()); } return null; case UNMODIFIED: if (!canHaveChildren(oldMeta, newMeta)) { return null; } final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta) .getChild(identifier); return maybeChild.isPresent() ? AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get()) : null; case DELETE: case WRITE: if (!canHaveChildren(oldMeta, newMeta)) { return null; } return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta), identifier); default: throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); } }