public MessageIterator(final KafkaConsumer<byte[], byte[]> kafkaConsumer, final KafkaPartitionScanSpec subScanSpec, final long kafkaPollTimeOut) { this.kafkaConsumer = kafkaConsumer; this.kafkaPollTimeOut = kafkaPollTimeOut; List<TopicPartition> partitions = Lists.newArrayListWithCapacity(1); topicPartition = new TopicPartition(subScanSpec.getTopicName(), subScanSpec.getPartitionId()); partitions.add(topicPartition); this.kafkaConsumer.assign(partitions); logger.info("Start offset of {}:{} is - {}", subScanSpec.getTopicName(), subScanSpec.getPartitionId(), subScanSpec.getStartOffset()); this.kafkaConsumer.seek(topicPartition, subScanSpec.getStartOffset()); this.endOffset = subScanSpec.getEndOffset(); }
@Override protected ArrayList<LockGraphNode> initialValue() { return Lists.<LockGraphNode>newArrayListWithCapacity(3); } };
private static List<String> getNames(List<IdentifierHolder> identifiers) { List<String> names = Lists.newArrayListWithCapacity(identifiers.size()); for (IdentifierHolder h : identifiers) { names.add(h.value); } return names; }
public SqlNode getAsCompoundIdentifier() { List<String> names = Lists.newArrayListWithCapacity(ids.size()); List<SqlParserPos> pos = Lists.newArrayListWithCapacity(ids.size()); for (IdentifierHolder holder : ids) { names.add(holder.value); pos.add(holder.parserPos); } return new SqlIdentifier(names, null, pos.get(0), pos); }
/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { int size = remaining.length + 6; List<E> all = Lists.newArrayListWithCapacity(size); Collections.addAll(all, e1, e2, e3, e4, e5, e6); Collections.addAll(all, remaining); return copyOf(Ordering.natural(), all); }
/** * Gets an iterator representing an immutable snapshot of all subscribers to the given event at * the time this method is called. */ Iterator<Subscriber> getSubscribers(Object event) { ImmutableSet<Class<?>> eventTypes = flattenHierarchy(event.getClass()); List<Iterator<Subscriber>> subscriberIterators = Lists.newArrayListWithCapacity(eventTypes.size()); for (Class<?> eventType : eventTypes) { CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType); if (eventSubscribers != null) { // eager no-copy snapshot subscriberIterators.add(eventSubscribers.iterator()); } } return Iterators.concat(subscriberIterators.iterator()); }
/** * For a given Enum type, creates an immutable map from each of the Enum's values to a * corresponding LockGraphNode, with the {@code allowedPriorLocks} and * {@code disallowedPriorLocks} prepopulated with nodes according to the natural ordering of the * associated Enum values. */ @VisibleForTesting static <E extends Enum<E>> Map<E, LockGraphNode> createNodes(Class<E> clazz) { EnumMap<E, LockGraphNode> map = Maps.newEnumMap(clazz); E[] keys = clazz.getEnumConstants(); final int numKeys = keys.length; ArrayList<LockGraphNode> nodes = Lists.newArrayListWithCapacity(numKeys); // Create a LockGraphNode for each enum value. for (E key : keys) { LockGraphNode node = new LockGraphNode(getLockName(key)); nodes.add(node); map.put(key, node); } // Pre-populate all allowedPriorLocks with nodes of smaller ordinal. for (int i = 1; i < numKeys; i++) { nodes.get(i).checkAcquiredLocks(Policies.THROW, nodes.subList(0, i)); } // Pre-populate all disallowedPriorLocks with nodes of larger ordinal. for (int i = 0; i < numKeys - 1; i++) { nodes.get(i).checkAcquiredLocks(Policies.DISABLED, nodes.subList(i + 1, numKeys)); } return Collections.unmodifiableMap(map); }
int ntasks = tasks.size(); checkArgument(ntasks > 0); List<Future<T>> futures = Lists.newArrayListWithCapacity(ntasks); BlockingQueue<Future<T>> futureQueue = Queues.newLinkedBlockingQueue(); long timeoutNanos = unit.toNanos(timeout);
/** Utility method to get the schema path as list for given schema instance. */ public static List<String> getSchemaPathAsList(SchemaPlus schema) { if (isRootSchema(schema)) { return Collections.emptyList(); } List<String> path = Lists.newArrayListWithCapacity(5); while(schema != null) { final String name = schema.getName(); if (!Strings.isNullOrEmpty(name)) { path.add(schema.getName()); } schema = schema.getParentSchema(); } return Lists.reverse(path); }
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Map.Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
result.outputNames = Lists.newArrayListWithCapacity(incomingSchemaSize); for (int j=0; j < incomingSchemaSize; j++) { result.outputNames = Lists.newArrayListWithCapacity(incomingSchemaSize); for (int j=0; j < incomingSchemaSize; j++) {
List<TypeProtos.MinorType> types = Lists.newArrayListWithCapacity(2); types.add(Types.getMinorTypeFromName(type1.getSqlTypeName().getName())); types.add(Types.getMinorTypeFromName(type2.getSqlTypeName().getName()));