private synchronized void updateEndpoints() { try { Collection<DrillbitEndpoint> newDrillbitSet = transform( discovery.queryForInstances(serviceName), new Function<ServiceInstance<DrillbitEndpoint>, DrillbitEndpoint>() {
@Override Iterable<OptionValue> getLocalOptions() { final Collection<OptionValue> liveOptions = Collections2.filter(options.values(), isLive); return liveOptions; }
/** * Creates an {@code ArrayDeque} containing the elements of the specified iterable, * in the order they are returned by the iterable's iterator. * * @since 12.0 */ public static <E> ArrayDeque<E> newArrayDeque(Iterable<? extends E> elements) { if (elements instanceof Collection) { return new ArrayDeque<E>(Collections2.cast(elements)); } ArrayDeque<E> deque = new ArrayDeque<E>(); Iterables.addAll(deque, elements); return deque; }
@Override public boolean contains(@Nullable Object object) { return object != null && Collections2.safeContains(delegate, object); }
/** * A sensible definition of {@link #containsAll} in terms of {@link #contains} * . If you override {@link #contains}, you may wish to override {@link * #containsAll} to forward to this implementation. * * @since 7.0 */ protected boolean standardContainsAll(Collection<?> collection) { return Collections2.containsAllImpl(this, collection); }
/** * An implementation of {@link Map#toString}. */ static String toStringImpl(Map<?, ?> map) { StringBuilder sb = Collections2.newStringBuilderForCollection(map.size()).append('{'); boolean first = true; for (Map.Entry<?, ?> entry : map.entrySet()) { if (!first) { sb.append(", "); } first = false; sb.append(entry.getKey()).append('=').append(entry.getValue()); } return sb.append('}').toString(); }
/** * A sensible definition of {@link #toString} in terms of {@link #iterator}. * If you override {@link #iterator}, you may wish to override {@link * #toString} to forward to this implementation. * * @since 7.0 */ protected String standardToString() { return Collections2.toStringImpl(this); }
@Override public boolean remove(Object object) { return object != null && Collections2.safeRemove(delegate, object); }
public static <E extends Comparable<? super E>> Collection<List<E>> orderedPermutations( Iterable<E> elements) { return orderedPermutations(elements, Ordering.natural());
static <E> Collection<E> filterCollection( Collection<E> collection, Predicate<? super E> predicate) { if (collection instanceof Set) { return Sets.filter((Set<E>) collection, predicate); } else { return Collections2.filter(collection, predicate); } }
/** * Creates a {@code PriorityQueue} containing the given elements. * * <b>Note:</b> If the specified iterable is a {@code SortedSet} or a {@code PriorityQueue}, * this priority queue will be ordered according to the same ordering. * * @since 11.0 (requires that {@code E} be {@code Comparable} since 15.0). */ public static <E extends Comparable> PriorityQueue<E> newPriorityQueue( Iterable<? extends E> elements) { if (elements instanceof Collection) { return new PriorityQueue<E>(Collections2.cast(elements)); } PriorityQueue<E> queue = new PriorityQueue<E>(); Iterables.addAll(queue, elements); return queue; }
@Override @Nullable public V getOrDefault(@Nullable Object key, @Nullable V defaultValue) { if (Collections2.safeContains(set, key)) { @SuppressWarnings("unchecked") // unsafe, but Javadoc warns about it K k = (K) key; return function.apply(k); } else { return defaultValue; } }
@Override public boolean containsAll(Collection<?> targets) { return Collections2.containsAllImpl(this, targets); }
/** * An implementation of {@link Collection#toString()}. */ static String toStringImpl(final Collection<?> collection) { StringBuilder sb = newStringBuilderForCollection(collection.size()).append('['); boolean first = true; for (Object o : collection) { if (!first) { sb.append(", "); } first = false; if (o == collection) { sb.append("(this Collection)"); } else { sb.append(o); } } return sb.append(']').toString(); }
@Override Collection<V> createValues() { return Collections2.transform(set, function); }
@Override public String toString() { return MoreObjects.toStringHelper(ServiceManager.class) .add("services", Collections2.filter(services, not(instanceOf(NoOpService.class)))) .toString(); }
/** * Creates a <i>mutable</i> {@code HashSet} instance containing the given elements. A very thin * convenience for creating an empty set then calling {@link Collection#addAll} or {@link * Iterables#addAll}. * * <p><b>Note:</b> if mutability is not required and the elements are non-null, use {@link * ImmutableSet#copyOf(Iterable)} instead. (Or, change {@code elements} to be a {@link * FluentIterable} and call {@code elements.toSet()}.) * * <p><b>Note:</b> if {@code E} is an {@link Enum} type, use {@link #newEnumSet(Iterable, Class)} * instead. * * <p><b>Note for Java 7 and later:</b> if {@code elements} is a {@link Collection}, you don't * need this method. Instead, use the {@code HashSet} constructor directly, taking advantage of * the new <a href="http://goo.gl/iz2Wi">"diamond" syntax</a>. * * <p>Overall, this method is not very useful and will likely be deprecated in the future. */ public static <E> HashSet<E> newHashSet(Iterable<? extends E> elements) { return (elements instanceof Collection) ? new HashSet<E>(Collections2.cast(elements)) : newHashSet(elements.iterator()); }
@Override public boolean contains(@Nullable Object element) { if (safeContains(unfiltered, element)) { @SuppressWarnings("unchecked") // element is in unfiltered, so it must be an E E e = (E) element; return predicate.apply(e); } return false; }
@Override public boolean containsAll(Collection<?> collection) { return containsAllImpl(this, collection); }
@Override Collection<V2> createValues() { return Collections2.transform(fromTable.values(), function); }