blob: b3e3da31fdadbe3e434a1a4332777230246c84cc [file] [log] [blame]
Madan Jampani50589ac2015-06-08 11:38:46 -07001/*
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 */
16package org.onosproject.store.consistent.impl;
17
Madan Jampanie8af1cc2015-06-23 14:23:31 -070018import org.onosproject.core.ApplicationId;
Madan Jampani50589ac2015-06-08 11:38:46 -070019import org.onosproject.store.service.ConsistentMapBuilder;
20import org.onosproject.store.service.DistributedSet;
21import org.onosproject.store.service.Serializer;
22import org.onosproject.store.service.DistributedSetBuilder;
23
24/**
25 * Default distributed set builder.
26 *
27 * @param <E> type for set elements
28 */
29public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> {
30
31 private String name;
32 private ConsistentMapBuilder<E, Boolean> mapBuilder;
33
34 public DefaultDistributedSetBuilder(DatabaseManager manager) {
35 this.mapBuilder = manager.consistentMapBuilder();
36 }
37
38 @Override
39 public DistributedSetBuilder<E> withName(String name) {
40 mapBuilder.withName(name);
41 this.name = name;
42 return this;
43 }
44
45 @Override
Madan Jampanie8af1cc2015-06-23 14:23:31 -070046 public DistributedSetBuilder<E> withApplicationId(ApplicationId id) {
47 mapBuilder.withApplicationId(id);
48 return this;
49 }
50
51 @Override
52 public DistributedSetBuilder<E> withPurgeOnUninstall() {
53 mapBuilder.withPurgeOnUninstall();
54 return this;
55 }
56
57 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070058 public DistributedSetBuilder<E> withSerializer(Serializer serializer) {
59 mapBuilder.withSerializer(serializer);
60 return this;
61 }
62
63 @Override
64 public DistributedSetBuilder<E> withUpdatesDisabled() {
65 mapBuilder.withUpdatesDisabled();
66 return this;
67 }
68
69 @Override
70 public DistributedSetBuilder<E> withPartitionsDisabled() {
71 mapBuilder.withPartitionsDisabled();
72 return this;
73 }
74
75 @Override
76 public DistributedSet<E> build() {
77 return new DefaultDistributedSet<E>(name, mapBuilder.build());
78 }
79}