/** * Returns the node with the minimal key wrt. {@link TreeManager#getOrder()}. * For the empty sequence this is {@link TreeManager#getRoot()}. */ protected final Node getMinimal() throws RepositoryException { Node p = null; Node n = root; while ((n = getMinimal(n)) != null) { p = n; } return p; }
/** * Returns the predecessor node for the given * <code>key</code>. That is the node * whose key directly precedes the passed <code>key</code> in the order * determined by {@link TreeManager#getOrder()}. There are two cases: * <ul> * <li>A node with the given <code>key</code> is mapped: then that node is * returned.</li> * <li>A node with the given <code>key</code> is not mapped: the the node * where that would contain that key if present is returned.</li> * </ul> */ protected final Node getPredecessor(String key) throws RepositoryException { Node p = root; Node n; while ((n = getPredecessor(p, key)) != null) { p = n; } return p; }
static PropertySequence getPropertySequence(Node nMembers, UserManagerImpl userManager) throws RepositoryException { Comparator<String> order = Rank.comparableComparator(); int maxChildren = userManager.getMemberSplitSize(); int minChildren = maxChildren / 2; TreeManager treeManager = new BTreeManager(nMembers, minChildren, maxChildren, order, userManager.isAutoSave()); return ItemSequence.createPropertySequence(treeManager); }
/** * Rename the path of the node with the minimal key. That is, assuming * <code>node</code> is the node with the minimal key (see * {@link #getMinimal()}), this method renames every segment of the path of * <code>node</code> up to {@link TreeManager#getRoot()} to <code>key</code> * . <em>Note: </em> If <code>node</code> is not the node with the minimal * key, the behavior of this method is not specified. */ protected final void renamePath(Node node, String key) throws RepositoryException { if (!treeManager.isRoot(node)) { Node p = node.getParent(); renamePath(p, key); Session s = node.getSession(); s.move(node.getPath(), p.getPath() + "/" + key); // If orderable, move to first child node if (p.getPrimaryNodeType().hasOrderableChildNodes()) { p.orderBefore(key, p.getNodes().nextNode().getName()); } } }
Node dest = itemSequence.getSuccessor(grandParent, key); newParent = createIntermediateNode(grandParent, key); grandParent.orderBefore(key, dest == null ? null : dest.getName());
public void testEmptyNodeSequence() throws RepositoryException { Comparator<String> order = Rank.<String>comparableComparator(); TreeManager treeManager = new BTreeManager(testNode, 5, 10, order, true); NodeSequence nodes = ItemSequence.createNodeSequence(treeManager, errorHandler); Iterator<Node> nodeIt = nodes.iterator(); assertTrue(nodeIt.hasNext()); assertTrue(treeManager.isRoot(nodeIt.next())); assertFalse(nodeIt.hasNext()); checkTreeProperty(testNode, 5, 10, order); checkOrder(nodes, order); assertEmpty(nodes); }
static PropertySequence getPropertySequence(Node nMembers, UserManagerImpl userManager) throws RepositoryException { Comparator<String> order = Rank.comparableComparator(); int maxChildren = userManager.getMemberSplitSize(); int minChildren = maxChildren / 2; TreeManager treeManager = new BTreeManager(nMembers, minChildren, maxChildren, order, userManager.isAutoSave()); return ItemSequence.createPropertySequence(treeManager); }
/** * Rename the path of the node with the minimal key. That is, assuming * <code>node</code> is the node with the minimal key (see * {@link #getMinimal()}), this method renames every segment of the path of * <code>node</code> up to {@link TreeManager#getRoot()} to <code>key</code> * . <em>Note: </em> If <code>node</code> is not the node with the minimal * key, the behavior of this method is not specified. */ protected final void renamePath(Node node, String key) throws RepositoryException { if (!treeManager.isRoot(node)) { Node p = node.getParent(); renamePath(p, key); Session s = node.getSession(); s.move(node.getPath(), p.getPath() + "/" + key); // If orderable, move to first child node if (p.getPrimaryNodeType().hasOrderableChildNodes()) { p.orderBefore(key, p.getNodes().nextNode().getName()); } } }
Node dest = itemSequence.getSuccessor(grandParent, key); newParent = createIntermediateNode(grandParent, key); grandParent.orderBefore(key, dest == null ? null : dest.getName());
public void testSingletonNodeSequence() throws RepositoryException { Comparator<String> order = Rank.<String>comparableComparator(); TreeManager treeManager = new BTreeManager(testNode, 5, 10, order, true); NodeSequence nodes = ItemSequence.createNodeSequence(treeManager, errorHandler); nodes.addNode("key", NodeType.NT_UNSTRUCTURED); assertTrue(nodes.hasItem("key")); Iterator<Node> nodeIt = nodes.iterator(); assertTrue(nodeIt.hasNext()); assertEquals("key", nodeIt.next().getName()); assertFalse(nodeIt.hasNext()); checkTreeProperty(testNode, 5, 10, order); checkOrder(nodes, order); nodes.removeNode("key"); assertEmpty(nodes); }
public void testEmptyPropertySequence() throws RepositoryException { Comparator<String> order = Rank.<String>comparableComparator(); TreeManager treeManager = new BTreeManager(testNode, 2, 4, order, true); PropertySequence properties = ItemSequence.createPropertySequence(treeManager, errorHandler); Iterator<Property> propertyIt = properties.iterator(); assertFalse(propertyIt.hasNext()); assertEmpty(properties); }
/** * Returns the node with the minimal key wrt. {@link TreeManager#getOrder()}. * For the empty sequence this is {@link TreeManager#getRoot()}. */ protected final Node getMinimal() throws RepositoryException { Node p = null; Node n = root; while ((n = getMinimal(n)) != null) { p = n; } return p; }
/** * Returns the predecessor node for the given * <code>key</code>. That is the node * whose key directly precedes the passed <code>key</code> in the order * determined by {@link TreeManager#getOrder()}. There are two cases: * <ul> * <li>A node with the given <code>key</code> is mapped: then that node is * returned.</li> * <li>A node with the given <code>key</code> is not mapped: the the node * where that would contain that key if present is returned.</li> * </ul> */ protected final Node getPredecessor(String key) throws RepositoryException { Node p = root; Node n; while ((n = getPredecessor(p, key)) != null) { p = n; } return p; }
/** * Rename the path of the node with the minimal key. That is, assuming * <code>node</code> is the node with the minimal key (see * {@link #getMinimal()}), this method renames every segment of the path of * <code>node</code> up to {@link TreeManager#getRoot()} to <code>key</code> * . <em>Note: </em> If <code>node</code> is not the node with the minimal * key, the behavior of this method is not specified. */ protected final void renamePath(Node node, String key) throws RepositoryException { if (!treeManager.isRoot(node)) { Node p = node.getParent(); renamePath(p, key); Session s = node.getSession(); s.move(node.getPath(), p.getPath() + "/" + key); // If orderable, move to first child node if (p.getPrimaryNodeType().hasOrderableChildNodes()) { p.orderBefore(key, p.getNodes().nextNode().getName()); } } }
Node dest = itemSequence.getSuccessor(grandParent, key); newParent = createIntermediateNode(grandParent, key); grandParent.orderBefore(key, dest == null ? null : dest.getName());
public void testNodeSequence() throws RepositoryException, IOException { Comparator<String> order = Rank.<String>comparableComparator(); TreeManager treeManager = new BTreeManager(testNode, 5, 10, order, true); NodeSequence nodes = ItemSequence.createNodeSequence(treeManager, errorHandler); List<String> words = loadWords(); Collections.shuffle(words); addAll(nodes, words); checkTreeProperty(testNode, 5, 10, order); checkOrder(nodes, order); Collections.shuffle(words); checkLookup(nodes, words); Collections.shuffle(words); List<String> toRemove = take(words.size()/5, words); removeAll(nodes, toRemove); checkNotFound(nodes, toRemove); checkLookup(nodes, words); removeAll(nodes, words); assertEmpty(nodes); }
public void testPropertySequence() throws RepositoryException, IOException { Comparator<String> order = Rank.<String>comparableComparator(); TreeManager treeManager = new BTreeManager(testNode, 2, 4, order, true); PropertySequence properties = ItemSequence.createPropertySequence(treeManager, errorHandler); List<String> words = loadWords(); Collections.shuffle(words); ValueFactory vFactory = testNode.getSession().getValueFactory(); addAll(properties, words, vFactory); checkTreeProperty(testNode, 2, 4, order); Collections.shuffle(words); checkLookup(properties, words); Collections.shuffle(words); List<String> toRemove = take(words.size()/5, words); removeAll(properties, toRemove); checkNotFound(properties, toRemove); checkLookup(properties, words); removeAll(properties, words); assertEmpty(properties); }
/** * Returns the node with the minimal key wrt. {@link TreeManager#getOrder()}. * For the empty sequence this is {@link TreeManager#getRoot()}. */ protected final Node getMinimal() throws RepositoryException { Node p = null; Node n = root; while ((n = getMinimal(n)) != null) { p = n; } return p; }
/** * Returns the predecessor node for the given * <code>key</code>. That is the node * whose key directly precedes the passed <code>key</code> in the order * determined by {@link TreeManager#getOrder()}. There are two cases: * <ul> * <li>A node with the given <code>key</code> is mapped: then that node is * returned.</li> * <li>A node with the given <code>key</code> is not mapped: the the node * where that would contain that key if present is returned.</li> * </ul> */ protected final Node getPredecessor(String key) throws RepositoryException { Node p = root; Node n; while ((n = getPredecessor(p, key)) != null) { p = n; } return p; }
public void testSingletonPropertySequence() throws RepositoryException { Comparator<String> order = Rank.<String>comparableComparator(); TreeManager treeManager = new BTreeManager(testNode, 2, 4, order, true); PropertySequence properties = ItemSequence.createPropertySequence(treeManager, errorHandler); ValueFactory vFactory = testNode.getSession().getValueFactory(); properties.addProperty("key", vFactory.createValue("key_")); assertTrue(properties.hasItem("key")); Iterator<Property> propertyIt = properties.iterator(); assertTrue(propertyIt.hasNext()); assertEquals("key", propertyIt.next().getName()); assertFalse(propertyIt.hasNext()); properties.removeProperty("key"); assertEmpty(properties); }