/** * Add an exception. If this is the first exception added, it will be the one * that is thrown when this is closed. If not the first exception, then it will * be added to the suppressed exceptions on the first exception. * * @param exception the exception to add */ public void addException(final Exception exception) { Preconditions.checkNotNull(exception); synchronized(this) { Preconditions.checkState(!isClosed); if (this.exception == null) { if (exceptionSupplier == null) { this.exception = exception; } else { this.exception = exceptionSupplier.get(); if (this.exception == null) { this.exception = new RuntimeException("Missing root exception"); } this.exception.addSuppressed(exception); } } else { this.exception.addSuppressed(exception); } } }
@Override protected List<V> createCollection() { return factory.get(); }
@Override public Object apply(Supplier<Object> input) { return input.get(); }
@Override protected SortedSet<V> createCollection() { return factory.get(); }
@Override public T get() { synchronized (delegate) { return delegate.get(); } }
@Override protected Collection<V> createCollection() { return factory.get(); }
@Override protected Set<V> createCollection() { return factory.get(); }
public static LongAddable create() { return SUPPLIER.get(); }
@Override public T get() { // A 2-field variant of Double Checked Locking. if (!initialized) { synchronized (this) { if (!initialized) { T t = delegate.get(); value = t; initialized = true; return t; } } } return value; }
public static LongAddable create() { return SUPPLIER.get(); }
@Override public T get() { // A 2-field variant of Double Checked Locking. if (!initialized) { synchronized (this) { if (!initialized) { T t = delegate.get(); value = t; initialized = true; // Release the delegate to GC. delegate = null; return t; } } } return value; }
@Override public T apply(@Nullable Object input) { return supplier.get(); }
private Map<C, V> getOrCreate(R rowKey) { Map<C, V> map = backingMap.get(rowKey); if (map == null) { map = factory.get(); backingMap.put(rowKey, map); } return map; }
@Override public T call() throws Exception { Thread currentThread = Thread.currentThread(); String oldName = currentThread.getName(); boolean restoreName = trySetName(nameSupplier.get(), currentThread); try { return callable.call(); } finally { if (restoreName) { boolean unused = trySetName(oldName, currentThread); } } } };
@Override public void run() { Thread currentThread = Thread.currentThread(); String oldName = currentThread.getName(); boolean restoreName = trySetName(nameSupplier.get(), currentThread); try { task.run(); } finally { if (restoreName) { boolean unused = trySetName(oldName, currentThread); } } } };
@Override public void execute(Runnable command) { MoreExecutors.newThread(threadNameSupplier.get(), command).start(); } };
@Override public V load(Object key) { checkNotNull(key); return computingSupplier.get(); }
CustomSortedSetMultimap(Map<K, Collection<V>> map, Supplier<? extends SortedSet<V>> factory) { super(map); this.factory = checkNotNull(factory); valueComparator = factory.get().comparator(); }
@Override public Hasher newHasher() { return new ChecksumHasher(checksumSupplier.get()); }
private CompactStriped(int stripes, Supplier<L> supplier) { super(stripes); Preconditions.checkArgument(stripes <= Ints.MAX_POWER_OF_TWO, "Stripes must be <= 2^30)"); this.array = new Object[mask + 1]; for (int i = 0; i < array.length; i++) { array[i] = supplier.get(); } }