List of usage examples for java.util Iterator Iterator
Iterator
From source file:org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl.java
private synchronized void addContainersToStretchToProto() { maybeInitBuilder();/*from w w w . j av a2 s . c om*/ builder.clearContainersToStretch(); if (containersToStretch == null) return; Iterable<ContainerIdProto> iterable = new Iterable<ContainerIdProto>() { @Override public Iterator<ContainerIdProto> iterator() { return new Iterator<ContainerIdProto>() { Iterator<ContainerId> iter = containersToStretch.iterator(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public ContainerIdProto next() { return convertToProtoFormat(iter.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; builder.addAllContainersToStretch(iterable); }
From source file:com.linkedin.pinot.core.startree.StarTreeDataTable.java
public Iterator<Pair<byte[], byte[]>> iterator(int startDocId, int endDocId) throws IOException { try {//w w w . j av a2s . com final int length = endDocId - startDocId; final long startOffset = startDocId * (long) totalSizeInBytes; final MMapBuffer mappedByteBuffer = new MMapBuffer(file, startOffset, length * (long) totalSizeInBytes, MMapMode.READ_WRITE); return new Iterator<Pair<byte[], byte[]>>() { int pointer = 0; @Override public boolean hasNext() { return pointer < length; } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public Pair<byte[], byte[]> next() { byte[] dimBuff = new byte[dimensionSizeInBytes]; byte[] metBuff = new byte[metricSizeInBytes]; mappedByteBuffer.toDirectByteBuffer(pointer * (long) totalSizeInBytes, dimensionSizeInBytes) .get(dimBuff); // mappedByteBuffer.position(pointer * totalSizeInBytes); // mappedByteBuffer.get(dimBuff); if (metricSizeInBytes > 0) { mappedByteBuffer .toDirectByteBuffer(pointer * (long) totalSizeInBytes + dimensionSizeInBytes, metricSizeInBytes) .get(metBuff); // mappedByteBuffer.get(metBuff); } pointer = pointer + 1; if (pointer == length) { try { mappedByteBuffer.close(); } catch (IOException e) { e.printStackTrace(); } } return Pair.of(dimBuff, metBuff); } }; } catch (IOException e) { throw e; } finally { //IOUtils.closeQuietly(randomAccessFile); } }
From source file:org.onehippo.repository.update.UpdaterInfo.java
Iterator<String> getUpdatedNodes() { if (updatedNodes != null) { try {/* w ww .j a va2 s. c o m*/ final BufferedReader reader = new BufferedReader(new InputStreamReader(updatedNodes.getStream())); return new Iterator<String>() { private String next; private boolean closed; private void fetchNext() { if (next == null && !closed) { try { next = reader.readLine(); } catch (IOException e) { log.error("Failed to read next line of updated paths", e); } if (next == null) { IOUtils.closeQuietly(reader); closed = true; } } } @Override public boolean hasNext() { fetchNext(); return next != null; } @Override public String next() { if (hasNext()) { final String result = next; next = null; return result; } throw new NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } catch (RepositoryException e) { log.error("Failed to read updated nodes property", e); } } return Collections.<String>emptyList().iterator(); }
From source file:Cache.java
public synchronized Collection<V> values() { // First, clear all entries that have been in cache longer than the // maximum defined age. deleteExpiredEntries();/*from w ww.j av a 2s. co m*/ return Collections.unmodifiableCollection(new AbstractCollection<V>() { Collection<CacheObject<V>> values = map.values(); public Iterator<V> iterator() { return new Iterator<V>() { Iterator<CacheObject<V>> it = values.iterator(); public boolean hasNext() { return it.hasNext(); } public V next() { return it.next().object; } public void remove() { it.remove(); } }; } public int size() { return values.size(); } }); }
From source file:cross.datastructures.fragments.CachedList.java
@Override public Iterator<Array> iterator() { return new Iterator<Array>() { private int start = offset; private final int end = size(); @Override//from www . j a v a 2 s. co m public boolean hasNext() { return (this.start < this.end); } @Override public Array next() { return get(this.start++); } @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } }; }
From source file:com.nofuturecorp.www.connector.DataSet.java
@Override public Iterator<ColumnSet> iterator() { return new Iterator<ColumnSet>() { @Override//from ww w. j a v a 2s . com public boolean hasNext() { if (dataSet != null && dataSet.size() > 0) { if (position >= dataSet.size() - 1) { position = -1; return false; } else { return true; } } else { position = -1; return false; } } @Override public ColumnSet next() { if (position == dataSet.size()) { throw new NoSuchElementException(); } position++; return dataSet.get(position); } @Override public void remove() { } }; }
From source file:org.onehippo.forge.document.commenting.cms.impl.DefaultDocumentCommentingFieldPlugin.java
private RefreshingView<? extends Serializable> createRefreshingView() { return new RefreshingView<Serializable>("view") { private static final long serialVersionUID = 1L; private IDataProvider<CommentItem> dataProvider = new SimpleListDataProvider<CommentItem>( currentCommentItems);//from w w w. j a va 2 s. c o m @Override protected Iterator getItemModels() { final Iterator<? extends CommentItem> baseIt = dataProvider.iterator(0, currentCommentItems.size()); return new Iterator<IModel<CommentItem>>() { public boolean hasNext() { return baseIt.hasNext(); } public IModel<CommentItem> next() { return dataProvider.model(baseIt.next()); } public void remove() { baseIt.remove(); } }; } @Override protected void populateItem(Item item) { final CommentItem comment = (CommentItem) item.getModelObject(); final Session userJcrSession = UserSession.get().getJcrSession(); final Label commentHeadLabel = new Label("docitem-head-text", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return getCommentPersistenceManager().getCommentHeadText(getCommentingContext(), comment); } }); commentHeadLabel.setEscapeModelStrings(false); item.add(commentHeadLabel); final String headTooltip = getCommentPersistenceManager() .getCommentHeadTooltip(getCommentingContext(), comment); if (StringUtils.isNotBlank(headTooltip)) { commentHeadLabel.add(new AttributeModifier("title", new Model<String>(headTooltip))); } final Label commentBodyLabel = new Label("docitem-body-text", new Model<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return getCommentPersistenceManager().getCommentBodyText(getCommentingContext(), comment); } }); commentBodyLabel.setEscapeModelStrings(false); item.add(commentBodyLabel); final String bodyTooltip = getCommentPersistenceManager() .getCommentBodyTooltip(getCommentingContext(), comment); if (StringUtils.isNotBlank(bodyTooltip)) { commentBodyLabel.add(new AttributeModifier("title", new Model<String>(bodyTooltip))); } if (item.getIndex() == currentCommentItems.size() - 1) { item.add(new AttributeAppender("class", new Model("last"), " ")); } final DialogAction editDialogAction = new DialogAction( createDialogFactory(comment, new SerializableCallable<Object>() { @Override public Object call() throws Exception { refreshCommentItems(); return refreshDocumentEditorWithSelectedCompounds(); } }), getDialogService()); AjaxLink editLink = new AjaxLink("edit") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { editDialogAction.execute(); } }; final Image editImage = new Image("edit-image") { private static final long serialVersionUID = 1L; }; editImage.setImageResourceReference(EDIT_ICON_REF, null); editLink.add(editImage); editLink.setVisible(isEditableCommentItem(userJcrSession, comment)); item.add(editLink); AjaxLink deleteLink = new AjaxLink("delete") { private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget target) { try { final ConfirmDialog confirmDlg = new ConfirmDialog( new StringResourceModel("confirm.delete.comment.title", this, null, "Confirmation"), new StringResourceModel("confirm.delete.comment.message", this, null, "Are you sure to delete the item?")) { @Override public void invokeWorkflow() throws Exception { getCommentPersistenceManager().deleteCommentItem(getCommentingContext(), comment); currentCommentItems.remove(comment); refreshDocumentEditorWithSelectedCompounds(); } }; getDialogService().show(confirmDlg); } catch (CommentingException e) { log.error("Failed to delete comment.", e); } } }; final Image deleteImage = new Image("delete-image") { private static final long serialVersionUID = 1L; }; deleteImage.setImageResourceReference(DELETE_ICON_REF, null); deleteLink.add(deleteImage); deleteLink.setVisible(isDeletableCommentItem(userJcrSession, comment)); item.add(deleteLink); } }; }
From source file:act.installer.brenda.SQLConnection.java
/** * Iterate over all BRENDA ligands (from the ligands_molfiles table). * @return An iterator over all BRENDA ligands. * @throws SQLException/*from ww w.j av a 2s . co m*/ */ public Iterator<BrendaSupportingEntries.Ligand> getLigands() throws SQLException { final PreparedStatement stmt = brendaLigandConn.prepareStatement(BrendaSupportingEntries.Ligand.QUERY); final ResultSet results = stmt.executeQuery(); return new Iterator<BrendaSupportingEntries.Ligand>() { @Override public boolean hasNext() { return hasNextHelper(results, stmt); } @Override public BrendaSupportingEntries.Ligand next() { try { results.next(); return BrendaSupportingEntries.Ligand.fromResultSet(results); } catch (SQLException e) { throw new RuntimeException(e); } } }; }
From source file:ArrayMap.java
/** * @see java.util.Map#values()/*from ww w . j a va2s . co m*/ */ public Collection<V> values() { final Object[] iterKeys = theKeys; final Object[] iterVals = theValues; return new java.util.AbstractSet<V>() { @Override public int size() { return iterVals.length; } @Override public Iterator<V> iterator() { return new Iterator<V>() { private int index = 0; public boolean hasNext() { return index < iterVals.length; } public V next() { V ret = (V) iterVals[index]; index++; return ret; } public void remove() { ArrayMap.this.remove(iterKeys[index - 1]); } }; } }; }
From source file:org.dcache.chimera.FsSqlDriver.java
/** * the same as listDir, but array of {@HimeraDirectoryEntry} is returned, which contains * file attributes as well./*from w ww .ja v a 2 s . com*/ * * @param dir * @return */ DirectoryStreamB<HimeraDirectoryEntry> newDirectoryStream(FsInode dir) { return new DirectoryStreamB<HimeraDirectoryEntry>() { final DirectoryStreamImpl stream = new DirectoryStreamImpl(dir, _jdbc); @Override public Iterator<HimeraDirectoryEntry> iterator() { return new Iterator<HimeraDirectoryEntry>() { private HimeraDirectoryEntry current = innerNext(); @Override public boolean hasNext() { return current != null; } @Override public HimeraDirectoryEntry next() { if (current == null) { throw new NoSuchElementException("No more entries"); } HimeraDirectoryEntry entry = current; current = innerNext(); return entry; } protected HimeraDirectoryEntry innerNext() { try { ResultSet rs = stream.next(); if (rs == null) { return null; } Stat stat = toStat(rs); FsInode inode = new FsInode(dir.getFs(), rs.getLong("inumber"), FsInodeType.INODE, 0, stat); inode.setParent(dir); return new HimeraDirectoryEntry(rs.getString("iname"), inode, stat); } catch (SQLException e) { _log.error("failed to fetch next entry: {}", e.getMessage()); return null; } } }; } @Override public void close() throws IOException { stream.close(); } }; }