com.google.common.collect.AbstractSequentialIterator Java Examples

The following examples show how to use com.google.common.collect.AbstractSequentialIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTestParquetReader.java    From presto with Apache License 2.0 6 votes vote down vote up
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;
        }
    };
}
 
Example #2
Source File: ProductPartitionTreeImpl.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
  };
}
 
Example #3
Source File: PrestoS3FileSystem.java    From presto with Apache License 2.0 5 votes vote down vote up
private Iterator<LocatedFileStatus> listPrefix(Path path)
{
    String key = keyFromPath(path);
    if (!key.isEmpty()) {
        key += PATH_SEPARATOR;
    }

    ListObjectsV2Request request = new ListObjectsV2Request()
            .withBucketName(getBucketName(uri))
            .withPrefix(key)
            .withDelimiter(PATH_SEPARATOR)
            .withRequesterPays(requesterPaysEnabled);

    STATS.newListObjectsCall();
    Iterator<ListObjectsV2Result> listings = new AbstractSequentialIterator<ListObjectsV2Result>(s3.listObjectsV2(request))
    {
        @Override
        protected ListObjectsV2Result computeNext(ListObjectsV2Result previous)
        {
            if (!previous.isTruncated()) {
                return null;
            }

            request.setContinuationToken(previous.getNextContinuationToken());

            return s3.listObjectsV2(request);
        }
    };

    return Iterators.concat(Iterators.transform(listings, this::statusFromListing));
}
 
Example #4
Source File: PrestoS3FileSystem.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
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));
}
 
Example #5
Source File: ShiroAuthorizingParamInterceptor.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 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.ofNullable(declaringClass.getSuperclass())
              .map(ImmutableSet::of)
              .orElse(ImmutableSet.of()))
          .addAll(ImmutableList.copyOf(declaringClass.getInterfaces()))
          .build();

      for (Class<?> klazz : searchOrder) {
        try {
          return klazz.getMethod(name, parameterTypes);
        } catch (NoSuchMethodException ignored) {
          // Expected.
        }
      }

      return null;
    }
  };
}
 
Example #6
Source File: CidrAddressBlock.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@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;
    }
  };
}
 
Example #7
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #8
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #9
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #10
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #11
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
                                                                                         }
                     };
}
 
Example #12
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
                                                                                        }
                     };
}
 
Example #13
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #14
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #15
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #16
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #17
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #18
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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;
    }
  };
}
 
Example #19
Source File: LocalCache.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@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;
    }
  };
}
 
Example #20
Source File: LocalCache.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
@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;
    }
  };
}