@SuppressWarnings("unchecked") public static Predicate<View> isClass(final Class<? extends View> clazz) { return (Predicate<View>) (Predicate<?>) Predicates.instanceOf(clazz); }
@Override public String toString() { return MoreObjects.toStringHelper(ServiceManager.class) .add("services", Collections2.filter(services, not(instanceOf(NoOpService.class)))) .toString(); }
/** * Returns a view of {@code unfiltered} containing all elements that are of the type {@code * desiredType}. */ @SuppressWarnings("unchecked") // can cast to <T> because non-Ts are removed @GwtIncompatible // Class.isInstance public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) { return (UnmodifiableIterator<T>) filter(unfiltered, instanceOf(desiredType)); }
private boolean hasUnresolvedValue(List<Object> values) { return values.stream().anyMatch(instanceOf(Expression.class)::apply); }
@Override public String toString() { return MoreObjects.toStringHelper(ServiceManager.class) .add("services", Collections2.filter(services, not(instanceOf(NoOpService.class)))) .toString(); }
/** * Returns a view of {@code unfiltered} containing all elements that are of the type {@code * desiredType}. The returned iterable's iterator does not support {@code remove()}. * * <p><b>{@code Stream} equivalent:</b> {@code stream.filter(type::isInstance).map(type::cast)}. * This does perform a little more work than necessary, so another option is to insert an * unchecked cast at some later point: * * <pre> * {@code @SuppressWarnings("unchecked") // safe because of ::isInstance check * ImmutableList<NewType> result = * (ImmutableList) stream.filter(NewType.class::isInstance).collect(toImmutableList());} * </pre> */ @SuppressWarnings("unchecked") @GwtIncompatible // Class.isInstance public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType) { checkNotNull(unfiltered); checkNotNull(desiredType); return (Iterable<T>) filter(unfiltered, Predicates.instanceOf(desiredType)); }
/** * Returns a view of {@code unfiltered} containing all elements that are of the type {@code * desiredType}. */ @SuppressWarnings("unchecked") // can cast to <T> because non-Ts are removed @GwtIncompatible // Class.isInstance public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) { return (UnmodifiableIterator<T>) filter(unfiltered, instanceOf(desiredType)); }
@Override public String toString() { return MoreObjects.toStringHelper(ServiceManager.class) .add("services", Collections2.filter(services, not(instanceOf(NoOpService.class)))) .toString(); }
/** * Returns a view of {@code unfiltered} containing all elements that are of the type {@code * desiredType}. */ @SuppressWarnings("unchecked") // can cast to <T> because non-Ts are removed @GwtIncompatible // Class.isInstance public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) { return (UnmodifiableIterator<T>) filter(unfiltered, instanceOf(desiredType)); }
private static final class UnmodifiableIterable<T> extends FluentIterable<T> { private final Iterable<? extends T> iterable; private UnmodifiableIterable(Iterable<? extends T> iterable) { this.iterable = iterable; } @Override public Iterator<T> iterator() { return Iterators.unmodifiableIterator(iterable.iterator()); } @Override public String toString() { return iterable.toString(); } // no equals and hashCode; it would break the contract! }
private static <T> void assertTaskWrapped(Collection<? extends Callable<T>> tasks) { Predicate<Object> p = Predicates.instanceOf(WrappedCallable.class); assertTrue(Iterables.all(tasks, p)); } }
@GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_equality() { new EqualsTester() .addEqualityGroup( Predicates.instanceOf(Integer.class), Predicates.instanceOf(Integer.class)) .addEqualityGroup(Predicates.instanceOf(Number.class)) .addEqualityGroup(Predicates.instanceOf(Float.class)) .testEquals(); }
@GwtIncompatible // Predicates.instanceOf, SerializableTester public void testIsInstanceOf_serialization() { checkSerialization(Predicates.instanceOf(Integer.class)); }
@GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_subclass() { Predicate<Object> isNumber = Predicates.instanceOf(Number.class); assertTrue(isNumber.apply(1)); assertTrue(isNumber.apply(2.0f)); assertFalse(isNumber.apply("")); assertFalse(isNumber.apply(null)); }
@GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_interface() { Predicate<Object> isComparable = Predicates.instanceOf(Comparable.class); assertTrue(isComparable.apply(1)); assertTrue(isComparable.apply(2.0f)); assertTrue(isComparable.apply("")); assertFalse(isComparable.apply(null)); }
/** * Tests for Predicates.instanceOf(x). TODO: Fix the comment style after fixing annotation * stripper to remove comments properly. Currently, all tests before the comments are removed as * well. */ @GwtIncompatible // Predicates.instanceOf public void testIsInstanceOf_apply() { Predicate<Object> isInteger = Predicates.instanceOf(Integer.class); assertTrue(isInteger.apply(1)); assertFalse(isInteger.apply(2.0f)); assertFalse(isInteger.apply("")); assertFalse(isInteger.apply(null)); }
@Override public Ordering<Element> enclosedBy(Element element) { if (element instanceof ElementImpl && Iterables.all(element.getEnclosedElements(), Predicates.instanceOf(ElementImpl.class))) { ElementImpl implementation = (ElementImpl) element; if (implementation._binding instanceof SourceTypeBinding) { SourceTypeBinding sourceBinding = (SourceTypeBinding) implementation._binding; return Ordering.natural().onResultOf( Functions.compose(bindingsToSourceOrder(sourceBinding), this)); } } return DEFAULT_PROVIDER.enclosedBy(element); }
@Override @Nullable public Choice<Unifier> visitNewArray(NewArrayTree newArray, @Nullable Unifier unifier) { boolean hasRepeated = getInitializers() != null && Iterables.any(getInitializers(), Predicates.instanceOf(URepeated.class)); return unifyNullable(unifier, getType(), newArray.getType()) .thenChoose(unifications(getDimensions(), newArray.getDimensions())) .thenChoose(unifications(getInitializers(), newArray.getInitializers(), hasRepeated)); }
public <V extends View> ViewTreeAssert doesNotHaveVisible( final Class<V> clazz, final Predicate<Object> predicate) { final Predicate<View> conjunction = Predicates.and(Predicates.instanceOf(clazz), ViewPredicates.isVisible(), predicate); final ImmutableList<View> path = actual.findChild( conjunction, ViewPredicates.isVisible()); Java6Assertions.assertThat(path) .overridingErrorMessage( "Found a view for which given predicate is true in view hierarchy:%n%s", actual.makeString(null)) .isNull(); return this; }
public <V extends View> ViewTreeAssert hasVisible(final Class<V> clazz, final Predicate<V> predicate) { final Predicate<View> conjunction = Predicates.and( Predicates.instanceOf(clazz), ViewPredicates.isVisible(), (Predicate<View>) predicate); final ImmutableList<View> path = actual.findChild( conjunction, ViewPredicates.isVisible()); Java6Assertions.assertThat(path) .overridingErrorMessage( "Did not find view for which given predicate is true in view hierarchy:%n%s", actual.makeString(null)) .isNotNull(); return this; }