Creates a CacheBuilderSpec from a string. @param cacheBuilderSpecification the string form
(String cacheBuilderSpecification)
| 132 | |
| 133 | |
| 134 | public static CacheBuilderSpec parse(String cacheBuilderSpecification) { |
| 135 | CacheBuilderSpec spec = new CacheBuilderSpec(cacheBuilderSpecification); |
| 136 | if (!cacheBuilderSpecification.isEmpty()) { |
| 137 | for (String keyValuePair : KEYS_SPLITTER.split(cacheBuilderSpecification)) { |
| 138 | List<String> keyAndValue = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyValuePair)); |
| 139 | checkArgument(!keyAndValue.isEmpty(), "blank key-value pair"); |
| 140 | checkArgument(keyAndValue.size() <= 2, "key-value pair %s with more than one equals sign", keyValuePair); |
| 141 | |
| 142 | // Find the ValueParser for the current key. |
| 143 | String key = keyAndValue.get(0); |
| 144 | ValueParser valueParser = VALUE_PARSERS.get(key); |
| 145 | checkArgument(valueParser != null, "unknown key %s", key); |
| 146 | String value = keyAndValue.size() == 1 ? null : keyAndValue.get(1); |
| 147 | valueParser.parse(spec, key, value); |
| 148 | } |
| 149 | } |
| 150 | return spec; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Returns a CacheBuilderSpec that will prevent caching. |