List of usage examples for org.apache.commons.collections.iterators AbstractIteratorDecorator AbstractIteratorDecorator
public AbstractIteratorDecorator(Iterator iterator)
From source file:org.apache.jackrabbit.core.query.lucene.SearchIndex.java
/** * This implementation forwards the call to * {@link MultiIndex#update(java.util.Iterator, java.util.Iterator)} and * transforms the two iterators to the required types. * * @param remove uuids of nodes to remove. * @param add NodeStates to add. Calls to <code>next()</code> on this * iterator may return <code>null</code>, to indicate that a * node could not be indexed successfully. * @throws RepositoryException if an error occurs while indexing a node. * @throws IOException if an error occurs while updating the index. *//*from w w w .j av a 2 s . co m*/ public void updateNodes(NodeIdIterator remove, NodeStateIterator add) throws RepositoryException, IOException { checkOpen(); final Map aggregateRoots = new HashMap(); final Set removedNodeIds = new HashSet(); final Set addedNodeIds = new HashSet(); index.update(new AbstractIteratorDecorator(remove) { public Object next() { NodeId nodeId = (NodeId) super.next(); removedNodeIds.add(nodeId); return nodeId.getUUID(); } }, new AbstractIteratorDecorator(add) { public Object next() { NodeState state = (NodeState) super.next(); if (state == null) { return null; } addedNodeIds.add(state.getNodeId()); removedNodeIds.remove(state.getNodeId()); Document doc = null; try { doc = createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion()); retrieveAggregateRoot(state, aggregateRoots); } catch (RepositoryException e) { log.warn("Exception while creating document for node: " + state.getNodeId() + ": " + e.toString()); } return doc; } }); // remove any aggregateRoot nodes that are new // and therefore already up-to-date aggregateRoots.keySet().removeAll(addedNodeIds); // based on removed NodeIds get affected aggregate root nodes retrieveAggregateRoot(removedNodeIds, aggregateRoots); // update aggregates if there are any affected if (aggregateRoots.size() > 0) { index.update(new AbstractIteratorDecorator(aggregateRoots.keySet().iterator()) { public Object next() { return ((NodeId) super.next()).getUUID(); } }, new AbstractIteratorDecorator(aggregateRoots.values().iterator()) { public Object next() { NodeState state = (NodeState) super.next(); try { return createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion()); } catch (RepositoryException e) { log.warn("Exception while creating document for node: " + state.getNodeId() + ": " + e.toString()); } return null; } }); } }
From source file:org.onehippo.forge.document.commenting.cms.impl.SimpleListDataProvider.java
@Override public Iterator<? extends T> iterator(final long first, final long count) { return new AbstractIteratorDecorator(list.listIterator((int) first)) { private int iterationCount; @Override/*from w ww . j ava 2s . co m*/ public boolean hasNext() { return super.hasNext() && (iterationCount < (int) count); } @Override public Object next() { try { return super.next(); } finally { iterationCount += 1; } } }; }
From source file:org.onehippo.forge.exdocpicker.impl.SimpleExternalDocumentCollection.java
@SuppressWarnings("unchecked") @Override/* w w w. j a v a 2 s .c om*/ public Iterator<? extends T> iterator(long first, final long count) { return new AbstractIteratorDecorator(list.listIterator((int) first)) { private int iterationCount; @Override public boolean hasNext() { return super.hasNext() && (iterationCount < (int) count); } @Override public Object next() { try { return super.next(); } finally { iterationCount += 1; } } }; }
From source file:org.paxml.table.AbstractTable.java
@Override public Iterator<IRow> getRows() { ITableRange r = getRange();//from ww w .ja v a 2 s. c om Iterator<IRow> it; if (r == null) { it = getAllRows(); } else { it = new RangedIterator<IRow>(r.getFirstRow(), r.getLastRow(), getAllRows()); } return new AbstractIteratorDecorator(it) { @Override public Object next() { Object n = super.next(); currentRowIndex++; return n; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:org.paxml.table.csv.CsvRow.java
@Override protected Iterator<ICell> getAllCells() { return new AbstractIteratorDecorator(getTable().getColumnCurrentRow().iterator()) { private int index = 0; @Override//from w w w . j a v a 2 s. c o m public Object next() { return new CsvCell(CsvRow.this, index++); } }; }
From source file:org.paxml.table.excel.ExcelRow.java
@Override protected Iterator<ICell> getAllCells() { Iterator<ICell> it;//from w w w .j a v a 2 s .c o m if (getTable().isCompact()) { it = new AbstractIteratorDecorator(row.cellIterator()) { @Override public Object next() { Cell cell = (Cell) getIterator().next(); return new ExcelCell(cell, ExcelRow.this); } }; } else { it = new Iterator<ICell>() { private int i; @Override public boolean hasNext() { return i < row.getLastCellNum(); } @Override public ICell next() { return getCell(i++); } @Override public void remove() { Cell c = row.getCell(i); if (c != null) { row.removeCell(c); } } }; } return it; }
From source file:org.paxml.table.excel.ExcelTable.java
@Override protected Iterator<IRow> getAllRows() { if (compact) { Iterator it = sheet.rowIterator(); return new AbstractIteratorDecorator(it) { @Override/* w w w. j a v a 2 s. com*/ public Object next() { return new ExcelRow((Row) getIterator().next(), ExcelTable.this); } }; } else { return new Iterator<IRow>() { private int index = 0; @Override public boolean hasNext() { return index <= sheet.getLastRowNum(); } @Override public IRow next() { ExcelRow r = getRow(index); index++; return r; } @Override public void remove() { Row row = sheet.getRow(index); if (row != null) { sheet.removeRow(row); } } }; } }
From source file:org.paxml.table.jdbc.JdbcTable.java
@Override protected Iterator<IRow> getAllRows() { return new AbstractIteratorDecorator(new ResultSetIterator(rs)) { private int index; @Override//w w w . ja v a 2 s . co m public Object next() { Object[] row = (Object[]) super.next(); return new JdbcRow(index++, row, JdbcTable.this); } }; }