/** * 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()); }
/** * Create a new instance of <code>Rank</code> for a given collection 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 * copied into an internal array before they are manipulated. * * @param <S> extends Comparable<S> * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(Collection<S> values, Class<S> componentType) { return new Rank<S>(values, componentType, Rank.<S>comparableComparator()); }
/** * 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()); }
/** * 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()); }
/** * Create a new instance of <code>Rank</code> for a given collection 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 * copied into an internal array before they are manipulated. * * @param <S> extends Comparable<S> * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(Collection<S> values, Class<S> componentType) { return new Rank<S>(values, componentType, Rank.<S>comparableComparator()); }
/** * Create a new instance of <code>Rank</code> for a given collection 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 * copied into an internal array before they are manipulated. * * @param <S> extends Comparable<S> * @param values values for ranking. Duplicates are <em>not allowed</em>. * @param componentType type evidence for the values * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(Collection<S> values, Class<S> componentType) { return new Rank<S>(values, componentType, Rank.<S>comparableComparator()); }
/** * Create a new instance of <code>Rank</code> for the first * <code>count</code> values in a a given iterator 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 copied into an * internal array before they are manipulated. * * @param <S> extends Comparable<S> * @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. * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(Iterator<S> values, Class<S> componentType, int count) { return new Rank<S>(values, componentType, count, Rank.<S>comparableComparator()); }
/** * Create a new instance of <code>Rank</code> for the first * <code>count</code> values in a a given iterator 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 copied into an * internal array before they are manipulated. * * @param <S> extends Comparable<S> * @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. * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(Iterator<S> values, Class<S> componentType, int count) { return new Rank<S>(values, componentType, count, Rank.<S>comparableComparator()); }
/** * Create a new instance of <code>Rank</code> for the first * <code>count</code> values in a a given iterator 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 copied into an * internal array before they are manipulated. * * @param <S> extends Comparable<S> * @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. * @return A new instance of <code>Rank</code>. */ public static <S extends Comparable<S>> Rank<S> rank(Iterator<S> values, Class<S> componentType, int count) { return new Rank<S>(values, componentType, count, Rank.<S>comparableComparator()); }
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); }
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); }
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); }
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); }
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 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); }
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); }
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); }