@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); }
/** * 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); }
/** * 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); }
/** * 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); }
@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); } }
@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)); } }
protected long cntEntries(Tree parent) { long cnt = parent.getChildrenCount(Long.MAX_VALUE); for (Tree child : parent.getChildren()) { cnt += cntEntries(child); } return cnt; }
@Test public void testGetHiddenChildrenCount() { assertEquals(0, parent.getChildrenCount(1)); }
@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)); }
@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)); }
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()); } }
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; }
@Test public void testGetChildrenCountOnVersionStorage() throws Exception { Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH); vs.getChildrenCount(Long.MAX_VALUE); }
@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)); }
@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); } }
private void assertTokenNodes(int expectedNumber) throws Exception { Tree tokenParent = root.getTree(getTestUser().getPath() + '/' + TokenConstants.TOKENS_NODE_NAME); assertEquals(expectedNumber, tokenParent.getChildrenCount(expectedNumber*2)); }
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())); } } }
@Test public void testGetHiddenTree() { Tree hidden = parent.getChild(HIDDEN_NAME); assertNotNull(hidden); assertFalse(hidden.exists()); assertEquals(0, hidden.getChildrenCount(1)); }
@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(); } }
@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)); }