gpt4 book ai didi

org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.getAncestor()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 16:16:40 27 4
gpt4 key购买 nike

本文整理了Java中org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.getAncestor()方法的一些代码示例,展示了YangInstanceIdentifier.getAncestor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YangInstanceIdentifier.getAncestor()方法的具体详情如下:
包路径:org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
类名称:YangInstanceIdentifier
方法名:getAncestor

YangInstanceIdentifier.getAncestor介绍

[英]Return the ancestor YangInstanceIdentifier with a particular depth, e.g. number of path arguments.
[中]返回具有特定深度的InstanceIdentifier,例如路径参数数。

代码示例

代码示例来源:origin: org.opendaylight.yangtools/yang-data-api

public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final YangInstanceIdentifier path) {
  T current = tree;
  int depth = 1;
  for (PathArgument pathArg : path.getPathArguments()) {
    Optional<T> potential = current.getChild(pathArg);
    if (!potential.isPresent()) {
      throw new IllegalArgumentException(String.format("Child %s is not present in tree.",
          path.getAncestor(depth)));
    }
    current = potential.get();
    ++depth;
  }
  return current;
}

代码示例来源:origin: opendaylight/yangtools

public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final YangInstanceIdentifier path) {
  T current = tree;
  int depth = 1;
  for (PathArgument pathArg : path.getPathArguments()) {
    Optional<T> potential = current.getChild(pathArg);
    if (!potential.isPresent()) {
      throw new IllegalArgumentException(String.format("Child %s is not present in tree.",
          path.getAncestor(depth)));
    }
    current = potential.get();
    ++depth;
  }
  return current;
}

代码示例来源:origin: org.opendaylight.yangtools/yang-data-api

public static <T extends StoreTreeNode<T>> Entry<YangInstanceIdentifier, T> findClosestsOrFirstMatch(final T tree,
    final YangInstanceIdentifier path, final Predicate<T> predicate) {
  Optional<T> parent = Optional.of(tree);
  Optional<T> current = Optional.of(tree);
  int nesting = 0;
  Iterator<PathArgument> pathIter = path.getPathArguments().iterator();
  while (current.isPresent() && pathIter.hasNext() && !predicate.test(current.get())) {
    parent = current;
    current = current.get().getChild(pathIter.next());
    nesting++;
  }
  if (current.isPresent()) {
    final YangInstanceIdentifier currentPath = path.getAncestor(nesting);
    return new SimpleImmutableEntry<>(currentPath, current.get());
  }
  /*
   * Subtracting 1 from nesting level at this point is safe, because we
   * cannot reach here with nesting == 0: that would mean the above check
   * for current.isPresent() failed, which it cannot, as current is always
   * present. At any rate we verify state just to be on the safe side.
   */
  verify(nesting > 0);
  return new SimpleImmutableEntry<>(path.getAncestor(nesting - 1), parent.get());
}

代码示例来源:origin: opendaylight/yangtools

public static <T extends StoreTreeNode<T>> Entry<YangInstanceIdentifier, T> findClosestsOrFirstMatch(final T tree,
    final YangInstanceIdentifier path, final Predicate<T> predicate) {
  Optional<T> parent = Optional.of(tree);
  Optional<T> current = Optional.of(tree);
  int nesting = 0;
  Iterator<PathArgument> pathIter = path.getPathArguments().iterator();
  while (current.isPresent() && pathIter.hasNext() && !predicate.test(current.get())) {
    parent = current;
    current = current.get().getChild(pathIter.next());
    nesting++;
  }
  if (current.isPresent()) {
    final YangInstanceIdentifier currentPath = path.getAncestor(nesting);
    return new SimpleImmutableEntry<>(currentPath, current.get());
  }
  /*
   * Subtracting 1 from nesting level at this point is safe, because we
   * cannot reach here with nesting == 0: that would mean the above check
   * for current.isPresent() failed, which it cannot, as current is always
   * present. At any rate we verify state just to be on the safe side.
   */
  verify(nesting > 0);
  return new SimpleImmutableEntry<>(path.getAncestor(nesting - 1), parent.get());
}

代码示例来源:origin: org.opendaylight.yangtools/yang-data-api

@Nonnull
@Override
public YangInstanceIdentifier getAncestor(final int depth) {
  checkArgument(depth >= 0, "Steps cannot be negative");
  // Calculate how far up our FixedYangInstanceIdentifier ancestor is
  int stackedDepth = 1;
  YangInstanceIdentifier wlk = getParent();
  while (wlk instanceof StackedYangInstanceIdentifier) {
    wlk = wlk.getParent();
    stackedDepth++;
  }
  // Guaranteed to come from FixedYangInstanceIdentifier
  final int fixedDepth = wlk.getPathArguments().size();
  if (fixedDepth >= depth) {
    return wlk.getAncestor(depth);
  }
  // Calculate our depth and check argument
  final int ourDepth = stackedDepth + fixedDepth;
  checkArgument(depth <= ourDepth, "Depth %s exceeds maximum depth %s", depth, ourDepth);
  // Requested depth is covered by the stack, traverse up for specified number of steps
  final int toWalk = ourDepth - depth;
  YangInstanceIdentifier result = this;
  for (int i = 0; i < toWalk; ++i) {
    result = result.getParent();
  }
  return result;
}

代码示例来源:origin: opendaylight/yangtools

@Nonnull
@Override
public YangInstanceIdentifier getAncestor(final int depth) {
  checkArgument(depth >= 0, "Steps cannot be negative");
  // Calculate how far up our FixedYangInstanceIdentifier ancestor is
  int stackedDepth = 1;
  YangInstanceIdentifier wlk = getParent();
  while (wlk instanceof StackedYangInstanceIdentifier) {
    wlk = wlk.getParent();
    stackedDepth++;
  }
  // Guaranteed to come from FixedYangInstanceIdentifier
  final int fixedDepth = wlk.getPathArguments().size();
  if (fixedDepth >= depth) {
    return wlk.getAncestor(depth);
  }
  // Calculate our depth and check argument
  final int ourDepth = stackedDepth + fixedDepth;
  checkArgument(depth <= ourDepth, "Depth %s exceeds maximum depth %s", depth, ourDepth);
  // Requested depth is covered by the stack, traverse up for specified number of steps
  final int toWalk = ourDepth - depth;
  YangInstanceIdentifier result = this;
  for (int i = 0; i < toWalk; ++i) {
    result = result.getParent();
  }
  return result;
}

代码示例来源:origin: org.opendaylight.yangtools/yang-data-impl

private OperationWithModification resolveModificationFor(final YangInstanceIdentifier path) {
  upgradeIfPossible();
  /*
   * Walk the strategy and modification trees in-sync, creating modification nodes as needed.
   *
   * If the user has provided wrong input, we may end up with a bunch of TOUCH nodes present
   * ending with an empty one, as we will throw the exception below. This fact could end up
   * being a problem, as we'd have bunch of phantom operations.
   *
   * That is fine, as we will prune any empty TOUCH nodes in the last phase of the ready
   * process.
   */
  ModificationApplyOperation operation = strategyTree;
  ModifiedNode modification = rootNode;
  int depth = 1;
  for (final PathArgument pathArg : path.getPathArguments()) {
    final Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
    if (!potential.isPresent()) {
      throw new SchemaValidationFailedException(String.format("Child %s is not present in schema tree.",
          path.getAncestor(depth)));
    }
    operation = potential.get();
    ++depth;
    modification = modification.modifyChild(pathArg, operation, version);
  }
  return OperationWithModification.from(operation, modification);
}

代码示例来源:origin: opendaylight/yangtools

private OperationWithModification resolveModificationFor(final YangInstanceIdentifier path) {
  upgradeIfPossible();
  /*
   * Walk the strategy and modification trees in-sync, creating modification nodes as needed.
   *
   * If the user has provided wrong input, we may end up with a bunch of TOUCH nodes present
   * ending with an empty one, as we will throw the exception below. This fact could end up
   * being a problem, as we'd have bunch of phantom operations.
   *
   * That is fine, as we will prune any empty TOUCH nodes in the last phase of the ready
   * process.
   */
  ModificationApplyOperation operation = strategyTree;
  ModifiedNode modification = rootNode;
  int depth = 1;
  for (final PathArgument pathArg : path.getPathArguments()) {
    final Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
    if (!potential.isPresent()) {
      throw new SchemaValidationFailedException(String.format("Child %s is not present in schema tree.",
          path.getAncestor(depth)));
    }
    operation = potential.get();
    ++depth;
    modification = modification.modifyChild(pathArg, operation, version);
  }
  return OperationWithModification.from(operation, modification);
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com