/** * Returns whether {@link #lazyStackTrace} will use the special implementation described in its * documentation. * * @since 19.0 */ @Beta @GwtIncompatible // getStackTraceElementMethod public static boolean lazyStackTraceIsLazy() { return getStackTraceElementMethod != null && getStackTraceDepthMethod != null; }
/** * Returns a {@code ByteSink} that writes base-encoded bytes to the specified {@code CharSink}. */ @GwtIncompatible // ByteSink,CharSink public final ByteSink encodingSink(final CharSink encodedSink) { checkNotNull(encodedSink); return new ByteSink() { @Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } }; }
/** * Creates an {@link AsyncCallable} from a {@link Callable}. * * <p>The {@link AsyncCallable} returns the {@link ListenableFuture} resulting from {@link * ListeningExecutorService#submit(Callable)}. * * @since 20.0 */ @Beta @GwtIncompatible public static <T> AsyncCallable<T> asAsyncCallable( final Callable<T> callable, final ListeningExecutorService listeningExecutorService) { checkNotNull(callable); checkNotNull(listeningExecutorService); return new AsyncCallable<T>() { @Override public ListenableFuture<T> call() throws Exception { return listeningExecutorService.submit(callable); } }; }
@GwtCompatible(emulated = true) public final class Charsets { private Charsets() {} @GwtIncompatible // Charset not supported by GWT public static final Charset US_ASCII = Charset.forName("US-ASCII"); @GwtIncompatible // Charset not supported by GWT public static final Charset UTF_16BE = Charset.forName("UTF-16BE"); @GwtIncompatible // Charset not supported by GWT public static final Charset UTF_16LE = Charset.forName("UTF-16LE"); @GwtIncompatible // Charset not supported by GWT public static final Charset UTF_16 = Charset.forName("UTF-16");
/** * Returns a {@code ByteSource} that reads base-encoded bytes from the specified {@code * CharSource}. */ @GwtIncompatible // ByteSource,CharSource public final ByteSource decodingSource(final CharSource encodedSource) { checkNotNull(encodedSource); return new ByteSource() { @Override public InputStream openStream() throws IOException { return decodingStream(encodedSource.openStream()); } }; }
/** * Creates an {@link AsyncCallable} from a {@link Callable}. * * <p>The {@link AsyncCallable} returns the {@link ListenableFuture} resulting from {@link * ListeningExecutorService#submit(Callable)}. * * @since 20.0 */ @Beta @GwtIncompatible public static <T> AsyncCallable<T> asAsyncCallable( final Callable<T> callable, final ListeningExecutorService listeningExecutorService) { checkNotNull(callable); checkNotNull(listeningExecutorService); return new AsyncCallable<T>() { @Override public ListenableFuture<T> call() throws Exception { return listeningExecutorService.submit(callable); } }; }
/** * A callback to be used with the streaming {@code readLines} methods. * * <p>{@link #processLine} will be called for each line that is read, and should return {@code * false} when you want to stop processing. * * @author Miles Barr * @since 1.0 */ @Beta @GwtIncompatible public interface LineProcessor<T> { /** * This method will be called once for each line. * * @param line the line read from the input, without delimiter * @return true to continue processing, false to stop */ @CanIgnoreReturnValue // some uses know that their processor never returns false boolean processLine(String line) throws IOException; /** Return the result of processing all the lines. */ T getResult(); }
abstract class Itr<T> implements Iterator<T> { int index = 0; int toRemove = -1; abstract T output(int index); @Override public boolean hasNext() { for (; index < enumConstants.length; index++) { if (counts[index] > 0) { return true; } } return false; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } T result = output(index); toRemove = index; index++; return result; } @Override public void remove() { checkRemove(toRemove >= 0);
/** * Sets a custom {@code Equivalence} strategy for comparing keys. * * <p>By default, the cache uses {@link Equivalence#identity} to determine key equality when * {@link #weakKeys} is specified, and {@link Equivalence#equals()} otherwise. * * @return this {@code CacheBuilder} instance (for chaining) */ @GwtIncompatible // To be supported CacheBuilder<K, V> keyEquivalence(Equivalence<Object> equivalence) { checkState(keyEquivalence == null, "key equivalence was already set to %s", keyEquivalence); keyEquivalence = checkNotNull(equivalence); return this; }
@Beta @CanIgnoreReturnValue @GwtIncompatible // BlockingQueue @SuppressWarnings("GoodTime") // should accept a java.time.Duration public static <E> int drain( TimeUnit unit) throws InterruptedException { Preconditions.checkNotNull(buffer);
/** * Provides equivalent behavior to {@link String#intern} for other immutable types. Common * implementations are available from the {@link Interners} class. * * @author Kevin Bourrillion * @since 3.0 */ @Beta @GwtIncompatible public interface Interner<E> { /** * Chooses and returns the representative instance for any of a collection of instances that are * equal to each other. If two {@linkplain Object#equals equal} inputs are given to this method, * both calls will return the same instance. That is, {@code intern(a).equals(a)} always holds, * and {@code intern(a) == intern(b)} if and only if {@code a.equals(b)}. Note that {@code * intern(a)} is permitted to return one instance now and a different instance later if the * original interned instance was garbage-collected. * * <p><b>Warning:</b> do not use with mutable objects. * * @throws NullPointerException if {@code sample} is null */ @CanIgnoreReturnValue // TODO(cpovirk): Consider removing this? E intern(E sample); }
@GwtCompatible(serializable = true, emulated = true) public final class HashMultiset<E> extends AbstractMapBasedMultiset<E> { @GwtIncompatible // Not needed in emulated source. private static final long serialVersionUID = 0;
/** * Sets a custom {@code Equivalence} strategy for comparing values. * * <p>By default, the cache uses {@link Equivalence#identity} to determine value equality when * {@link #weakValues} or {@link #softValues} is specified, and {@link Equivalence#equals()} * otherwise. * * @return this {@code CacheBuilder} instance (for chaining) */ @GwtIncompatible // To be supported CacheBuilder<K, V> valueEquivalence(Equivalence<Object> equivalence) { checkState( valueEquivalence == null, "value equivalence was already set to %s", valueEquivalence); this.valueEquivalence = checkNotNull(equivalence); return this; }
@Beta @CanIgnoreReturnValue @GwtIncompatible // BlockingQueue @SuppressWarnings("GoodTime") // should accept a java.time.Duration public static <E> int drainUninterruptibly( long timeout, TimeUnit unit) { Preconditions.checkNotNull(buffer); long deadline = System.nanoTime() + unit.toNanos(timeout); int added = 0;
/** * A callback interface to process bytes from a stream. * * <p>{@link #processBytes} will be called for each chunk of data that is read, and should return * {@code false} when you want to stop processing. * * @author Chris Nokleberg * @since 1.0 */ @Beta @GwtIncompatible public interface ByteProcessor<T> { /** * This method will be called for each chunk of bytes in an input stream. The implementation * should process the bytes from {@code buf[off]} through {@code buf[off + len - 1]} (inclusive). * * @param buf the byte array containing the data to process * @param off the initial offset into the array * @param len the length of data to be processed * @return true to continue processing, false to stop */ @CanIgnoreReturnValue // some uses know that their processor never returns false boolean processBytes(byte[] buf, int off, int len) throws IOException; /** Return the result of processing all the bytes. */ T getResult(); }
@GwtCompatible(serializable = true, emulated = true) @SuppressWarnings("serial") // we're overriding default serialization public final class LinkedHashMultiset<E> extends AbstractMapBasedMultiset<E> { @GwtIncompatible // not needed in emulated source private static final long serialVersionUID = 0;
@GwtIncompatible // invokeAccessibleNonThrowingMethod private static List<StackTraceElement> jlaStackTrace(final Throwable t) { checkNotNull(t); /* * TODO(cpovirk): Consider optimizing iterator() to catch IOOBE instead of doing bounds checks. * * TODO(cpovirk): Consider the UnsignedBytes pattern if it performs faster and doesn't cause * AOSP grief. */ return new AbstractList<StackTraceElement>() { @Override public StackTraceElement get(int n) { return (StackTraceElement) invokeAccessibleNonThrowingMethod(getStackTraceElementMethod, jla, t, n); } @Override public int size() { return (Integer) invokeAccessibleNonThrowingMethod(getStackTraceDepthMethod, jla, t); } }; }
@Beta @GwtIncompatible // NavigableSet public static <K extends Comparable<? super K>> NavigableSet<K> subSet( NavigableSet<K> set, Range<K> range) { return set.headSet(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED); return checkNotNull(set);
@Beta @GwtIncompatible public interface ListeningScheduledExecutorService extends ScheduledExecutorService, ListeningExecutorService {
abstract class Itr<T> implements Iterator<T> { BiEntry<K, V> next = firstInKeyInsertionOrder; BiEntry<K, V> toRemove = null; int expectedModCount = modCount; int remaining = size(); @Override public boolean hasNext() { if (modCount != expectedModCount) { throw new ConcurrentModificationException(); } return next != null && remaining > 0; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } BiEntry<K, V> entry = next; next = entry.nextInKeyInsertionOrder; toRemove = entry; remaining--; return output(entry); } @Override public void remove() { if (modCount != expectedModCount) {