AbstractChainingFuture(ListenableFuture<? extends I> inputFuture, F function) { this.inputFuture = Preconditions.checkNotNull(inputFuture); this.function = Preconditions.checkNotNull(function); }
@Inject public GsonSourceParser(Gson gson, Type type) { checkNotNull(gson, "Gson can't be null"); checkNotNull(type, "Type can't be null"); this.gson = gson; this.type = type; }
@Inject public GsonStringParser(Gson gson, Type parsedClass) { checkNotNull(gson, "Gson can't be null"); checkNotNull(parsedClass, "Type can't be null"); this.gson = gson; this.type = parsedClass; }
private RemovalNotification( K key, V value, @Nonnull RemovalCause cause) { this.key = key; this.value = value; this.cause = checkNotNull(cause); }
/** * Use {@link MoreObjects#toStringHelper(Object)} to create an instance. */ private ToStringHelper(@Nonnull String className) { this.className = Preconditions.checkNotNull(className); }
@Override public void invalidate(@Nonnull Object key) { Preconditions.checkNotNull(key); localCache.remove(key); }
@Nonnull CacheBuilder<K, V> setKeyStrength(@Nonnull LocalCache.Strength strength) { Preconditions.checkState(keyStrength == null, "Key strength was already set to %s", keyStrength); keyStrength = Preconditions.checkNotNull(strength); return this; }
@Nonnull @Override public V load(@Nonnull Object key) { Preconditions.checkNotNull(key); return computingSupplier.get(); }
@Nonnull public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable) { Preconditions.checkNotNull(throwable); return new Futures.ImmediateFailedFuture<>(throwable); }
@Override public V get(long timeout, @Nonnull TimeUnit unit) throws ExecutionException { Preconditions.checkNotNull(unit); return this.get(); }
/** * 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. */ @Nonnull CacheBuilder<K, V> keyEquivalence(@Nonnull Equivalence<Object> equivalence) { Preconditions.checkState(keyEquivalence == null, "key equivalence was already set to %s", keyEquivalence); keyEquivalence = Preconditions.checkNotNull(equivalence); return this; }
@Nullable public ListenableFuture<V> reload(@Nonnull K key, @Nonnull V oldValue) throws Exception { Preconditions.checkNotNull(key); Preconditions.checkNotNull(oldValue); return Futures.immediateFuture(load(key)); }
@Nonnull private ToStringHelper addHolder(@Nonnull String name, Object value) { ValueHolder valueHolder = addHolder(); valueHolder.value = value; valueHolder.name = Preconditions.checkNotNull(name); return this; }
@Nullable @Override public V put(@Nonnull K key, @Nonnull V value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); int hash = hash(key); return segmentFor(hash).put(key, hash, value, false); }
@Override public boolean replace(@Nonnull K key, @Nullable V oldValue, @Nonnull V newValue) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(newValue); if (oldValue == null) { return false; } int hash = hash(key); return segmentFor(hash).replace(key, hash, oldValue, newValue); }
@Nullable @Override public V replace(@Nonnull K key, @Nonnull V value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); int hash = hash(key); return segmentFor(hash).replace(key, hash, value); }
@Nullable @Override public V putIfAbsent(@Nonnull K key, @Nonnull V value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); int hash = hash(key); return segmentFor(hash).put(key, hash, value, true); }
@Nonnull public static <I, O> ListenableFuture<O> transform(@Nonnull ListenableFuture<I> input, Function<? super I, ? extends O> function) { Preconditions.checkNotNull(function); Futures.ChainingFuture<I,O> output = new Futures.ChainingFuture(input, function); input.addListener(output, DirectExecutor.INSTANCE); return output; }
/** * This method is a convenience for testing. Code should call {@link Segment#setValue} instead. */ // Guarded By Segment.this @Nonnull ValueReference<K, V> newValueReference(@Nonnull ReferenceEntry<K, V> entry, @Nonnull V value, int weight) { int hash = entry.getHash(); return valueStrength.referenceValue(segmentFor(hash), entry, Preconditions.checkNotNull(value), weight); }
@Nullable V get(@Nonnull K key, @Nonnull CacheLoader<? super K, V> loader) throws ExecutionException { int hash = hash(Preconditions.checkNotNull(key)); return segmentFor(hash).get(key, hash, loader); }