private static Iterable<Double> doubleSequence(double start, double step, int items) { return () -> new AbstractSequentialIterator<Double>(start) { private int item; @Override protected Double computeNext(Double previous) { if (item >= items) { return null; } item++; return previous + step; } }; }
@Override public Iterator<ReferenceEntry<K, V>> iterator() { return new AbstractSequentialIterator<ReferenceEntry<K, V>>(peek()) { @Override protected ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> previous) { ReferenceEntry<K, V> next = previous.getNextInWriteQueue(); return (next == head) ? null : next; } }; }
@Override public Iterator<ReferenceEntry<K, V>> iterator() { return new AbstractSequentialIterator<ReferenceEntry<K, V>>(peek()) { @Override protected ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> previous) { ReferenceEntry<K, V> next = previous.getNextInAccessQueue(); return (next == head) ? null : next; } }; }
/** * Return each method in the inheritance hierarchy of method in the order described by * {@link AuthorizingParam}. * * @see org.apache.aurora.scheduler.http.api.security.AuthorizingParam */ private static Iterable<Method> getCandidateMethods(final Method method) { return () -> new AbstractSequentialIterator<Method>(method) { @Override protected Method computeNext(Method previous) { String name = previous.getName(); Class<?>[] parameterTypes = previous.getParameterTypes(); Class<?> declaringClass = previous.getDeclaringClass(); if (declaringClass.isInterface()) { return null; } Iterable<Class<?>> searchOrder = ImmutableList.<Class<?>>builder() .addAll(Optional.fromNullable(declaringClass.getSuperclass()).asSet()) .addAll(ImmutableList.copyOf(declaringClass.getInterfaces())) .build(); for (Class<?> klazz : searchOrder) { try { return klazz.getMethod(name, parameterTypes); } catch (NoSuchMethodException ignored) { // Expected. } } return null; } }; }
@Override public Iterator<InetAddress> iterator() { return new AbstractSequentialIterator<InetAddress>(ip) { @Override protected InetAddress computeNext(InetAddress previous) { if (InetAddresses.isMaximum(previous)) { return null; } InetAddress next = InetAddresses.increment(previous); return (contains(next)) ? next : null; } }; }
@Override public Iterator<CsvRow> iterator() { return new AbstractSequentialIterator<CsvRow>(getRow(0)) { @Override protected CsvRow computeNext(CsvRow previous) { return getRow(previous.getIndex() + 1); } }; }
@Override public Iterator<CsvCell> iterator() { return new AbstractSequentialIterator<CsvCell>(getCell(0)) { @Override protected CsvCell computeNext(CsvCell previous) { return getCell(previous.getIndex() + 1); } }; }
public Iterator<TokenStreamFragment.Node> iterator() { return new AbstractSequentialIterator<TokenStreamFragment.Node>(getStart()) { @Override protected TokenStreamFragment.Node computeNext(TokenStreamFragment.Node previous) { return previous == getEnd() ? null : previous.getNext(); } }; }
private Iterator<LocatedFileStatus> listPrefix(Path path) { String key = keyFromPath(path); if (!key.isEmpty()) { key += "/"; } ListObjectsRequest request = new ListObjectsRequest() .withBucketName(uri.getHost()) .withPrefix(key) .withDelimiter("/"); STATS.newListObjectsCall(); Iterator<ObjectListing> listings = new AbstractSequentialIterator<ObjectListing>(s3.listObjects(request)) { @Override protected ObjectListing computeNext(ObjectListing previous) { if (!previous.isTruncated()) { return null; } return s3.listNextBatchOfObjects(previous); } }; return Iterators.concat(Iterators.transform(listings, this::statusFromListing)); }
/** * Returns an iterable of all superclasses of this class, in ascending * order; thus, the first class is the immediate superclass. * @return an an iterable of all superclasses of this class */ public Iterable<Klass> superclasses() { return new Iterable<Klass>() { @Override public Iterator<Klass> iterator() { return new AbstractSequentialIterator<Klass>(getSuperclass()) { @Override protected Klass computeNext(Klass previous) { return previous.getSuperclass(); } }; } }; }
private Iterator<LocatedFileStatus> listPrefix(Path path) { String key = keyFromPath(path); if (!key.isEmpty()) { key += PATH_SEPARATOR; } ListObjectsRequest request = new ListObjectsRequest() .withBucketName(uri.getHost()) .withPrefix(key) .withDelimiter(PATH_SEPARATOR); STATS.newListObjectsCall(); Iterator<ObjectListing> listings = new AbstractSequentialIterator<ObjectListing>(s3.listObjects(request)) { @Override protected ObjectListing computeNext(ObjectListing previous) { if (!previous.isTruncated()) { return null; } return s3.listNextBatchOfObjects(previous); } }; return Iterators.concat(Iterators.transform(listings, this::statusFromListing)); }
/** * Constructor that initializes the temp ID generator based on the ID of the root node. * * @param adGroupId the ID of the ad group * @param biddingStrategyConfig the bidding strategy configuration of the ad group * @param rootNode the root node of the tree */ ProductPartitionTreeImpl(long adGroupId, BiddingStrategyConfiguration biddingStrategyConfig, ProductPartitionNode rootNode) { this.adGroupId = adGroupId; this.biddingStrategyConfig = Preconditions.checkNotNull(biddingStrategyConfig, "Null bidding strategy configuration"); this.root = Preconditions.checkNotNull(rootNode, "Null root node"); long startingTempId; this.dimensionComparator = new ProductDimensionComparator(); if (this.root.getProductPartitionId() < 0L) { // The root has a temporary ID, so all changes made to this tree should result in ADD // operations. originalRoot = null; startingTempId = -1L; } else { // Set originalRoot to a deep copy of the root node. originalRoot = new ProductPartitionNode(null, root.getDimension(), root.getProductPartitionId(), this.dimensionComparator); long minimumId = cloneChildrenToNewParent(originalRoot, root.getChildren(), originalRoot.getProductPartitionId()); // The starting temp ID should be -1 if all nodes are non-temporary (have positive IDs), // else start at one less than the lowest ID found in the tree. startingTempId = minimumId >= 0L ? -1L : minimumId - 1L; } this.idGenerator = new AbstractSequentialIterator<Long>(startingTempId) { @Override protected Long computeNext(Long previous) { return Long.MIN_VALUE == previous.longValue() ? null : previous - 1; } }; }