List of usage examples for org.apache.commons.collections.iterators IteratorChain addIterator
public void addIterator(Iterator iterator)
From source file:com.amalto.core.storage.dispatch.CompositeStorageResults.java
@Override public Iterator<DataRecord> iterator() { IteratorChain chain = new IteratorChain(); for (StorageResults result : results) { chain.addIterator(result.iterator()); }/*from w w w. j a v a 2 s.c om*/ return chain; }
From source file:org.apache.accumulo.core.client.mock.MockBatchScanner.java
@SuppressWarnings("unchecked") @Override/* www . j ava 2 s . co m*/ public Iterator<Entry<Key, Value>> iterator() { if (ranges == null) { throw new IllegalStateException("ranges not set"); } IteratorChain chain = new IteratorChain(); for (Range range : ranges) { SortedKeyValueIterator<Key, Value> i = new SortedMapIterator(table.table); try { i = createFilter(i); i.seek(range, createColumnBSS(fetchedColumns), !fetchedColumns.isEmpty()); chain.addIterator(new IteratorAdapter(i)); } catch (IOException e) { throw new RuntimeException(e); } } return chain; }
From source file:org.apache.jackrabbit.core.integration.random.operation.OperationSequence.java
public NodeIterator execute() throws Exception { IteratorChain chain = new IteratorChain(); for (int i = 0; i < ops.length; i++) { chain.addIterator(ops[i].execute()); }// www .j a va2 s. c o m return new NodeIteratorAdapter(chain); }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Returns an iterator over those transient item state instances that are * direct or indirect descendants of the item state with the given * <code>parentId</code>. The transient item state instance with the given * <code>parentId</code> itself (if there is such) not be included. * <p/>//from w ww . j a va 2s.com * The instances are returned in depth-first tree traversal order. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances * @throws InvalidItemStateException if any descendant item state has been * deleted externally * @throws RepositoryException if another error occurs */ public Iterator<ItemState> getDescendantTransientItemStates(NodeId parentId) throws InvalidItemStateException, RepositoryException { if (transientStore.isEmpty()) { List<ItemState> empty = Collections.emptyList(); return empty.iterator(); } // build ordered collection of descendant transient states // sorted by decreasing relative depth // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { Iterator iter = transientStore.values().iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); // determine relative depth: > 0 means it's a descendant int depth; try { depth = hierMgr.getShareRelativeDepth(parentId, state.getId()); } catch (ItemNotFoundException infe) { /** * one of the parents of the specified item has been * removed externally; as we don't know its path, * we can't determine if it is a descendant; * InvalidItemStateException should only be thrown if * a descendant is affected; * => throw InvalidItemStateException for now * todo FIXME */ // unable to determine relative depth, assume that the item // (or any of its ancestors) has been removed externally String msg = state.getId() + ": the item seems to have been removed externally."; log.debug(msg); throw new InvalidItemStateException(msg); } if (depth < 1) { // not a descendant continue; } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { List<ItemState> empty = Collections.emptyList(); return empty.iterator(); } return resultIter; }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Same as <code>{@link #getDescendantTransientItemStates(NodeId)}</code> * except that item state instances in the attic are returned. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances in the attic *///from w ww. j ava2s . c o m public Iterator<ItemState> getDescendantTransientItemStatesInAttic(NodeId parentId) { if (atticStore.isEmpty()) { List<ItemState> empty = Collections.emptyList(); return empty.iterator(); } // build ordered collection of descendant transient states in attic // sorted by decreasing relative depth // use a special attic-aware hierarchy manager ZombieHierarchyManager zombieHierMgr = new ZombieHierarchyManager(hierMgr, this, getAttic()); // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { for (ItemState state : atticStore.values()) { // determine relative depth: > 0 means it's a descendant //int depth = zombieHierMgr.getRelativeDepth(parentId, state.getId()); int depth = zombieHierMgr.getShareRelativeDepth(parentId, state.getId()); if (depth < 1) { // not a descendant continue; } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { List<ItemState> empty = Collections.emptyList(); return empty.iterator(); } return resultIter; }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Returns an iterator over those transient item state instances that are * direct or indirect descendants of the item state with the given * <code>parentId</code>. The transient item state instance with the given * <code>parentId</code> itself (if there is such) not be included. * <p/>// www . j ava2 s.com * The instances are returned in depth-first tree traversal order. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances * @throws InvalidItemStateException if any descendant item state has been * deleted externally * @throws RepositoryException if another error occurs */ public Iterator getDescendantTransientItemStates(NodeId parentId) throws InvalidItemStateException, RepositoryException { if (transientStore.isEmpty()) { return Collections.EMPTY_LIST.iterator(); } // build ordered collection of descendant transient states // sorted by decreasing relative depth // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { Iterator iter = transientStore.values().iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); // determine relative depth: > 0 means it's a descendant int depth; try { depth = hierMgr.getShareRelativeDepth(parentId, state.getId()); } catch (ItemNotFoundException infe) { /** * one of the parents of the specified item has been * removed externally; as we don't know its path, * we can't determine if it is a descendant; * InvalidItemStateException should only be thrown if * a descendant is affected; * => throw InvalidItemStateException for now * todo FIXME */ // unable to determine relative depth, assume that the item // (or any of its ancestors) has been removed externally String msg = state.getId() + ": the item seems to have been removed externally."; log.debug(msg); throw new InvalidItemStateException(msg); } if (depth < 1) { // TODO SN: move this to HierarchyManager // if state is shareable, it has actually more than one parent if (state.isNode()) { NodeState ns = (NodeState) state; if (ns.isShareable()) { Set sharedSet = ns.getSharedSet(); if (ns.hasOverlayedState()) { sharedSet = ((NodeState) ns.getOverlayedState()).getSharedSet(); } Iterator sharedParentIds = sharedSet.iterator(); while (sharedParentIds.hasNext()) { NodeId sharedParentId = (NodeId) sharedParentIds.next(); int depth2 = hierMgr.getRelativeDepth(parentId, sharedParentId); if (depth2 >= 0) { depth = depth2 + 1; break; } } } } if (depth < 1) { // not a descendant continue; } } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { return Collections.EMPTY_LIST.iterator(); } return resultIter; }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Same as <code>{@link #getDescendantTransientItemStates(NodeId)}</code> * except that item state instances in the attic are returned. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances in the attic *///from w ww .j a v a2s .c o m public Iterator getDescendantTransientItemStatesInAttic(NodeId parentId) { if (atticStore.isEmpty()) { return Collections.EMPTY_LIST.iterator(); } // build ordered collection of descendant transient states in attic // sorted by decreasing relative depth // use a special attic-aware hierarchy manager ZombieHierarchyManager zombieHierMgr = new ZombieHierarchyManager(hierMgr, this, getAttic()); // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { Iterator iter = atticStore.values().iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); // determine relative depth: > 0 means it's a descendant //int depth = zombieHierMgr.getRelativeDepth(parentId, state.getId()); int depth = zombieHierMgr.getShareRelativeDepth(parentId, state.getId()); if (depth < 1) { // not a descendant continue; } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { return Collections.EMPTY_LIST.iterator(); } return resultIter; }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Returns an iterator over those transient item state instances that are * direct or indirect descendants of the item state with the given * <code>parentId</code>. The transient item state instance with the given * <code>parentId</code> itself (if there is such) will not be included. * <p/>/*from w w w.ja v a2s.c om*/ * The instances are returned in depth-first tree traversal order. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances * @throws InvalidItemStateException if any descendant item state has been * deleted externally * @throws RepositoryException if another error occurs */ public Iterator getDescendantTransientItemStates(NodeId parentId) throws InvalidItemStateException, RepositoryException { if (transientStore.isEmpty()) { return Collections.EMPTY_LIST.iterator(); } // build ordered collection of descendant transient states // sorted by decreasing relative depth // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { Iterator iter = transientStore.values().iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); // determine relative depth: > 0 means it's a descendant int depth; try { depth = hierMgr.getRelativeDepth(parentId, state.getId()); } catch (ItemNotFoundException infe) { /** * one of the parents of the specified item has been * removed externally; as we don't know its path, * we can't determine if it is a descendant; * InvalidItemStateException should only be thrown if * a descendant is affected; * => throw InvalidItemStateException for now * todo FIXME */ // unable to determine relative depth, assume that the item // (or any of its ancestors) has been removed externally String msg = state.getId() + ": the item seems to have been removed externally."; log.debug(msg); throw new InvalidItemStateException(msg); } if (depth < 1) { // TODO SN: move this to HierarchyManager // if state is shareable, it has actually more than one parent if (state.isNode()) { NodeState ns = (NodeState) state; if (ns.isShareable()) { Set sharedSet = ns.getSharedSet(); if (ns.hasOverlayedState()) { sharedSet = ((NodeState) ns.getOverlayedState()).getSharedSet(); } Iterator sharedParentIds = sharedSet.iterator(); while (sharedParentIds.hasNext()) { NodeId sharedParentId = (NodeId) sharedParentIds.next(); int depth2 = hierMgr.getRelativeDepth(parentId, sharedParentId); if (depth2 >= 0) { depth = depth2 + 1; break; } } } } if (depth < 1) { // not a descendant continue; } } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { return Collections.EMPTY_LIST.iterator(); } return resultIter; }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Same as <code>{@link #getDescendantTransientItemStates(NodeId)}</code> * except that item state instances in the attic are returned. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances in the attic *///from ww w.j a v a 2 s. c om public Iterator getDescendantTransientItemStatesInAttic(NodeId parentId) { if (atticStore.isEmpty()) { return Collections.EMPTY_LIST.iterator(); } // build ordered collection of descendant transient states in attic // sorted by decreasing relative depth // use a special attic-aware hierarchy manager ZombieHierarchyManager zombieHierMgr = new ZombieHierarchyManager(hierMgr, this, getAttic()); // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { Iterator iter = atticStore.values().iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); // determine relative depth: > 0 means it's a descendant int depth = zombieHierMgr.getRelativeDepth(parentId, state.getId()); if (depth < 1) { // not a descendant continue; } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { return Collections.EMPTY_LIST.iterator(); } return resultIter; }
From source file:org.apache.jackrabbit.core.state.SessionItemStateManager.java
/** * Returns an iterator over those transient item state instances that are * direct or indirect descendants of the item state with the given * <code>parentId</code>. The transient item state instance with the given * <code>parentId</code> itself (if there is such) not be included. * <p/>/*from w w w .ja v a 2s .c o m*/ * The instances are returned in depth-first tree traversal order. * * @param parentId the id of the common parent of the transient item state * instances to be returned. * @return an iterator over descendant transient item state instances * @throws InvalidItemStateException if any descendant item state has been * deleted externally * @throws RepositoryException if another error occurs */ public Iterator getDescendantTransientItemStates(NodeId parentId) throws InvalidItemStateException, RepositoryException { if (transientStore.isEmpty()) { return Collections.EMPTY_LIST.iterator(); } // build ordered collection of descendant transient states // sorted by decreasing relative depth // use an array of lists to group the descendants by relative depth; // the depth is used as array index List[] la = new List[10]; try { Iterator iter = transientStore.values().iterator(); while (iter.hasNext()) { ItemState state = (ItemState) iter.next(); // determine relative depth: > 0 means it's a descendant int depth; try { depth = hierMgr.getShareRelativeDepth(parentId, state.getId()); } catch (ItemNotFoundException infe) { /** * one of the parents of the specified item has been * removed externally; as we don't know its path, * we can't determine if it is a descendant; * InvalidItemStateException should only be thrown if * a descendant is affected; * => throw InvalidItemStateException for now * todo FIXME */ // unable to determine relative depth, assume that the item // (or any of its ancestors) has been removed externally String msg = state.getId() + ": the item seems to have been removed externally."; log.debug(msg); throw new InvalidItemStateException(msg); } if (depth < 1) { // not a descendant continue; } // ensure capacity if (depth > la.length) { List[] old = la; la = new List[depth + 10]; System.arraycopy(old, 0, la, 0, old.length); } List list = la[depth - 1]; if (list == null) { list = new ArrayList(); la[depth - 1] = list; } list.add(state); } } catch (RepositoryException re) { log.warn("inconsistent hierarchy state", re); } // create an iterator over the collected descendants // in decreasing depth order IteratorChain resultIter = new IteratorChain(); for (int i = la.length - 1; i >= 0; i--) { List list = la[i]; if (list != null) { resultIter.addIterator(list.iterator()); } } /** * if the resulting iterator chain is empty return * EMPTY_LIST.iterator() instead because older versions * of IteratorChain (pre Commons Collections 3.1) * would throw UnsupportedOperationException in this * situation */ if (resultIter.getIterators().isEmpty()) { return Collections.EMPTY_LIST.iterator(); } return resultIter; }