diff options
Diffstat (limited to 'guava/src/com/google/common/base/Predicates.java')
-rw-r--r-- | guava/src/com/google/common/base/Predicates.java | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/guava/src/com/google/common/base/Predicates.java b/guava/src/com/google/common/base/Predicates.java index aa12750..5c77a28 100644 --- a/guava/src/com/google/common/base/Predicates.java +++ b/guava/src/com/google/common/base/Predicates.java @@ -37,10 +37,6 @@ import javax.annotation.Nullable; * <p>All methods returns serializable predicates as long as they're given * serializable parameters. * - * <p>See the Guava User Guide article on <a href= - * "http://code.google.com/p/guava-libraries/wiki/FunctionalExplained">the - * use of {@code Predicate}</a>. - * * @author Kevin Bourrillion * @since 2.0 (imported from Google Collections Library) */ @@ -200,12 +196,12 @@ public final class Predicates { public static Predicate<Object> instanceOf(Class<?> clazz) { return new InstanceOfPredicate(clazz); } - + /** * Returns a predicate that evaluates to {@code true} if the class being * tested is assignable from the given class. The returned predicate * does not allow null inputs. - * + * * @since 10.0 */ @GwtIncompatible("Class.isAssignableFrom") @@ -293,7 +289,7 @@ public final class Predicates { return o != null; } }; - + @SuppressWarnings("unchecked") // these Object predicates work for any T <T> Predicate<T> withNarrowedType() { return (Predicate<T>) this; @@ -308,7 +304,7 @@ public final class Predicates { this.predicate = checkNotNull(predicate); } @Override - public boolean apply(@Nullable T t) { + public boolean apply(T t) { return !predicate.apply(t); } @Override public int hashCode() { @@ -337,8 +333,7 @@ public final class Predicates { this.components = components; } @Override - public boolean apply(@Nullable T t) { - // Avoid using the Iterator to avoid generating garbage (issue 820). + public boolean apply(T t) { for (int i = 0; i < components.size(); i++) { if (!components.get(i).apply(t)) { return false; @@ -347,7 +342,7 @@ public final class Predicates { return true; } @Override public int hashCode() { - // add a random number to avoid collisions with OrPredicate + // 0x12472c2c is a random number to help avoid collisions with OrPredicate return components.hashCode() + 0x12472c2c; } @Override public boolean equals(@Nullable Object obj) { @@ -371,8 +366,7 @@ public final class Predicates { this.components = components; } @Override - public boolean apply(@Nullable T t) { - // Avoid using the Iterator to avoid generating garbage (issue 820). + public boolean apply(T t) { for (int i = 0; i < components.size(); i++) { if (components.get(i).apply(t)) { return true; @@ -381,7 +375,7 @@ public final class Predicates { return false; } @Override public int hashCode() { - // add a random number to avoid collisions with AndPredicate + // 0x053c91cf is a random number to help avoid collisions with AndPredicate return components.hashCode() + 0x053c91cf; } @Override public boolean equals(@Nullable Object obj) { @@ -453,7 +447,7 @@ public final class Predicates { } private static final long serialVersionUID = 0; } - + /** @see Predicates#assignableFrom(Class) */ @GwtIncompatible("Class.isAssignableFrom") private static class AssignableFromPredicate @@ -492,7 +486,7 @@ public final class Predicates { } @Override - public boolean apply(@Nullable T t) { + public boolean apply(T t) { try { return target.contains(t); } catch (NullPointerException e) { @@ -532,7 +526,7 @@ public final class Predicates { } @Override - public boolean apply(@Nullable A a) { + public boolean apply(A a) { return p.apply(f.apply(a)); } |