/** * Create a new instance of <code>Rank</code> for a given array of * <code>values</code>. The order is determined by the natural ordering of * the values (i.e. through {@link Comparable}). The <code>values</code> are * manipulated in place, no copying is performed. * * @param <S> extends Comparable<S> * @param values values for ranking. Duplicates are <em>not allowed</em>. * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(S[] values) { return new Rank<S>(values, Rank.<S>comparableComparator()); }
private static <S> S[] toArray(Collection<S> collection, Class<S> componentType) { return collection.toArray(createArray(collection.size(), componentType)); }
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); }
/** * Create a new instance of <code>Rank</code> for the first * <code>count</code> values in a a given iterator of <code>values</code> * and a given <code>order</code>. The <code>values</code> are copied into * an internal array before they are manipulated. * * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @param count Number of items to include. -1 for all. * @param order Ordering for ranking */ public Rank(Iterator<T> values, Class<T> componentType, int count, Comparator<? super T> order) { super(); this.order = order; if (count >= 0) { this.values = createArray(count, componentType); for (int k = 0; k < count; k++) { this.values[k] = values.next(); } } else { List<T> l = new LinkedList<T>(); while (values.hasNext()) { l.add(values.next()); } this.values = toArray(l, componentType); } }
private <T extends Item> void split(Node node, Rank<T> ranking, ItemSequence itemSequence) throws RepositoryException { if (ranking.size() <= maxChildren) { return; ranking.take(minChildren); for (int k = ranking.size() / minChildren; k > 0; k--) { T item = ranking.take(1).next(); String key = item.getName(); int c = k > 1 ? minChildren - 1 : ranking.size(); Iterator<T> remaining = ranking.take(c);
/** * This implementations splits <code>node</code> when its number of child * nodes exceeds the maximum number specified in the constructor. Splitting * is done such that after the split each of the new child nodes contains at * least as many nodes as specified in the constructor. * * @see org.apache.jackrabbit.commons.flat.TreeManager#split(org.apache.jackrabbit.commons.flat.ItemSequence, * javax.jcr.Node, javax.jcr.Node) */ @SuppressWarnings("deprecation") public void split(ItemSequence itemSequence, Node node, Node cause) throws RepositoryException { SizedIterator<Node> childNodes = getNodes(node); int count = (int) childNodes.getSize(); if (count >= 0 && count <= maxChildren) { return; } split(node, new Rank<Node>(childNodes, Node.class, count, itemOrder), itemSequence); }
/** * Create a new instance of <code>Rank</code> for a given collection of * <code>values</code> and a given <code>order</code>. The * <code>values</code> are copied into an internal array before they are * manipulated. * * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @param order Ordering for ranking */ public Rank(Collection<T> values, Class<T> componentType, Comparator<? super T> order) { super(); this.values = toArray(values, componentType); this.order = order; }
/** * Returns the <code>n</code>-th smallest values remaining in this * <code>Rank</code>. * * @param n Number of values to return * @return An iterator containing the next <code>n</code> smallest values. * @throws NoSuchElementException if this <code>Rank</code> has not enough * remaining elements or when <code>n</code> is negative. */ public Iterator<T> take(int n) { if (n < 0 || n + first > values.length) { throw new NoSuchElementException(); } if (n > 0) { take(n, first, values.length - 1); first += n; return Arrays.asList(values).subList(first - n, first).iterator(); } else { return Collections.<T>emptySet().iterator(); } }
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); }
/** * Create a new instance of <code>Rank</code> for the first * <code>count</code> values in a a given iterator of <code>values</code> * and a given <code>order</code>. The <code>values</code> are copied into * an internal array before they are manipulated. * * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @param count Number of items to include. -1 for all. * @param order Ordering for ranking */ public Rank(Iterator<T> values, Class<T> componentType, int count, Comparator<? super T> order) { super(); this.order = order; if (count >= 0) { this.values = createArray(count, componentType); for (int k = 0; k < count; k++) { this.values[k] = values.next(); } } else { List<T> l = new LinkedList<T>(); while (values.hasNext()) { l.add(values.next()); } this.values = toArray(l, componentType); } }
private <T extends Item> void split(Node node, Rank<T> ranking, ItemSequence itemSequence) throws RepositoryException { if (ranking.size() <= maxChildren) { return; ranking.take(minChildren); for (int k = ranking.size() / minChildren; k > 0; k--) { T item = ranking.take(1).next(); String key = item.getName(); int c = k > 1 ? minChildren - 1 : ranking.size(); Iterator<T> remaining = ranking.take(c);
/** * This implementations splits <code>node</code> when its number of * properties exceeds the maximum number specified in the constructor. * Splitting is done such that after the split each of the new child nodes * contains at least as many nodes as specified in the constructor. * * @see org.apache.jackrabbit.commons.flat.TreeManager#split(org.apache.jackrabbit.commons.flat.ItemSequence, * javax.jcr.Node, javax.jcr.Property) */ @SuppressWarnings("deprecation") public void split(ItemSequence itemSequence, Node node, Property cause) throws RepositoryException { SizedIterator<Property> properties = getProperties(node); int count = (int) properties.getSize(); if (count >= 0 && count <= maxChildren) { return; } split(node, new Rank<Property>(properties, Property.class, count, itemOrder), itemSequence); }
/** * Create a new instance of <code>Rank</code> for a given collection of * <code>values</code> and a given <code>order</code>. The * <code>values</code> are copied into an internal array before they are * manipulated. * * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @param order Ordering for ranking */ public Rank(Collection<T> values, Class<T> componentType, Comparator<? super T> order) { super(); this.values = toArray(values, componentType); this.order = order; }
/** * Returns the <code>n</code>-th smallest values remaining in this * <code>Rank</code>. * * @param n Number of values to return * @return An iterator containing the next <code>n</code> smallest values. * @throws NoSuchElementException if this <code>Rank</code> has not enough * remaining elements or when <code>n</code> is negative. */ public Iterator<T> take(int n) { if (n < 0 || n + first > values.length) { throw new NoSuchElementException(); } if (n > 0) { take(n, first, values.length - 1); first += n; return Arrays.asList(values).subList(first - n, first).iterator(); } else { return Collections.<T>emptySet().iterator(); } }
/** * Create a new instance of <code>Rank</code> for a given array of * <code>values</code>. The order is determined by the natural ordering of * the values (i.e. through {@link Comparable}). The <code>values</code> are * manipulated in place, no copying is performed. * * @param <S> extends Comparable<S> * @param values values for ranking. Duplicates are <em>not allowed</em>. * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(S[] values) { return new Rank<S>(values, Rank.<S>comparableComparator()); }
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); }
/** * Create a new instance of <code>Rank</code> for the first * <code>count</code> values in a a given iterator of <code>values</code> * and a given <code>order</code>. The <code>values</code> are copied into * an internal array before they are manipulated. * * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @param count Number of items to include. -1 for all. * @param order Ordering for ranking */ public Rank(Iterator<T> values, Class<T> componentType, int count, Comparator<? super T> order) { super(); this.order = order; if (count >= 0) { this.values = createArray(count, componentType); for (int k = 0; k < count; k++) { this.values[k] = values.next(); } } else { List<T> l = new LinkedList<T>(); while (values.hasNext()) { l.add(values.next()); } this.values = toArray(l, componentType); } }
private <T extends Item> void split(Node node, Rank<T> ranking, ItemSequence itemSequence) throws RepositoryException { if (ranking.size() <= maxChildren) { return; ranking.take(minChildren); for (int k = ranking.size() / minChildren; k > 0; k--) { T item = ranking.take(1).next(); String key = item.getName(); int c = k > 1 ? minChildren - 1 : ranking.size(); Iterator<T> remaining = ranking.take(c);