Specifies the weigher to use in determining the weight of entries. Entry weight is taken into consideration by #maximumWeight(long) when determining which entries to evict, and use of this method requires a corresponding call to #maximumWeight(long) prior to calling #build. W
(Weigher<? super K1, ? super V1> weigher)
| 490 | */ |
| 491 | |
| 492 | @GwtIncompatible // To be supported |
| 493 | public <K1 extends K, V1 extends V> CacheBuilder<K1, V1> weigher(Weigher<? super K1, ? super V1> weigher) { |
| 494 | checkState(this.weigher == null); |
| 495 | if (strictParsing) { |
| 496 | checkState(this.maximumSize == UNSET_INT, |
| 497 | "weigher can not be combined with maximum size", |
| 498 | this.maximumSize); |
| 499 | } |
| 500 | |
| 501 | // safely limiting the kinds of caches this can produce |
| 502 | @SuppressWarnings("unchecked") |
| 503 | CacheBuilder<K1, V1> me = (CacheBuilder<K1, V1>) this; |
| 504 | me.weigher = checkNotNull(weigher); |
| 505 | return me; |
| 506 | } |
| 507 | |
| 508 | long getMaximumWeight() { |
| 509 | if (expireAfterWriteNanos == 0 || expireAfterAccessNanos == 0) { |
no test coverage detected