public MultiParser(List<KeyParser> parsers) { checkNotNull(parsers, "Parsers can't be null."); checkArgument(!parsers.isEmpty(), "Parsers can't be empty."); for (KeyParser parser : parsers) { checkNotNull(parser, "Parser can't be null."); } this.parsers.addAll(parsers); }
/** * Specifies that each entry should be automatically removed from the cache once a fixed duration * has elapsed after the entry's creation, or the most recent replacement of its value. * * <p>When {@code duration} is zero, this method hands off to * {@link #maximumSize(long) maximumSize}{@code (0)}, ignoring any otherwise-specificed maximum * size or weight. This can be useful in testing, or to disable caching temporarily without a code * change. * * <p>Expired entries may be counted in @link Cache#size}, but will never be visible to read or * write operations. Expired entries are cleaned up as part of the routine maintenance described * in the class javadoc. * * @param duration the length of time after an entry is created that it should be automatically * removed * @param unit the unit that {@code duration} is expressed in * @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalStateException if the time to live or time to idle was already set */ @Nonnull public CacheBuilder<K, V> expireAfterWrite(long duration, @Nonnull TimeUnit unit) { Preconditions.checkState(expireAfterWriteNanos == UNSET_INT, "expireAfterWrite was already set to %s ns", expireAfterWriteNanos); Preconditions.checkArgument(duration >= 0, "duration cannot be negative: %s %s", duration, unit); this.expireAfterWriteNanos = unit.toNanos(duration); return this; }
Preconditions.checkState(this.concurrencyLevel == UNSET_INT, "concurrency level was already set to %s", this.concurrencyLevel); Preconditions.checkArgument(concurrencyLevel > 0); this.concurrencyLevel = concurrencyLevel; return this;
/** * Specifies that each entry should be automatically removed from the cache once a fixed duration * has elapsed after the entry's creation, the most recent replacement of its value, or its last * access. Access time is reset by all cache read and write operations (including * {@code Cache.asMap().get(Object)} and {@code Cache.asMap().put(K, V)}), but not by operations * on the collection-views of @link Cache#asMap}. * * <p>When {@code duration} is zero, this method hands off to * {@link #maximumSize(long) maximumSize}{@code (0)}, ignoring any otherwise-specificed maximum * size or weight. This can be useful in testing, or to disable caching temporarily without a code * change. * * <p>Expired entries may be counted in @link Cache#size}, but will never be visible to read or * write operations. Expired entries are cleaned up as part of the routine maintenance described * in the class javadoc. * * @param duration the length of time after an entry is last accessed that it should be * automatically removed * @param unit the unit that {@code duration} is expressed in * @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalStateException if the time to idle or time to live was already set */ @Nonnull public CacheBuilder<K, V> expireAfterAccess(long duration, @Nonnull TimeUnit unit) { Preconditions.checkState(expireAfterAccessNanos == UNSET_INT, "expireAfterAccess was already set to %s ns", expireAfterAccessNanos); Preconditions.checkArgument(duration >= 0, "duration cannot be negative: %s %s", duration, unit); this.expireAfterAccessNanos = unit.toNanos(duration); return this; }
this.maximumSize); this.maximumWeight = weight; Preconditions.checkArgument(weight >= 0, "maximum weight must not be negative"); return this;
/** * Specifies the maximum number of entries the cache may contain. Note that the cache <b>may evict * an entry before this limit is exceeded</b>. As the cache size grows close to the maximum, the * cache evicts entries that are less likely to be used again. For example, the cache may evict an * entry because it hasn't been used recently or very often. * * <p>When {@code size} is zero, elements will be evicted immediately after being loaded into the * cache. This can be useful in testing, or to disable caching temporarily without a code change. * * <p>This feature cannot be used in conjunction with {@link #maximumWeight}. * * @param size the maximum size of the cache * @throws IllegalArgumentException if {@code size} is negative * @throws IllegalStateException if a maximum size or weight was already set */ @Nonnull public CacheBuilder<K, V> maximumSize(long size) { Preconditions.checkState(this.maximumSize == UNSET_INT, "maximum size was already set to %s", this.maximumSize); Preconditions.checkState(this.maximumWeight == UNSET_INT, "maximum weight was already set to %s", this.maximumWeight); Preconditions.checkState(this.weigher == null, "maximum size can not be combined with weigher"); Preconditions.checkArgument(size >= 0, "maximum size must not be negative"); this.maximumSize = size; return this; }