/** * Returns a {@code char} matcher functionally equivalent to this one, but which may be faster to * query than the original; your mileage may vary. Precomputation takes time and is likely to be * worthwhile only if the precomputed matcher is queried many thousands of times. * * <p>This method has no effect (returns {@code this}) when called in GWT: it's unclear whether a * precomputed matcher is faster, but it certainly consumes more memory, which doesn't seem like a * worthwhile tradeoff in a browser. */ public CharMatcher precomputed() { return Platform.precomputeCharMatcher(this); }
@Override public long read() { return Platform.systemNanoTime(); } };
/** * Returns an optional enum constant for the given type, using {@link Enum#valueOf}. If the * constant does not exist, {@link Optional#absent} is returned. A common use case is for parsing * user input or falling back to a default enum constant. For example, {@code * Enums.getIfPresent(Country.class, countryInput).or(Country.DEFAULT);} * * @since 12.0 */ public static <T extends Enum<T>> Optional<T> getIfPresent(Class<T> enumClass, String value) { checkNotNull(enumClass); checkNotNull(value); return Platform.getEnumIfPresent(enumClass, value); }
ContainsPatternFromStringPredicate(String string) { super(Platform.compilePattern(string)); }
/** * Returns {@code true} if the given string is null or is the empty string. * * <p>Consider normalizing your string references with {@link #nullToEmpty}. If you do, you can * use {@link String#isEmpty()} instead of this method, and you won't need special null-safe forms * of methods like {@link String#toUpperCase} either. Or, if you'd like to normalize "in the other * direction," converting empty strings to {@code null}, you can use {@link #emptyToNull}. * * @param string a string reference to check * @return {@code true} if the string is null or is the empty string */ public static boolean isNullOrEmpty(@Nullable String string) { return Platform.stringIsNullOrEmpty(string); }
/** * Returns the given string if it is nonempty; {@code null} otherwise. * * @param string the string to test and possibly return * @return {@code string} itself if it is nonempty; {@code null} if it is empty or null */ public static @Nullable String emptyToNull(@Nullable String string) { return Platform.emptyToNull(string); }
/** * Returns the given string if it is non-null; the empty string otherwise. * * @param string the string to test and possibly return * @return {@code string} itself if it is non-null; {@code ""} if it is null */ public static String nullToEmpty(@Nullable String string) { return Platform.nullToEmpty(string); }
/** Returns a string representation of the current elapsed time. */ @Override public String toString() { long nanos = elapsedNanos(); TimeUnit unit = chooseUnit(nanos); double value = (double) nanos / NANOSECONDS.convert(1, unit); // Too bad this functionality is not exposed as a regular method call return Platform.formatCompact4Digits(value) + " " + abbreviate(unit); }
public static CommonPattern compile(String pattern) { return Platform.compilePattern(pattern); }
static String emptyToNull(@Nullable String string) { return stringIsNullOrEmpty(string) ? null : string; }
/** * Returns the given string if it is nonempty; {@code null} otherwise. * * @param string the string to test and possibly return * @return {@code string} itself if it is nonempty; {@code null} if it is empty or null */ @NullableDecl public static String emptyToNull(@NullableDecl String string) { return Platform.emptyToNull(string); }
/** * Returns the given string if it is non-null; the empty string otherwise. * * @param string the string to test and possibly return * @return {@code string} itself if it is non-null; {@code ""} if it is null */ public static String nullToEmpty(@NullableDecl String string) { return Platform.nullToEmpty(string); }
/** Returns a string representation of the current elapsed time. */ @Override public String toString() { long nanos = elapsedNanos(); TimeUnit unit = chooseUnit(nanos); double value = (double) nanos / NANOSECONDS.convert(1, unit); // Too bad this functionality is not exposed as a regular method call return Platform.formatCompact4Digits(value) + " " + abbreviate(unit); }
@Override public long read() { return Platform.systemNanoTime(); } };
/** * Returns a {@code char} matcher functionally equivalent to this one, but which may be faster to * query than the original; your mileage may vary. Precomputation takes time and is likely to be * worthwhile only if the precomputed matcher is queried many thousands of times. * * <p>This method has no effect (returns {@code this}) when called in GWT: it's unclear whether a * precomputed matcher is faster, but it certainly consumes more memory, which doesn't seem like a * worthwhile tradeoff in a browser. */ public CharMatcher precomputed() { return Platform.precomputeCharMatcher(this); }
/** * Returns an optional enum constant for the given type, using {@link Enum#valueOf}. If the * constant does not exist, {@link Optional#absent} is returned. A common use case is for parsing * user input or falling back to a default enum constant. For example, {@code * Enums.getIfPresent(Country.class, countryInput).or(Country.DEFAULT);} * * @since 12.0 */ public static <T extends Enum<T>> Optional<T> getIfPresent(Class<T> enumClass, String value) { checkNotNull(enumClass); checkNotNull(value); return Platform.getEnumIfPresent(enumClass, value); }
ContainsPatternFromStringPredicate(String string) { super(Platform.compilePattern(string)); }
/** * Returns {@code true} if the given string is null or is the empty string. * * <p>Consider normalizing your string references with {@link #nullToEmpty}. If you do, you can * use {@link String#isEmpty()} instead of this method, and you won't need special null-safe forms * of methods like {@link String#toUpperCase} either. Or, if you'd like to normalize "in the other * direction," converting empty strings to {@code null}, you can use {@link #emptyToNull}. * * @param string a string reference to check * @return {@code true} if the string is null or is the empty string */ public static boolean isNullOrEmpty(@NullableDecl String string) { return Platform.stringIsNullOrEmpty(string); }
/** * Returns the given string if it is nonempty; {@code null} otherwise. * * @param string the string to test and possibly return * @return {@code string} itself if it is nonempty; {@code null} if it is empty or null */ @NullableDecl public static String emptyToNull(@NullableDecl String string) { return Platform.emptyToNull(string); }
/** * Returns the given string if it is non-null; the empty string otherwise. * * @param string the string to test and possibly return * @return {@code string} itself if it is non-null; {@code ""} if it is null */ public static String nullToEmpty(@NullableDecl String string) { return Platform.nullToEmpty(string); }