blob: e1544fb49bcb92f210b470213a1b2e3b909429e9 [file] [log] [blame]
Aaron Kruglikov92511f22015-10-12 14:39:04 -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 */
16
17package org.onosproject.persistence.impl;
18
19import org.mapdb.DB;
20import org.onosproject.persistence.PersistentSetBuilder;
21import org.onosproject.store.service.Serializer;
22
23import static com.google.common.base.Preconditions.checkArgument;
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Default builder for persistent sets stored in the mapDB local database via the persistence service..
28 */
29public class DefaultPersistentSetBuilder<E> implements PersistentSetBuilder<E> {
30
31 private final DB localDB;
32
33 private String name = null;
34
35 private Serializer serializer = null;
36
37 public DefaultPersistentSetBuilder(DB localDB) {
38 this.localDB = checkNotNull(localDB, "The local database cannot be null.");
39 }
40
41 public PersistentSetBuilder<E> withName(String name) {
42 this.name = PersistenceManager.SET_PREFIX + checkNotNull(name);
43 return this;
44 }
45
46 public PersistentSetBuilder<E> withSerializer(Serializer serializer) {
47 checkArgument(this.serializer == null);
48 checkNotNull(serializer);
49 this.serializer = serializer;
50 return this;
51 }
52
53 public PersistentSet<E> build() {
54 checkNotNull(name, "The name must be assigned.");
55 checkNotNull(serializer, "The serializer must be assigned.");
56
57 return new PersistentSet<E>(serializer, localDB, name);
58 }
59}