@Override public Set<Entry<K, V>> entrySet() { return Sets.newHashSet(Iterables.transform(primary.entrySet(), new Function<Entry<K, Entry<Integer, V>>, Entry<K, V>>() { @Override public Entry<K, V> apply(Entry<K, Entry<Integer, V>> entry) { return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getValue()); } })); } };
private static <T extends LogicalOperator> Iterable<T> findOperator(LogicalPlan plan, final Class<T> operatorClazz) { return (Iterable<T>) Iterables.filter(plan.getSortedOperators(), new Predicate<LogicalOperator>() { @Override public boolean apply(LogicalOperator input) { return input.getClass().equals(operatorClazz); } }); }
private static <T extends LogicalOperator> T findOnlyOperator(LogicalPlan plan, final Class<T> operatorClazz) { return Iterables.getOnlyElement(findOperator(plan, operatorClazz)); }
/** * Returns a new, <i>mutable</i> {@code EnumSet} instance containing the given elements in their * natural order. This method behaves identically to {@link EnumSet#copyOf(Collection)}, but also * accepts non-{@code Collection} iterables and empty iterables. */ public static <E extends Enum<E>> EnumSet<E> newEnumSet( Iterable<E> iterable, Class<E> elementType) { EnumSet<E> set = EnumSet.noneOf(elementType); Iterables.addAll(set, iterable); return set; }
public static boolean includesIdField(Collection<FieldPath> projected) { return Iterables.tryFind(projected, path -> Preconditions.checkNotNull(path).equals(ID_FIELD)).isPresent(); }
@Override public Iterator<T> iterator() { return Iterators.mergeSorted( Iterables.transform(iterables, Iterables.<T>toIterator()), comparator); } };
allExpressions.add(newElseExpr); boolean containsNullExpr = Iterables.any(allExpressions, new Predicate<LogicalExpression>() { @Override public boolean apply(LogicalExpression input) { Optional<LogicalExpression> nonNullExpr = Iterables.tryFind(allExpressions, new Predicate<LogicalExpression>() { @Override
@Override public void clear() { Iterables.removeIf(unfiltered, predicate); }
@Override public Iterator<OptionValue> iterator() { return Iterables.concat(fallback, getLocalOptions()).iterator(); }
/** * Returns the element at the specified position in this fluent iterable. * * <p><b>{@code Stream} equivalent:</b> {@code stream.skip(position).findFirst().get()} (but note * that this throws different exception types, and throws an exception if {@code null} would be * returned). * * @param position position of the element to return * @return the element at the specified position in this fluent iterable * @throws IndexOutOfBoundsException if {@code position} is negative or greater than or equal to * the size of this fluent iterable */ // TODO(kevinb): add @Nullable? public final E get(int position) { return Iterables.get(getDelegate(), position); }
@Override public boolean isEmpty() { return !Iterables.any(unfiltered, predicate); }
/** * Creates a fluent iterable with the first {@code size} elements of this fluent iterable. If this * fluent iterable does not contain that many elements, the returned fluent iterable will have the * same behavior as this fluent iterable. The returned fluent iterable's iterator supports {@code * remove()} if this fluent iterable's iterator does. * * <p><b>{@code Stream} equivalent:</b> {@link Stream#limit} (same). * * @param maxSize the maximum number of elements in the returned fluent iterable * @throws IllegalArgumentException if {@code size} is negative */ public final FluentIterable<E> limit(int maxSize) { return from(Iterables.limit(getDelegate(), maxSize)); }
/** * Returns a new {@code EnumMultiset} instance containing the given elements. Unlike * {@link EnumMultiset#create(Iterable)}, this method does not produce an exception on an empty * iterable. * * @since 14.0 */ public static <E extends Enum<E>> EnumMultiset<E> create(Iterable<E> elements, Class<E> type) { EnumMultiset<E> result = create(type); Iterables.addAll(result, elements); return result; }
/** * Returns an {@link Optional} containing the first element in this fluent iterable that satisfies * the given predicate, if such an element exists. * * <p><b>Warning:</b> avoid using a {@code predicate} that matches {@code null}. If {@code null} * is matched in this fluent iterable, a {@link NullPointerException} will be thrown. * * <p><b>{@code Stream} equivalent:</b> {@code stream.filter(predicate).findFirst()}. */ public final Optional<E> firstMatch(Predicate<? super E> predicate) { return Iterables.tryFind(getDelegate(), predicate); }
@Override public Iterable<? extends Field> removeUnreadFields() { final List<Field> removedFields = Lists.newArrayList(); Iterables.removeIf(fields, new Predicate<Field>() { @Override public boolean apply(Field field) { if (!field.isRead()) { removedFields.add(field); return true; } else if (field.hasSchema()) { Iterables.addAll(removedFields, field.getAssignedSchema().removeUnreadFields()); } return false; } }); return removedFields; } }
@Override public UnmodifiableIterator<E> iterator() { Iterable<E> incidentEdges = (selfLoopCount == 0) ? Iterables.concat(inEdgeMap.keySet(), outEdgeMap.keySet()) : Sets.union(inEdgeMap.keySet(), outEdgeMap.keySet()); return Iterators.unmodifiableIterator(incidentEdges.iterator()); }