blob: 57ec232a50fd5ce5b1efea90e66cfb865a18b0f3 [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
18import org.onosproject.store.service.ConsistentMapBuilder;
19import org.onosproject.store.service.DistributedSet;
20import org.onosproject.store.service.Serializer;
21import org.onosproject.store.service.DistributedSetBuilder;
22
23/**
24 * Default distributed set builder.
25 *
26 * @param <E> type for set elements
27 */
28public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> {
29
30 private String name;
31 private ConsistentMapBuilder<E, Boolean> mapBuilder;
32
33 public DefaultDistributedSetBuilder(DatabaseManager manager) {
34 this.mapBuilder = manager.consistentMapBuilder();
35 }
36
37 @Override
38 public DistributedSetBuilder<E> withName(String name) {
39 mapBuilder.withName(name);
40 this.name = name;
41 return this;
42 }
43
44 @Override
45 public DistributedSetBuilder<E> withSerializer(Serializer serializer) {
46 mapBuilder.withSerializer(serializer);
47 return this;
48 }
49
50 @Override
51 public DistributedSetBuilder<E> withUpdatesDisabled() {
52 mapBuilder.withUpdatesDisabled();
53 return this;
54 }
55
56 @Override
57 public DistributedSetBuilder<E> withPartitionsDisabled() {
58 mapBuilder.withPartitionsDisabled();
59 return this;
60 }
61
62 @Override
63 public DistributedSet<E> build() {
64 return new DefaultDistributedSet<E>(name, mapBuilder.build());
65 }
66}