private boolean compareInstanceIdentifierTail(InstanceIdentifier<?> identifier1, InstanceIdentifier<?> identifier2) { return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments())); } }
private boolean compareInstanceIdentifierTail(InstanceIdentifier<?> identifier1, InstanceIdentifier<?> identifier2) { return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments())); }
private static Collection<Class<?>> decompose(final InstanceIdentifier<?> path) { return ImmutableSet.copyOf(Iterators.transform(path.getPathArguments().iterator(), PathArgument::getType)); }
/** * Verifies that all requested key parts have keys */ private boolean isUniqueKeyConstructable(final InstanceIdentifier<?> actualContextIdentifier) { return StreamSupport.stream(actualContextIdentifier.getPathArguments().spliterator(), false) .filter(this::isAdditionalScope) .filter(this::isIdentifiable) .count() == additionalKeyTypes.size(); }
private String additionalKeys(final InstanceIdentifier<?> actualContextIdentifier) { return StreamSupport.stream(actualContextIdentifier.getPathArguments().spliterator(), false) .filter(this::isAdditionalScope) .filter(this::isIdentifiable) .map(IdentifiableItem.class::cast) .map(TypeAwareIdentifierCacheKeyFactory::bindKeyString) .collect(Collectors.joining(KEY_PARTS_SEPARATOR)); } }
public DataContainerCodecContext<?,?> getCodecContextNode(final InstanceIdentifier<?> binding, final List<YangInstanceIdentifier.PathArgument> builder) { DataContainerCodecContext<?,?> currentNode = root; for (final InstanceIdentifier.PathArgument bindingArg : binding.getPathArguments()) { currentNode = currentNode.bindingPathArgumentChild(bindingArg, builder); checkArgument(currentNode != null, "Supplied Instance Identifier %s is not valid.", binding); } return currentNode; }
public BindingDOMDataTreeWriteCursorAdapter(final DataTreeIdentifier<?> path, final T delegate, final BindingToNormalizedNodeCodec codec) { super(codec, delegate); path.getRootIdentifier().getPathArguments().forEach(stack::push); }
private static Collection<Class<?>> decompose(final InstanceIdentifier<?> path) { final Set<Class<?>> clazzes = new HashSet<>(); for(final InstanceIdentifier.PathArgument arg : path.getPathArguments()) { clazzes.add(arg.getType()); } return clazzes; }
private boolean isPathEqual(@Nonnull final InstanceIdentifier<?> iid, final InstanceIdentifier<?> childIiD) { // Verifying path because the same type can be used in several places. Iterator<InstanceIdentifier.PathArgument> pathArguments = iid.getPathArguments().iterator(); for (final InstanceIdentifier.PathArgument pathArgument : childIiD.getPathArguments()) { if (!pathArguments.hasNext() || !pathArgument.getType().equals(pathArguments.next().getType())) { return false; } } return true; }
/** * Transform a keyed instance identifier into a wildcarded one. * <p/> * ! This has to be called also for wildcarded List instance identifiers * due to weird behavior of equals in InstanceIdentifier ! */ @SuppressWarnings("unchecked") public static <D extends DataObject> InstanceIdentifier<D> makeIidWildcarded(final InstanceIdentifier<D> id) { final List<InstanceIdentifier.PathArgument> transformedPathArguments = StreamSupport.stream(id.getPathArguments().spliterator(), false) .map(RWUtils::cleanPathArgumentFromKeys) .collect(Collectors.toList()); return (InstanceIdentifier<D>) InstanceIdentifier.create(transformedPathArguments); }
@Nonnull @Override public Optional<? extends DataObject> read(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final ReadContext ctx) throws ReadFailedException { final InstanceIdentifier.PathArgument first = checkNotNull( Iterables.getFirst(id.getPathArguments(), null), "Empty id"); final Reader<? extends DataObject, ? extends Builder<?>> reader = rootReaders.get(first.getType()); checkNotNull(reader, "Read failed. Missing reader for %s. Current readers for: %s", id, rootReaders.keySet()); LOG.debug("Reading from delegate: {}", reader); return reader.read(id, ctx); }
/** * Replace last item in ID with a provided IdentifiableItem of the same type. */ @SuppressWarnings("unchecked") @Nonnull public static <D extends DataObject & Identifiable<K>, K extends Identifier<D>> InstanceIdentifier<D> replaceLastInId( @Nonnull final InstanceIdentifier<D> id, final InstanceIdentifier.IdentifiableItem<D, K> currentBdItem) { final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); final Iterable<InstanceIdentifier.PathArgument> withoutCurrent = Iterables.limit(pathArguments, Iterables.size(pathArguments) - 1); final Iterable<InstanceIdentifier.PathArgument> concat = Iterables.concat(withoutCurrent, Collections.singleton(currentBdItem)); return (InstanceIdentifier<D>) InstanceIdentifier.create(concat); }
SubtreeReader(final Reader<D, B> delegate, Set<InstanceIdentifier<?>> handledTypes) { this.delegate = delegate; for (InstanceIdentifier<?> handledType : handledTypes) { // Iid has to start with Reader's handled root type checkArgument(delegate.getManagedDataObjectType().getTargetType().equals( handledType.getPathArguments().iterator().next().getType()), "Handled node from subtree has to be identified by an instance identifier starting from: %s." + "Instance identifier was: %s", getManagedDataObjectType().getTargetType(), handledType); checkArgument(Iterables.size(handledType.getPathArguments()) > 1, "Handled node from subtree identifier too short: %s", handledType); handledChildTypes.add(InstanceIdentifier.create(Iterables.concat( getManagedDataObjectType().getPathArguments(), Iterables.skip(handledType.getPathArguments(), 1)))); } }
private SubtreeWriter(final Writer<D> delegate, final Set<InstanceIdentifier<?>> handledTypes) { this.delegate = delegate; for (InstanceIdentifier<?> handledType : handledTypes) { // Iid has to start with writer's handled root type checkArgument(delegate.getManagedDataObjectType().getTargetType().equals( handledType.getPathArguments().iterator().next().getType()), "Handled node from subtree has to be identified by an instance identifier starting from: %s." + "Instance identifier was: %s", getManagedDataObjectType().getTargetType(), handledType); checkArgument(Iterables.size(handledType.getPathArguments()) > 1, "Handled node from subtree identifier too short: %s", handledType); handledChildTypes.add(InstanceIdentifier.create(Iterables.concat( getManagedDataObjectType().getPathArguments(), Iterables.skip(handledType.getPathArguments(), 1)))); } }
private NodeId getNodeId(final Map.Entry<InstanceIdentifier<?>, DataObject> entry) { NodeId nodeId = null; for (InstanceIdentifier.PathArgument pathArgument : entry.getKey().getPathArguments()) { if (pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?>) { final Identifier key = ((InstanceIdentifier.IdentifiableItem) pathArgument).getKey(); if (key instanceof NodeKey) { nodeId = ((NodeKey) key).getNodeId(); } } } return nodeId; }
/** * Find next item in ID after provided type. */ @Nonnull public static InstanceIdentifier.PathArgument getNextId(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final InstanceIdentifier<? extends DataObject> type) { final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); final int i = Iterables.indexOf(pathArguments, input -> input.getType().isAssignableFrom(type.getTargetType())); Preconditions.checkArgument(i >= 0, "Unable to find %s type in %s", type.getTargetType(), id); return Iterables.get(pathArguments, i + 1); }
/** * Trim InstanceIdentifier at indexOf(type). */ @SuppressWarnings("unchecked") @Nonnull public static <D extends DataObject> InstanceIdentifier<D> cutId(@Nonnull final InstanceIdentifier<? extends DataObject> id, @Nonnull final InstanceIdentifier<D> type) { final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); final int i = Iterables.indexOf(pathArguments, input -> input.getType().equals(type.getTargetType())); Preconditions.checkArgument(i >= 0, "ID %s does not contain %s", id, type); return (InstanceIdentifier<D>) InstanceIdentifier.create(Iterables.limit(pathArguments, i + 1)); }
@SuppressWarnings("unchecked") public static <D extends DataObject> InstanceIdentifier<D> appendTypeToId( final InstanceIdentifier<? extends DataObject> parentId, final InstanceIdentifier<D> type) { final InstanceIdentifier.PathArgument t = new InstanceIdentifier.Item<>(type.getTargetType()); return (InstanceIdentifier<D>) InstanceIdentifier.create(Iterables.concat( parentId.getPathArguments(), Collections.singleton(t))); }
/** * Transform a keyed instance identifier into a wildcarded one, keeping keys except the last item. */ @SuppressWarnings("unchecked") public static <D extends DataObject> InstanceIdentifier<D> makeIidLastWildcarded(final InstanceIdentifier<D> id) { final InstanceIdentifier.Item<D> wildcardedItem = new InstanceIdentifier.Item<>(id.getTargetType()); final Iterable<InstanceIdentifier.PathArgument> pathArguments = id.getPathArguments(); return (InstanceIdentifier<D>) InstanceIdentifier.create( Iterables.concat( Iterables.limit(pathArguments, Iterables.size(pathArguments) - 1), Collections.singleton(wildcardedItem))); }
@Override public boolean canProcess(@Nonnull InstanceIdentifier<?> instanceIdentifier) { if (isWildcarded) { final Class<D> parent = delegate.getManagedDataObjectType().getTargetType(); for (InstanceIdentifier.PathArgument pathArgument : instanceIdentifier.getPathArguments()) { if (pathArgument.getType().equals(parent)) { return true; } } return false; } return handledChildTypes.parallelStream() .filter(childIiD -> instanceIdentifier.getTargetType().equals(childIiD.getTargetType())) .anyMatch(instanceIdentifier1 -> isPathEqual(instanceIdentifier, instanceIdentifier1)); }