/** * Returns a predicate that evaluates to {@code true} if either of its components evaluates to * {@code true}. The components are evaluated in order, and evaluation will be "short-circuited" * as soon as a true predicate is found. */ public static <T> Predicate<T> or(Predicate<? super T> first, Predicate<? super T> second) { return new OrPredicate<T>(Predicates.<T>asList(checkNotNull(first), checkNotNull(second))); }
/** * Returns a predicate that evaluates to {@code true} if both of its components evaluate to {@code * true}. The components are evaluated in order, and evaluation will be "short-circuited" as soon * as a false predicate is found. */ public static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T> second) { return new AndPredicate<T>(Predicates.<T>asList(checkNotNull(first), checkNotNull(second))); }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("stream", stream) .add("reason", reason) .toString(); } }
@Override public String toString() { return MoreObjects.toStringHelper(this).addValue(callback).toString(); } }
@Override public <V> Optional<V> transform(Function<? super T, V> function) { return new Present<V>( checkNotNull( function.apply(reference), "the Function passed to Optional.transform() must not return null.")); }
@Override public V load(Object key) { checkNotNull(key); return computingSupplier.get(); }
/** * Returns a splitter that uses the given single-character separator. For example, {@code * Splitter.on(',').split("foo,,bar")} returns an iterable containing {@code ["foo", "", "bar"]}. * * @param separator the character to recognize as a separator * @return a splitter, with default settings, that recognizes that separator */ public static Splitter on(char separator) { return on(CharMatcher.is(separator)); }
@SuppressWarnings("deprecation") // intentional; deprecation is for callers primarily @Override public boolean apply(Character character) { return predicate.apply(checkNotNull(character)); }
@Override public final boolean hasNext() { checkState(state != State.FAILED); switch (state) { case READY: return true; case DONE: return false; default: } return tryToComputeNext(); }
/** * Returns a new supplier which is the composition of the provided function and supplier. In other * words, the new supplier's value will be computed by retrieving the value from {@code supplier}, * and then applying {@code function} to that value. Note that the resulting supplier will not * call {@code supplier} or invoke {@code function} until it is called. */ public static <F, T> Supplier<T> compose(Function<? super F, T> function, Supplier<F> supplier) { Preconditions.checkNotNull(function); Preconditions.checkNotNull(supplier); return new SupplierComposition<>(function, supplier); }
@Override public <V> Optional<V> transform(Function<? super T, V> function) { checkNotNull(function); return Optional.absent(); }
/** * Returns a supplier whose {@code get()} method synchronizes on {@code delegate} before calling * it, making it thread-safe. */ public static <T> Supplier<T> synchronizedSupplier(Supplier<T> delegate) { return new ThreadSafeSupplier<T>(Preconditions.checkNotNull(delegate)); }
/** * Returns a splitter that behaves equivalently to {@code this} splitter, but automatically * removes leading and trailing {@linkplain CharMatcher#whitespace whitespace} from each returned * substring; equivalent to {@code trimResults(CharMatcher.whitespace())}. For example, {@code * Splitter.on(',').trimResults().split(" a, b ,c ")} returns an iterable containing {@code ["a", * "b", "c"]}. * * @return a splitter with the desired configuration */ public Splitter trimResults() { return trimResults(CharMatcher.whitespace()); }
/** * Converts the specified {@code String str} from this format to the specified {@code format}. A * "best effort" approach is taken; if {@code str} does not conform to the assumed format, then * the behavior of this method is undefined but we make a reasonable effort at converting anyway. */ public final String to(CaseFormat format, String str) { checkNotNull(format); checkNotNull(str); return (format == this) ? str : convert(format, str); }
/** * Returns a predicate that evaluates to {@code true} if each of its components evaluates to * {@code true}. The components are evaluated in order, and evaluation will be "short-circuited" * as soon as a false predicate is found. It defensively copies the iterable passed in, so future * changes to it won't alter the behavior of this predicate. If {@code components} is empty, the * returned predicate will always evaluate to {@code true}. */ public static <T> Predicate<T> and(Iterable<? extends Predicate<? super T>> components) { return new AndPredicate<T>(defensiveCopy(components)); }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("traceId", traceId) .add("spanId", spanId) .add("traceOptions", traceOptions) .toString(); }
@Override public String toString() { ToStringHelper helper = MoreObjects.toStringHelper(this).add("type", type); if (comparator != null) { helper.add("comparator", comparator); } return helper.toString(); }
@Override public String toString() { return MoreObjects.toStringHelper(this).add("source", source).add("event", event).toString(); } }