@Override public synchronized void addListener ( final EventListener eventListener ) { this.listeners.add ( eventListener ); final UnmodifiableIterator<List<Event>> it = Iterators.partition ( AbstractEventQueryImpl.this.events.iterator (), chunkSize ); while ( it.hasNext () ) { final List<org.eclipse.scada.ae.Event> chunk = it.next (); this.executor.execute ( new Runnable () { @Override public void run () { eventListener.handleEvent ( chunk ); } } ); } }
@Override public UnmodifiableIterator<E> iterator() { final Iterator<? extends Entry<E, ?>> entries = outEdgeToNode.entrySet().iterator(); return new AbstractIterator<E>() { @Override protected E computeNext() { while (entries.hasNext()) { Entry<E, ?> entry = entries.next(); if (targetNode.equals(entry.getValue())) { return entry.getKey(); } } return endOfData(); } }; }
/** * Returns the unique alias metadata per concrete index. * * (note that although alias can point to the same concrete indices, each alias reference may have its own routing * and filters) */ public Iterable<Tuple<String, AliasMetaData>> getConcreteIndexAndAliasMetaDatas() { return new Iterable<Tuple<String, AliasMetaData>>() { @Override public Iterator<Tuple<String, AliasMetaData>> iterator() { return new UnmodifiableIterator<Tuple<String,AliasMetaData>>() { int index = 0; @Override public boolean hasNext() { return index < referenceIndexMetaDatas.size(); } @Override public Tuple<String, AliasMetaData> next() { IndexMetaData indexMetaData = referenceIndexMetaDatas.get(index++); return new Tuple<>(indexMetaData.getIndex(), indexMetaData.getAliases().get(aliasName)); } }; } }; }
@Override public Iterator<InetSocketAddress> iterator() { return new UnmodifiableIterator<InetSocketAddress>() { private final Iterator<Map.Entry<InetAddress, Integer>> it = addrs.entries().iterator(); @Override public boolean hasNext() { return it.hasNext(); } @Override public InetSocketAddress next() { Map.Entry<InetAddress, Integer> e = it.next(); return new InetSocketAddress(e.getKey(), e.getValue()); } }; }
/** * An implementation of {@link BaseGraph#edges()} defined in terms of {@link #nodes()} and {@link * #successors(Object)}. */ @Override public Set<EndpointPair<N>> edges() { return new AbstractSet<EndpointPair<N>>() { @Override public UnmodifiableIterator<EndpointPair<N>> iterator() { return EndpointPairIterator.of(AbstractBaseGraph.this); } @Override public int size() { return Ints.saturatedCast(edgeCount()); } @Override public boolean contains(@Nullable Object obj) { if (!(obj instanceof EndpointPair)) { return false; } EndpointPair<?> endpointPair = (EndpointPair<?>) obj; return isDirected() == endpointPair.isOrdered() && nodes().contains(endpointPair.nodeU()) && successors(endpointPair.nodeU()).contains(endpointPair.nodeV()); } }; }
/** * Writes the given blockstate to the given tag. * * @param tag The tag to write to * @param state The blockstate to be written */ public static NBTTagCompound writeBlockState(NBTTagCompound tag, IBlockState state) { tag.setString("Name", ((ResourceLocation)Block.REGISTRY.getNameForObject(state.getBlock())).toString()); if (!state.getProperties().isEmpty()) { NBTTagCompound nbttagcompound = new NBTTagCompound(); UnmodifiableIterator unmodifiableiterator = state.getProperties().entrySet().iterator(); while (unmodifiableiterator.hasNext()) { Entry < IProperty<?>, Comparable<? >> entry = (Entry)unmodifiableiterator.next(); IProperty<?> iproperty = (IProperty)entry.getKey(); nbttagcompound.setString(iproperty.getName(), getName(iproperty, (Comparable)entry.getValue())); } tag.setTag("Properties", nbttagcompound); } return tag; }
public boolean hasInstantEffect() { if (!this.effects.isEmpty()) { UnmodifiableIterator unmodifiableiterator = this.effects.iterator(); while (unmodifiableiterator.hasNext()) { PotionEffect potioneffect = (PotionEffect)unmodifiableiterator.next(); if (potioneffect.getPotion().isInstant()) { return true; } } } return false; }
@Override public Optional<TRSRTransformation> apply(final Optional<? extends IModelPart> part) { if (part.isPresent()) { final UnmodifiableIterator<String> parts = Models.getParts(part.get()); if (parts.hasNext()) { final String name = parts.next(); if (!parts.hasNext() && this.blacklist && this.parts.contains(name) || !this.blacklist && !this.parts.contains(name)) return this.value; } } return Optional.empty(); }
@Test public void testListTablesRestricted() { final TableOptions options = new TableOptionsBuilder().setPlacement("my:placement").build(); final ImmutableMap<String, Object> template = ImmutableMap.<String, Object>of("key", "value1"); final TableAvailability availability = new TableAvailability("my:placement", false); final DefaultTable a1 = new DefaultTable("a-table-1", options, template, availability); final DefaultTable a2 = new DefaultTable("a-table-2", options, template, availability); final DefaultTable b1 = new DefaultTable("b-table-1", options, template, availability); final DefaultTable b2 = new DefaultTable("b-table-2", options, template, availability); final DefaultTable a3 = new DefaultTable("a-table-3", options, template, availability); final ImmutableList<Table> tables = ImmutableList.of(a1, a2, b1, b2, a3); final UnmodifiableIterator<Table> iterator = tables.iterator(); //noinspection unchecked when(_server.listTables(null, Long.MAX_VALUE)).thenAnswer(invocation -> iterator); { final Iterator<Table> tableIterator = sorClient(APIKEY_READ_TABLES_A).listTables(null, 3); final ImmutableList<Table> result = ImmutableList.copyOf(tableIterator); assertEquals(ImmutableList.<Table>of(a1, a2, a3), result); } verify(_server, times(1)).listTables(null, Long.MAX_VALUE); }
@Override public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part) { if(part.isPresent()) { // This whole thing is subject to change, but should do for now. UnmodifiableIterator<String> parts = Models.getParts(part.get()); if(parts.hasNext()) { String name = parts.next(); // only interested in the root level if(!parts.hasNext() && hidden.contains(name)) { return value; } } } return Optional.absent(); }
@Provides Iterable<Callable<Integer>> callable() { return new Iterable<Callable<Integer>>() { @Override public Iterator<Callable<Integer>> iterator() { return new UnmodifiableIterator<Callable<Integer>>() { @Override public boolean hasNext() { return true; } @Override public Callable<Integer> next() { return new Callable<Integer>() { @Override public Integer call() throws Exception { TimeMeasure.millis(3).sleep(); return 1; } }; } }; } }; }
@Override protected Iterator<IModel<T>> getItemModels(final long offset, final long size) { final List<T> list = getModelObject(); if (list == null) { return Collections.emptyIterator(); } return new UnmodifiableIterator<IModel<T>>() { private int index = (int) offset; private final int end = (int) (offset + size); @Override public boolean hasNext() { return index < end && index < internalGetItemCount(); } @Override public IModel<T> next() { return newItemModel(index++); } }; }
@Override public IHand getHighestFiveCardHand() { // if(cards.size() < 5) // { // return this; // } // return new Hand(cards.asList().reverse().subList(0,5)); UnmodifiableIterator iter = cards.iterator(); int offset = cards.size() - 5; while(offset-- > 0) { iter.next(); } return new SortedHand(cards.tailSet((Card)iter.next()) ); }
@Override public IHand getHighestFiveCardHand() { if(cards.size() < 5) { return this; } ImmutableSortedSet<Card> sortedCards = cardsSorted(); UnmodifiableIterator iter = sortedCards.iterator(); int offset = sortedCards.size() - 5; while(offset-- > 0) { iter.next(); } return new SortedHand(sortedCards.tailSet((Card)iter.next()) ); }
@Override public Iterator<KAFDocument> iterator() { return new UnmodifiableIterator<KAFDocument>() { private int index = 0; @Override public boolean hasNext() { return this.index < Corpus.this.files.length; } @Override public KAFDocument next() { return get(this.index++); } }; }
@Test public void testReplacingValueInThirdRange() { final ImmutableCollection<Range> existingRanges = makeSomeRanges(); final long intendedNumBytesToTransfer = numBytesToTransfer(existingRanges, existingRanges.size()); final long numBytesTransferred = 27000; final ImmutableCollection<Range> newRanges = RangeHelper.replaceRange(existingRanges, numBytesTransferred, intendedNumBytesToTransfer); assertEquals(1, newRanges.size()); final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator(); existingRangesIterator.next(); final long lengthOf2ndRange = existingRangesIterator.next().getLength(); final long expectedStartIn3rdRange = lengthOf2ndRange + numBytesTransferred; assertEquals(expectedStartIn3rdRange, newRanges.iterator().next().getStart()); assertEquals(existingRangesIterator.next().getEnd(), newRanges.iterator().next().getEnd()); }
@Test public void testReplacingValueWhenWeTransferExactlyFirstRange() { final ImmutableCollection<Range> existingRanges = makeSomeRanges(); final long intendedNumBytesToTransfer = numBytesToTransfer(existingRanges, existingRanges.size()); final long numBytesTransferred = existingRanges.iterator().next().getLength(); final ImmutableCollection<Range> newRanges = RangeHelper.replaceRange(existingRanges, numBytesTransferred, intendedNumBytesToTransfer); assertEquals(2, newRanges.size()); final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator(); existingRangesIterator.next(); final UnmodifiableIterator<Range> newRangesIterator = newRanges.iterator(); while (existingRangesIterator.hasNext()) { final Range existingRange = existingRangesIterator.next(); final Range newRange = newRangesIterator.next(); assertEquals(existingRange.getStart(), newRange.getStart()); assertEquals(existingRange.getLength(), newRange.getLength()); } }
@Test public void testReplacingValueWhenWeTransferExactly1st2Ranges() { final ImmutableCollection<Range> existingRanges = makeSomeRanges(); final long intendedNumBytesToTransfer = numBytesToTransfer(existingRanges, existingRanges.size()); final long numBytesTransferred = numBytesToTransfer(existingRanges, 2); final ImmutableCollection<Range> newRanges = RangeHelper.replaceRange(existingRanges, numBytesTransferred, intendedNumBytesToTransfer); assertEquals(1, newRanges.size()); final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator(); existingRangesIterator.next(); existingRangesIterator.next(); final UnmodifiableIterator<Range> newRangesIterator = newRanges.iterator(); while (existingRangesIterator.hasNext()) { final Range existingRange = existingRangesIterator.next(); final Range newRange = newRangesIterator.next(); assertEquals(existingRange.getStart(), newRange.getStart()); assertEquals(existingRange.getLength(), newRange.getLength()); } }
@Test public void testReplacingValueWhenWeTransfer0Bytes() { final ImmutableCollection<Range> existingRanges = makeSomeRanges(); final long intendedNumBytesToTransfer = numBytesToTransfer(existingRanges, existingRanges.size()); final long numBytesTransferred = 0; final ImmutableCollection<Range> newRanges = RangeHelper.replaceRange(existingRanges, numBytesTransferred, intendedNumBytesToTransfer); assertEquals(3, newRanges.size()); final UnmodifiableIterator<Range> existingRangesIterator = existingRanges.iterator(); final UnmodifiableIterator<Range> newRangesIterator = newRanges.iterator(); while (existingRangesIterator.hasNext()) { final Range existingRange = existingRangesIterator.next(); final Range newRange = newRangesIterator.next(); assertEquals(existingRange.getStart(), newRange.getStart()); assertEquals(existingRange.getLength(), newRange.getLength()); } }
@Override public UnmodifiableIterator<EndpointPair<N>> iterator() { return Iterators.unmodifiableIterator( Iterators.concat( Iterators.transform( graph.predecessors(node).iterator(), new Function<N, EndpointPair<N>>() { @Override public EndpointPair<N> apply(N predecessor) { return EndpointPair.ordered(predecessor, node); } }), Iterators.transform( // filter out 'node' from successors (already covered by predecessors, above) Sets.difference(graph.successors(node), ImmutableSet.of(node)).iterator(), new Function<N, EndpointPair<N>>() { @Override public EndpointPair<N> apply(N successor) { return EndpointPair.ordered(node, successor); } }))); }
private void handle(final BatchStatement batchStmt, final UnmodifiableIterator<T> batchablesIt, final Function<T, ListenableFuture<Statement>> statementFetcher) { if (batchablesIt.hasNext()) { final ListenableFuture<Statement> statementFuture = statementFetcher.apply(batchablesIt.next()); Runnable resultHandler = new Runnable() { @Override public void run() { try { batchStmt.add(statementFuture.get()); handle(batchStmt, batchablesIt, statementFetcher); } catch (InterruptedException | ExecutionException | RuntimeException e) { setException(ListenableFutures.unwrapIfNecessary(e)); } } }; statementFuture.addListener(resultHandler, MoreExecutors.directExecutor()); } else { set(batchStmt); } }
@Override public Iterator<ClusterCentroid> iterator() { return new UnmodifiableIterator<ClusterCentroid>() { private int index = 0; @Override public final boolean hasNext() { return index < components.length; } @Override public final ClusterCentroid next() { return components[index++]; } }; }
@Override public Iterator<Numeric> iterator() { return new UnmodifiableIterator<Numeric>() { private int index = 0; @Override public final boolean hasNext() { return index < components.length; } @Override public final Numeric next() { return components[index++]; } }; }
/** * Obtain an unmodifiable iterator to traverse the {@code Vector} iteratively. * @return An {@code Iterator} of {@code Numeric}s. * @throws UnsupportedOperationException if {@code remove()} is called. */ @Override public Iterator<Numeric> iterator() { return new UnmodifiableIterator<Numeric>() { private int index = 0; @Override public final boolean hasNext() { return index < components.length; } @Override public final Numeric next() { return components[index++]; } }; }
@Nonnull @Override public Iterator<E> iterator() { return new UnmodifiableIterator<E>() { private int offset = 0; @Override public boolean hasNext() { return offset < array.length; } @Override public E next() { if (offset >= array.length) { throw new NoSuchElementException(); } return array[offset++]; } }; }
@Nonnull @Override public Iterator<Entry<K, V>> iterator() { final Iterator<Entry<K, Integer>> it = offsets.entrySet().iterator(); return new UnmodifiableIterator<Entry<K, V>>() { @Override public boolean hasNext() { return it.hasNext(); } @Override public Entry<K, V> next() { final Entry<K, Integer> e = it.next(); return new SimpleImmutableEntry<>(e.getKey(), objects[e.getValue()]); } }; }
/** * Returns the list of nodes which need to be traversed to get from this * node to the starting point (root for absolute SchemaPaths). * * @return list of <code>qname</code> instances which represents * path from the schema node towards the root. */ public Iterable<QName> getPathTowardsRoot() { return () -> new UnmodifiableIterator<QName>() { private SchemaNodeIdentifier current = SchemaNodeIdentifier.this; @Override public boolean hasNext() { return current.parent != null; } @Override public QName next() { if (current.parent != null) { final QName ret = current.qname; current = current.parent; return ret; } else { throw new NoSuchElementException("No more elements available"); } } }; }
/** * Returns the list of nodes which need to be traversed to get from this * node to the starting point (root for absolute SchemaPaths). * * @return list of <code>qname</code> instances which represents * path from the schema node towards the root. */ public Iterable<QName> getPathTowardsRoot() { return () -> new UnmodifiableIterator<QName>() { private SchemaPath current = SchemaPath.this; @Override public boolean hasNext() { return current.parent != null; } @Override public QName next() { if (current.parent != null) { final QName ret = current.qname; current = current.parent; return ret; } throw new NoSuchElementException("No more elements available"); } }; }
public int compareTo(@Nonnull RelMultipleTrait o) { final RelCollationImpl that = (RelCollationImpl) o; final UnmodifiableIterator<RelFieldCollation> iterator = that.fieldCollations.iterator(); for (RelFieldCollation f : fieldCollations) { if (!iterator.hasNext()) { return 1; } final RelFieldCollation f2 = iterator.next(); int c = Utilities.compare(f.getFieldIndex(), f2.getFieldIndex()); if (c != 0) { return c; } } return iterator.hasNext() ? -1 : 0; }
public static void main(String[] args) throws IOException { checkArgument( args.length == 2, "Usage: %s <input-jar> <output-jar>", Bug62456849TestDataGenerator.class.getName()); Path inputJar = Paths.get(args[0]); checkArgument(Files.isRegularFile(inputJar), "The input jar %s is not a file", inputJar); Path outputJar = Paths.get(args[1]); try (ZipFile inputZip = new ZipFile(inputJar.toFile()); ZipOutputStream outZip = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(outputJar)))) { for (UnmodifiableIterator<? extends ZipEntry> it = Iterators.forEnumeration(inputZip.entries()); it.hasNext(); ) { ZipEntry entry = it.next(); String entryName = entry.getName(); byte[] content = entryName.endsWith(".class") ? convertClass(inputZip, entry) : readEntry(inputZip, entry); writeToZipFile(outZip, entryName, content); } } }
@Override public Iterable<Track> loadTracks(final Iterable<Id> ids) throws IOException { return new Iterable<Track>() { @Override public Iterator<Track> iterator() { return new UnmodifiableIterator<Track>() { Iterator<Id> delegate = ids.iterator(); @Override public boolean hasNext() { return this.delegate.hasNext(); } @Override public Track next() { return loadTrack(this.delegate.next()); } }; } }; }
/** * This node and the transitive closure of its {@link #parent}s. */ public Iterable<CssNode> ancestors() { return new Iterable<CssNode>() { @Override public Iterator<CssNode> iterator() { return new UnmodifiableIterator<CssNode>() { private CssNode current = CssNode.this; @Override public boolean hasNext() { return current != null; } @Override public CssNode next() { CssNode result = current; current = current.getParent(); return result; } }; } }; }