Jordan Halterman | 2c04599 | 2018-03-20 21:33:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.store.service; |
| 17 | |
Jordan Halterman | 4500817 | 2018-03-19 16:40:31 -0700 | [diff] [blame] | 18 | import java.util.function.BiFunction; |
| 19 | |
Jordan Halterman | 2c04599 | 2018-03-20 21:33:00 -0700 | [diff] [blame] | 20 | import org.onosproject.store.primitives.DistributedPrimitiveOptions; |
| 21 | |
| 22 | /** |
| 23 | * Builder for {@link ConsistentMap} instances. |
| 24 | * |
| 25 | * @param <K> type for map key |
| 26 | * @param <V> type for map value |
| 27 | */ |
| 28 | public abstract class ConsistentMapOptions<O extends ConsistentMapOptions<O, K, V>, K, V> |
| 29 | extends DistributedPrimitiveOptions<O> { |
| 30 | |
| 31 | private boolean nullValues = false; |
| 32 | private boolean purgeOnUninstall = false; |
Jordan Halterman | 4500817 | 2018-03-19 16:40:31 -0700 | [diff] [blame] | 33 | protected BiFunction<V, org.onosproject.core.Version, V> compatibilityFunction; |
Jordan Halterman | 2c04599 | 2018-03-20 21:33:00 -0700 | [diff] [blame] | 34 | |
| 35 | public ConsistentMapOptions() { |
| 36 | super(DistributedPrimitive.Type.CONSISTENT_MAP); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Enables null values in the map. |
| 41 | * |
| 42 | * @return this builder |
| 43 | */ |
| 44 | public O withNullValues() { |
| 45 | nullValues = true; |
| 46 | return (O) this; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Clears map contents when the owning application is uninstalled. |
| 51 | * |
| 52 | * @return this builder |
| 53 | */ |
| 54 | public O withPurgeOnUninstall() { |
| 55 | purgeOnUninstall = true; |
| 56 | return (O) this; |
| 57 | } |
| 58 | |
| 59 | /** |
Jordan Halterman | 4500817 | 2018-03-19 16:40:31 -0700 | [diff] [blame] | 60 | * Sets a compatibility function on the map. |
| 61 | * |
| 62 | * @param compatibilityFunction the compatibility function |
| 63 | * @return the consistent map builder |
| 64 | */ |
| 65 | @SuppressWarnings("unchecked") |
| 66 | public O withCompatibilityFunction( |
| 67 | BiFunction<V, org.onosproject.core.Version, V> compatibilityFunction) { |
| 68 | this.compatibilityFunction = compatibilityFunction; |
| 69 | return (O) this; |
| 70 | } |
| 71 | |
| 72 | /** |
Jordan Halterman | 2c04599 | 2018-03-20 21:33:00 -0700 | [diff] [blame] | 73 | * Returns whether null values are supported by the map. |
| 74 | * |
| 75 | * @return {@code true} if null values are supported; {@code false} otherwise |
| 76 | */ |
| 77 | public boolean nullValues() { |
| 78 | return nullValues; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns if map entries need to be cleared when owning application is uninstalled. |
| 83 | * @return {@code true} if yes; {@code false} otherwise. |
| 84 | */ |
| 85 | public boolean purgeOnUninstall() { |
| 86 | return purgeOnUninstall; |
| 87 | } |
| 88 | |
| 89 | } |