blob: 21ca7a15740605d5eed53d5bb67d18196e4278df [file] [log] [blame]
Jordan Halterman400bbe52018-04-05 23:07:47 -07001/*
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 */
16package org.onosproject.store.primitives.impl;
17
18import java.util.function.BiFunction;
19
20import org.onosproject.core.Version;
21import org.onosproject.store.service.AtomicValueBuilder;
22import org.onosproject.store.service.RevisionType;
23import org.onosproject.store.service.Serializer;
24import org.onosproject.store.service.Topic;
25import org.onosproject.store.service.TopicBuilder;
26
27/**
28 * Default topic builder.
29 */
30public class DefaultDistributedTopicBuilder<T> extends TopicBuilder<T> {
31 private final AtomicValueBuilder<T> valueBuilder;
32
33 public DefaultDistributedTopicBuilder(AtomicValueBuilder<T> valueBuilder) {
34 this.valueBuilder = valueBuilder;
35 }
36
37 @Override
38 public TopicBuilder<T> withName(String name) {
39 valueBuilder.withName(name);
40 return this;
41 }
42
43 @Override
44 public TopicBuilder<T> withSerializer(Serializer serializer) {
45 valueBuilder.withSerializer(serializer);
46 return this;
47 }
48
49 @Override
50 public TopicBuilder<T> withVersion(Version version) {
51 valueBuilder.withVersion(version);
52 return this;
53 }
54
55 @Override
56 public TopicBuilder<T> withRevisionType(RevisionType revisionType) {
57 valueBuilder.withRevisionType(revisionType);
58 return this;
59 }
60
61 @Override
62 public TopicBuilder<T> withCompatibilityFunction(BiFunction<T, Version, T> compatibilityFunction) {
63 valueBuilder.withCompatibilityFunction(compatibilityFunction);
64 return this;
65 }
66
67 @Override
68 public Topic<T> build() {
69 return new DefaultDistributedTopic<>(valueBuilder.build());
70 }
71}