Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.store.consistent.impl; |
| 18 | |
| 19 | import static com.google.common.base.Preconditions.*; |
| 20 | |
| 21 | import java.util.Collection; |
| 22 | import java.util.Map; |
| 23 | import java.util.Map.Entry; |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 24 | import java.util.Objects; |
| 25 | import java.util.Optional; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 26 | import java.util.concurrent.CompletableFuture; |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 27 | import java.util.concurrent.atomic.AtomicReference; |
| 28 | import java.util.function.BiFunction; |
| 29 | import java.util.function.Function; |
| 30 | import java.util.function.Predicate; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 31 | import java.util.stream.Collectors; |
| 32 | import java.util.Set; |
| 33 | |
| 34 | import org.apache.commons.lang3.tuple.Pair; |
| 35 | import org.onlab.util.HexString; |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 36 | import org.onlab.util.Tools; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 37 | import org.onosproject.store.service.AsyncConsistentMap; |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 38 | import org.onosproject.store.service.ConsistentMapException; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 39 | import org.onosproject.store.service.Serializer; |
| 40 | import org.onosproject.store.service.Versioned; |
| 41 | |
| 42 | import com.google.common.cache.CacheBuilder; |
| 43 | import com.google.common.cache.CacheLoader; |
| 44 | import com.google.common.cache.LoadingCache; |
| 45 | |
| 46 | /** |
| 47 | * AsyncConsistentMap implementation that is backed by a Raft consensus |
| 48 | * based database. |
| 49 | * |
| 50 | * @param <K> type of key. |
| 51 | * @param <V> type of value. |
| 52 | */ |
| 53 | public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V> { |
| 54 | |
| 55 | private final String name; |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 56 | private final Database database; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 57 | private final Serializer serializer; |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 58 | private final boolean readOnly; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 59 | |
| 60 | private static final String ERROR_NULL_KEY = "Key cannot be null"; |
| 61 | private static final String ERROR_NULL_VALUE = "Null values are not allowed"; |
| 62 | |
| 63 | private final LoadingCache<K, String> keyCache = CacheBuilder.newBuilder() |
| 64 | .softValues() |
| 65 | .build(new CacheLoader<K, String>() { |
| 66 | |
| 67 | @Override |
| 68 | public String load(K key) { |
| 69 | return HexString.toHexString(serializer.encode(key)); |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | protected K dK(String key) { |
| 74 | return serializer.decode(HexString.fromHexString(key)); |
| 75 | } |
| 76 | |
| 77 | public DefaultAsyncConsistentMap(String name, |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 78 | Database database, |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 79 | Serializer serializer, |
| 80 | boolean readOnly) { |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 81 | this.name = checkNotNull(name, "map name cannot be null"); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 82 | this.database = checkNotNull(database, "database cannot be null"); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 83 | this.serializer = checkNotNull(serializer, "serializer cannot be null"); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 84 | this.readOnly = readOnly; |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public CompletableFuture<Integer> size() { |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 89 | return database.size(name); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public CompletableFuture<Boolean> isEmpty() { |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 94 | return database.isEmpty(name); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public CompletableFuture<Boolean> containsKey(K key) { |
| 99 | checkNotNull(key, ERROR_NULL_KEY); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 100 | return database.containsKey(name, keyCache.getUnchecked(key)); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public CompletableFuture<Boolean> containsValue(V value) { |
| 105 | checkNotNull(value, ERROR_NULL_VALUE); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 106 | return database.containsValue(name, serializer.encode(value)); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public CompletableFuture<Versioned<V>> get(K key) { |
| 111 | checkNotNull(key, ERROR_NULL_KEY); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 112 | return database.get(name, keyCache.getUnchecked(key)) |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 113 | .thenApply(v -> v != null |
| 114 | ? new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime()) : null); |
| 115 | } |
| 116 | |
| 117 | @Override |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 118 | public CompletableFuture<Versioned<V>> computeIfAbsent(K key, |
| 119 | Function<? super K, ? extends V> mappingFunction) { |
| 120 | return computeIf(key, Objects::isNull, (k, v) -> mappingFunction.apply(k)); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public CompletableFuture<Versioned<V>> computeIfPresent(K key, |
| 125 | BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
| 126 | return computeIf(key, Objects::nonNull, remappingFunction); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public CompletableFuture<Versioned<V>> compute(K key, |
| 131 | BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
| 132 | return computeIf(key, v -> true, remappingFunction); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public CompletableFuture<Versioned<V>> computeIf(K key, |
| 137 | Predicate<? super V> condition, |
| 138 | BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
| 139 | checkNotNull(key, ERROR_NULL_KEY); |
| 140 | checkNotNull(condition, "predicate function cannot be null"); |
| 141 | checkNotNull(remappingFunction, "Remapping function cannot be null"); |
| 142 | return get(key).thenCompose(r1 -> { |
| 143 | V existingValue = r1 == null ? null : r1.value(); |
| 144 | // if the condition evaluates to false, return existing value. |
| 145 | if (!condition.test(existingValue)) { |
| 146 | return CompletableFuture.completedFuture(r1); |
| 147 | } |
| 148 | |
| 149 | AtomicReference<V> computedValue = new AtomicReference<>(); |
| 150 | // if remappingFunction throws an exception, return the exception. |
| 151 | try { |
| 152 | computedValue.set(remappingFunction.apply(key, existingValue)); |
| 153 | } catch (Exception e) { |
| 154 | return Tools.exceptionalFuture(e); |
| 155 | } |
| 156 | |
| 157 | // if the computed value is null, remove current value if one exists. |
| 158 | // throw an exception if concurrent modification is detected. |
| 159 | if (computedValue.get() == null) { |
| 160 | if (r1 != null) { |
| 161 | return remove(key, r1.version()).thenApply(result -> { |
| 162 | if (result) { |
| 163 | return null; |
| 164 | } else { |
| 165 | throw new ConsistentMapException.ConcurrentModification(); |
| 166 | } |
| 167 | }); |
| 168 | } else { |
| 169 | return CompletableFuture.completedFuture(null); |
| 170 | } |
| 171 | } else { |
| 172 | // replace current value; throw an exception if concurrent modification is detected |
| 173 | if (r1 != null) { |
| 174 | return replaceAndGet(key, r1.version(), computedValue.get()) |
| 175 | .thenApply(v -> { |
| 176 | if (v.isPresent()) { |
| 177 | return v.get(); |
| 178 | } else { |
| 179 | throw new ConsistentMapException.ConcurrentModification(); |
| 180 | } |
| 181 | }); |
| 182 | } else { |
| 183 | return putIfAbsentAndGet(key, computedValue.get()).thenApply(result -> { |
| 184 | if (!result.isPresent()) { |
| 185 | throw new ConsistentMapException.ConcurrentModification(); |
| 186 | } else { |
| 187 | return result.get(); |
| 188 | } |
| 189 | }); |
| 190 | } |
| 191 | } |
| 192 | }); |
| 193 | } |
| 194 | |
| 195 | @Override |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 196 | public CompletableFuture<Versioned<V>> put(K key, V value) { |
| 197 | checkNotNull(key, ERROR_NULL_KEY); |
| 198 | checkNotNull(value, ERROR_NULL_VALUE); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 199 | checkIfUnmodifiable(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 200 | return database.put(name, keyCache.getUnchecked(key), serializer.encode(value)) |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 201 | .thenApply(this::unwrapResult) |
| 202 | .thenApply(v -> v != null |
| 203 | ? new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime()) : null); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public CompletableFuture<Versioned<V>> putAndGet(K key, V value) { |
| 208 | checkNotNull(key, ERROR_NULL_KEY); |
| 209 | checkNotNull(value, ERROR_NULL_VALUE); |
| 210 | checkIfUnmodifiable(); |
| 211 | return database.putAndGet(name, keyCache.getUnchecked(key), serializer.encode(value)) |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 212 | .thenApply(this::unwrapResult) |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 213 | .thenApply(v -> { |
| 214 | Versioned<byte[]> rawNewValue = v.newValue(); |
| 215 | return new Versioned<>(serializer.decode(rawNewValue.value()), |
| 216 | rawNewValue.version(), |
| 217 | rawNewValue.creationTime()); |
| 218 | }); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public CompletableFuture<Optional<Versioned<V>>> putIfAbsentAndGet(K key, V value) { |
| 223 | checkNotNull(key, ERROR_NULL_KEY); |
| 224 | checkNotNull(value, ERROR_NULL_VALUE); |
| 225 | checkIfUnmodifiable(); |
| 226 | return database.putIfAbsentAndGet(name, keyCache.getUnchecked(key), serializer.encode(value)) |
| 227 | .thenApply(this::unwrapResult) |
| 228 | .thenApply(v -> { |
| 229 | if (v.updated()) { |
| 230 | Versioned<byte[]> rawNewValue = v.newValue(); |
| 231 | return Optional.of(new Versioned<>(serializer.decode(rawNewValue.value()), |
| 232 | rawNewValue.version(), |
| 233 | rawNewValue.creationTime())); |
| 234 | } else { |
| 235 | return Optional.empty(); |
| 236 | } |
| 237 | }); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public CompletableFuture<Versioned<V>> remove(K key) { |
| 242 | checkNotNull(key, ERROR_NULL_KEY); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 243 | checkIfUnmodifiable(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 244 | return database.remove(name, keyCache.getUnchecked(key)) |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 245 | .thenApply(this::unwrapResult) |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 246 | .thenApply(v -> v != null |
| 247 | ? new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime()) : null); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public CompletableFuture<Void> clear() { |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 252 | checkIfUnmodifiable(); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 253 | return database.clear(name).thenApply(this::unwrapResult); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public CompletableFuture<Set<K>> keySet() { |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 258 | return database.keySet(name) |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 259 | .thenApply(s -> s |
| 260 | .stream() |
| 261 | .map(this::dK) |
| 262 | .collect(Collectors.toSet())); |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public CompletableFuture<Collection<Versioned<V>>> values() { |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 267 | return database.values(name).thenApply(c -> c |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 268 | .stream() |
| 269 | .map(v -> new Versioned<V>(serializer.decode(v.value()), v.version(), v.creationTime())) |
| 270 | .collect(Collectors.toList())); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet() { |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 275 | return database.entrySet(name).thenApply(s -> s |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 276 | .stream() |
| 277 | .map(this::fromRawEntry) |
| 278 | .collect(Collectors.toSet())); |
| 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public CompletableFuture<Versioned<V>> putIfAbsent(K key, V value) { |
| 283 | checkNotNull(key, ERROR_NULL_KEY); |
| 284 | checkNotNull(value, ERROR_NULL_VALUE); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 285 | checkIfUnmodifiable(); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 286 | return database.putIfAbsent(name, |
| 287 | keyCache.getUnchecked(key), |
| 288 | serializer.encode(value)) |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 289 | .thenApply(this::unwrapResult) |
| 290 | .thenApply(v -> v != null ? |
| 291 | new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime()) : null); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public CompletableFuture<Boolean> remove(K key, V value) { |
| 296 | checkNotNull(key, ERROR_NULL_KEY); |
| 297 | checkNotNull(value, ERROR_NULL_VALUE); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 298 | checkIfUnmodifiable(); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 299 | return database.remove(name, keyCache.getUnchecked(key), serializer.encode(value)) |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 300 | .thenApply(this::unwrapResult); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public CompletableFuture<Boolean> remove(K key, long version) { |
| 305 | checkNotNull(key, ERROR_NULL_KEY); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 306 | checkIfUnmodifiable(); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 307 | return database.remove(name, keyCache.getUnchecked(key), version) |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 308 | .thenApply(this::unwrapResult); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 309 | |
| 310 | } |
| 311 | |
| 312 | @Override |
| 313 | public CompletableFuture<Boolean> replace(K key, V oldValue, V newValue) { |
| 314 | checkNotNull(key, ERROR_NULL_KEY); |
| 315 | checkNotNull(newValue, ERROR_NULL_VALUE); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 316 | checkIfUnmodifiable(); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 317 | byte[] existing = oldValue != null ? serializer.encode(oldValue) : null; |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 318 | return database.replace(name, keyCache.getUnchecked(key), existing, serializer.encode(newValue)) |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 319 | .thenApply(this::unwrapResult); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) { |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 324 | return replaceAndGet(key, oldVersion, newValue).thenApply(Optional::isPresent); |
| 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public CompletableFuture<Optional<Versioned<V>>> replaceAndGet(K key, long oldVersion, V newValue) { |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 329 | checkNotNull(key, ERROR_NULL_KEY); |
| 330 | checkNotNull(newValue, ERROR_NULL_VALUE); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 331 | checkIfUnmodifiable(); |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame^] | 332 | return database.replaceAndGet(name, |
| 333 | keyCache.getUnchecked(key), |
| 334 | oldVersion, |
| 335 | serializer.encode(newValue)) |
| 336 | .thenApply(this::unwrapResult) |
| 337 | .thenApply(v -> { |
| 338 | if (v.updated()) { |
| 339 | Versioned<byte[]> rawNewValue = v.newValue(); |
| 340 | return Optional.of(new Versioned<>(serializer.decode(rawNewValue.value()), |
| 341 | rawNewValue.version(), |
| 342 | rawNewValue.creationTime())); |
| 343 | } else { |
| 344 | return Optional.empty(); |
| 345 | } |
| 346 | }); |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | private Map.Entry<K, Versioned<V>> fromRawEntry(Map.Entry<String, Versioned<byte[]>> e) { |
| 350 | return Pair.of( |
| 351 | dK(e.getKey()), |
| 352 | new Versioned<>( |
| 353 | serializer.decode(e.getValue().value()), |
| 354 | e.getValue().version(), |
| 355 | e.getValue().creationTime())); |
| 356 | } |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 357 | |
| 358 | private <T> T unwrapResult(Result<T> result) { |
| 359 | if (result.status() == Result.Status.LOCKED) { |
| 360 | throw new ConsistentMapException.ConcurrentModification(); |
| 361 | } else if (result.success()) { |
| 362 | return result.value(); |
| 363 | } else { |
| 364 | throw new IllegalStateException("Must not be here"); |
| 365 | } |
| 366 | } |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 367 | |
| 368 | private void checkIfUnmodifiable() { |
| 369 | if (readOnly) { |
| 370 | throw new UnsupportedOperationException(); |
| 371 | } |
| 372 | } |
Madan Jampani | 7c52100 | 2015-03-23 12:23:01 -0700 | [diff] [blame] | 373 | } |