org.apache.jackrabbit.oak.api.Tree.getChildrenCount()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(80)

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

Tree.getChildrenCount介绍

[英]Determine the number of children of this Tree instance taking access restrictions into account.

If an implementation does know the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).
[中]考虑访问限制,确定此树实例的子级数。
如果一个实现确实知道确切的值,它会返回它(即使该值高于max)。如果实现不知道确切的值,并且子节点计数高于max,则可能返回Long。最大值。这项手术的费用最多不超过0英镑。

代码示例

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Override
public long getNumEntries(@Nonnull String principalName, long max) {
  // we ignore the hash-collisions here
  Tree tree = getPrincipalRoot(principalName);
  return tree == null ? 0 : tree.getChildrenCount(max);
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Get the number of child nodes
 * <p>
 * If an implementation does know the exact value, it returns it (even if
 * the value is higher than max). If the implementation does not know the
 * exact value, and the child node count is higher than max, it may return
 * Long.MAX_VALUE. The cost of the operation is at most O(max).
 *
 * @param max the maximum value
 * @return number of child nodes of the node
 */
public long getChildCount(long max) throws InvalidItemStateException {
  return getTree().getChildrenCount(max);
}

代码示例来源:origin: org.apache.jackrabbit/oak-jcr

/**
 * Get the number of child nodes
 * <p>
 * If an implementation does know the exact value, it returns it (even if
 * the value is higher than max). If the implementation does not know the
 * exact value, and the child node count is higher than max, it may return
 * Long.MAX_VALUE. The cost of the operation is at most O(max).
 *
 * @param max the maximum value
 * @return number of child nodes of the node
 */
public long getChildCount(long max) throws InvalidItemStateException {
  return getTree().getChildrenCount(max);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

/**
 * Get the number of child nodes
 * <p>
 * If an implementation does know the exact value, it returns it (even if
 * the value is higher than max). If the implementation does not know the
 * exact value, and the child node count is higher than max, it may return
 * Long.MAX_VALUE. The cost of the operation is at most O(max).
 *
 * @param max the maximum value
 * @return number of child nodes of the node
 */
public long getChildCount(long max) throws InvalidItemStateException {
  return getTree().getChildrenCount(max);
}

代码示例来源:origin: org.apache.jackrabbit/oak-core

@NotNull
@Override
public NumEntries getNumEntries(@NotNull String principalName, long max) {
  Tree tree = getPrincipalRoot(principalName);
  if (tree == null) {
    return NumEntries.ZERO;
  } else {
    // if rep:numPermissions is present it contains the exact number of
    // access controlled nodes for the given principal name.
    // if this property is missing (backward compat) we use the old
    // mechanism and use child-cnt with a max value to get a rough idea
    // about the magnitude (note: this approximation ignores the hash-collisions)
    long l = TreeUtil.getLong(tree, REP_NUM_PERMISSIONS, -1);
    return (l >= 0) ? NumEntries.valueOf(l, true) : NumEntries.valueOf(tree.getChildrenCount(max), false);
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testGetChildrenCount() throws Exception {
  long cntRoot = root.getTree("/").getChildrenCount(Long.MAX_VALUE);
  long cntA = root.getTree("/a").getChildrenCount(Long.MAX_VALUE);
  // 'testUser' may only see 'regular' child nodes -> count must be adjusted.
  assertEquals(cntRoot-1, testRoot.getTree("/").getChildrenCount(Long.MAX_VALUE));
  assertEquals(cntA - 1, testRoot.getTree("/a").getChildrenCount(Long.MAX_VALUE));
  // for the following nodes the cnt must not differ
  List<String> paths = ImmutableList.of("/a/b", "/a/b/c");
  for (String path : paths) {
    assertEquals(
        root.getTree(path).getChildrenCount(Long.MAX_VALUE),
        testRoot.getTree(path).getChildrenCount(Long.MAX_VALUE));
  }
}

代码示例来源:origin: apache/jackrabbit-oak

protected long cntEntries(Tree parent) {
  long cnt = parent.getChildrenCount(Long.MAX_VALUE);
  for (Tree child : parent.getChildren()) {
    cnt += cntEntries(child);
  }
  return cnt;
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testGetHiddenChildrenCount() {
  assertEquals(0, parent.getChildrenCount(1));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void getChildrenCount() {
  Tree tree = root.getTree("/");
  assertEquals(3, tree.getChildrenCount(4));
  tree.getChild("x").remove();
  assertEquals(2, tree.getChildrenCount(3));
  tree.addChild("a");
  assertEquals(3, tree.getChildrenCount(3));
  tree.addChild("x");
  assertEquals(4, tree.getChildrenCount(5));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void getChildren() {
  Tree tree = root.getTree("/");
  Iterable<Tree> children = tree.getChildren();
  Set<String> expectedPaths = new HashSet<String>();
  Collections.addAll(expectedPaths, "/x", "/y", "/z");
  for (Tree child : children) {
    assertTrue(expectedPaths.remove(child.getPath()));
  }
  assertTrue(expectedPaths.isEmpty());
  assertEquals(3, tree.getChildrenCount(4));
}

代码示例来源:origin: apache/jackrabbit-oak

static void assertMemberList(@NotNull Tree groupTree, int cntRefTrees, int cnt) {
  Tree list = groupTree.getChild(REP_MEMBERS_LIST);
  assertTrue(list.exists());
  assertEquals(cntRefTrees, list.getChildrenCount(5));
  for (Tree c : list.getChildren()) {
    PropertyState repMembers = c.getProperty(REP_MEMBERS);
    assertNotNull(repMembers);
    assertTrue(SIZE_TH == repMembers.count() || cnt == repMembers.count());
  }
}

代码示例来源:origin: apache/jackrabbit-oak

private String chooseNode(String parentPath) {
  Tree state = root1.getTree(parentPath);
  int k = random.nextInt((int) (state.getChildrenCount(Long.MAX_VALUE) + 1));
  int c = 0;
  for (Tree child : state.getChildren()) {
    if (c++ == k) {
      return PathUtils.concat(parentPath, child.getName());
    }
  }
  return null;
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testGetChildrenCountOnVersionStorage() throws Exception {
  Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH);
  vs.getChildrenCount(Long.MAX_VALUE);
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testKnownMemberThresholdReached() throws Exception {
  List<String> memberIds = new ArrayList();
  for (int i = 0; i <= MembershipWriter.DEFAULT_MEMBERSHIP_THRESHOLD; i++) {
    memberIds.add(userProvider.getContentID("m"+i));
  }
  groupTree.setProperty(REP_MEMBERS, memberIds, Type.STRINGS);
  importer.startChildInfo(createNodeInfo("memberRef", NT_REP_MEMBER_REFERENCES), ImmutableList.of(createPropInfo(REP_MEMBERS, knownMemberContentId)));
  importer.processReferences();
  assertEquals(1, memberRefList.getChildrenCount(100));
  assertTrue(memberRefList.getChildren().iterator().next().hasProperty(REP_MEMBERS));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
  public void testGetChildrenCountOnVersionStorage2() throws Exception {
    setupPermission("/", testPrincipal, true, PrivilegeConstants.JCR_READ);
    Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH);
    vs.getChildrenCount(Long.MAX_VALUE);
  }
}

代码示例来源:origin: apache/jackrabbit-oak

private void assertTokenNodes(int expectedNumber) throws Exception {
  Tree tokenParent = root.getTree(getTestUser().getPath() + '/' + TokenConstants.TOKENS_NODE_NAME);
  assertEquals(expectedNumber, tokenParent.getChildrenCount(expectedNumber*2));
}

代码示例来源:origin: apache/jackrabbit-oak

private static void checkEqual(Tree tree1, Tree tree2) {
    assertEquals(tree1.getChildrenCount(Long.MAX_VALUE), tree2.getChildrenCount(Long.MAX_VALUE));
    assertEquals(tree1.getPropertyCount(), tree2.getPropertyCount());

    for (PropertyState property1 : tree1.getProperties()) {
      assertEquals(property1, tree2.getProperty(property1.getName()));
    }

    for (Tree child1 : tree1.getChildren()) {
      checkEqual(child1, tree2.getChild(child1.getName()));
    }
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testGetHiddenTree() {
  Tree hidden = parent.getChild(HIDDEN_NAME);
  assertNotNull(hidden);
  assertFalse(hidden.exists());
  assertEquals(0, hidden.getChildrenCount(1));
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testGetNumEntriesMissingPropertyThreshold() throws Exception {
  try {
    Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME);
    everyoneTree.removeProperty(REP_NUM_PERMISSIONS);
    long max = 1;
    assertEquals(NumEntries.valueOf(everyoneTree.getChildrenCount(max), false), permissionStore.getNumEntries(EveryonePrincipal.NAME, max));
  } finally {
    root.refresh();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void copyUnordered() throws Exception{
  builder.setProperty("foo", "x");
  builder.child("a").setProperty("foo", "y");
  builder.child("b").setProperty("foo", "z");
  builder.child("a").child("c").setProperty("foo", "acx");
  Tree tree = TreeFactory.createTree(EMPTY_NODE.builder());
  NodeStateCopyUtils.copyToTree(builder.getNodeState(), tree);
  assertEquals("x", tree.getProperty("foo").getValue(Type.STRING));
  assertEquals(2, tree.getChildrenCount(100));
  assertEquals("y", tree.getChild("a").getProperty("foo").getValue(Type.STRING));
  assertEquals("z", tree.getChild("b").getProperty("foo").getValue(Type.STRING));
  assertEquals("acx", tree.getChild("a").getChild("c").getProperty("foo").getValue(Type.STRING));
}

相关文章