@see Predicates#or(Iterable)
| 453 | /** @see Predicates#or(Iterable) */ |
| 454 | |
| 455 | private static class OrPredicate<T> implements Predicate<T>, Serializable { |
| 456 | |
| 457 | private final List<? extends Predicate<? super T>> components; |
| 458 | private OrPredicate(List<? extends Predicate<? super T>> components) { |
| 459 | this.components = components; |
| 460 | } |
| 461 | |
| 462 | @Override |
| 463 | public boolean apply(@Nullable T t) { |
| 464 | // Avoid using the Iterator to avoid generating garbage (issue 820). |
| 465 | for (int i = 0; i < components.size(); i++) { |
| 466 | if (components.get(i).apply(t)) { |
| 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | return false; |
| 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public int hashCode() { |
| 475 | // add a random number to avoid collisions with AndPredicate |
| 476 | return components.hashCode() + 0x053c91cf; |
| 477 | } |
| 478 | |
| 479 | @Override |
| 480 | public boolean equals(@Nullable Object obj) { |
| 481 | if (obj instanceof OrPredicate) { |
| 482 | OrPredicate<?> that = (OrPredicate<?>) obj; |
| 483 | return components.equals(that.components); |
| 484 | } |
| 485 | return false; |
| 486 | } |
| 487 | |
| 488 | @Override |
| 489 | public String toString() { |
| 490 | return "Predicates.or(" + COMMA_JOINER.join(components) + ")"; |
| 491 | } |
| 492 | |
| 493 | private static final long serialVersionUID = 0; |
| 494 | } |
| 495 | |
| 496 | /** @see Predicates#equalTo(Object) */ |
| 497 |
nothing calls this directly
no outgoing calls
no test coverage detected