A specification of a {@link CacheBuilder} configuration. <p>{@code CacheBuilderSpec} supports parsing configuration off of a string, which makes it especially useful for command-line configuration of a {@code CacheBuilder}. <p>The string syntax is a series of comma-separated keys or key-value pair
| 83 | * @since 12.0 |
| 84 | */ |
| 85 | @SuppressWarnings(class="st">"GoodTime") class="cm">// lots of violations (nanosecond math) |
| 86 | @GwtIncompatible |
| 87 | public final class CacheBuilderSpec { |
| 88 | /** Parses a single value. */ |
| 89 | private interface ValueParser { |
| 90 | void parse(CacheBuilderSpec spec, String key, @Nullable String value); |
| 91 | } |
| 92 | |
| 93 | /** Splits each key-value pair. */ |
| 94 | private static final Splitter KEYS_SPLITTER = Splitter.on(class="st">',').trimResults(); |
| 95 | |
| 96 | /** Splits the key from the value. */ |
| 97 | private static final Splitter KEY_VALUE_SPLITTER = Splitter.on(class="st">'=').trimResults(); |
| 98 | |
| 99 | /** Map of names to ValueParser. */ |
| 100 | private static final ImmutableMap<String, ValueParser> VALUE_PARSERS = |
| 101 | ImmutableMap.<String, ValueParser>builder() |
| 102 | .put(class="st">"initialCapacity", new InitialCapacityParser()) |
| 103 | .put(class="st">"maximumSize", new MaximumSizeParser()) |
| 104 | .put(class="st">"maximumWeight", new MaximumWeightParser()) |
| 105 | .put(class="st">"concurrencyLevel", new ConcurrencyLevelParser()) |
| 106 | .put(class="st">"weakKeys", new KeyStrengthParser(Strength.WEAK)) |
| 107 | .put(class="st">"softValues", new ValueStrengthParser(Strength.SOFT)) |
| 108 | .put(class="st">"weakValues", new ValueStrengthParser(Strength.WEAK)) |
| 109 | .put(class="st">"recordStats", new RecordStatsParser()) |
| 110 | .put(class="st">"expireAfterAccess", new AccessDurationParser()) |
| 111 | .put(class="st">"expireAfterWrite", new WriteDurationParser()) |
| 112 | .put(class="st">"refreshAfterWrite", new RefreshDurationParser()) |
| 113 | .put(class="st">"refreshInterval", new RefreshDurationParser()) |
| 114 | .buildOrThrow(); |
| 115 | |
| 116 | @VisibleForTesting @Nullable Integer initialCapacity; |
| 117 | @VisibleForTesting @Nullable Long maximumSize; |
| 118 | @VisibleForTesting @Nullable Long maximumWeight; |
| 119 | @VisibleForTesting @Nullable Integer concurrencyLevel; |
| 120 | @VisibleForTesting @Nullable Strength keyStrength; |
| 121 | @VisibleForTesting @Nullable Strength valueStrength; |
| 122 | @VisibleForTesting @Nullable Boolean recordStats; |
| 123 | @VisibleForTesting long writeExpirationDuration; |
| 124 | @VisibleForTesting @Nullable TimeUnit writeExpirationTimeUnit; |
| 125 | @VisibleForTesting long accessExpirationDuration; |
| 126 | @VisibleForTesting @Nullable TimeUnit accessExpirationTimeUnit; |
| 127 | @VisibleForTesting long refreshDuration; |
| 128 | @VisibleForTesting @Nullable TimeUnit refreshTimeUnit; |
| 129 | |
| 130 | /** Specification; used for toParseableString(). */ |
| 131 | private final String specification; |
| 132 | |
| 133 | private CacheBuilderSpec(String specification) { |
| 134 | this.specification = specification; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Creates a CacheBuilderSpec from a string. |
| 139 | * |
| 140 | * @param cacheBuilderSpecification the string form |
| 141 | */ |
| 142 | public static CacheBuilderSpec parse(String cacheBuilderSpecification) { |
nothing calls this directly
no test coverage detected