2 * ============LICENSE_START=======================================================
3 * ONAP Policy Engine - Common Modules
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.endpoints.event.comm.bus;
23 import java.util.Properties;
26 * Builder of properties used when configuring topics.
28 public abstract class TopicPropertyBuilder {
29 private final Properties properties = new Properties();
30 private final String prefix;
31 private String topicPrefix;
34 * Constructs the object.
36 * @param prefix the prefix for the properties to be built
38 public TopicPropertyBuilder(String prefix) {
43 * Constructs the properties from the builder.
45 * @return a copy of the properties
47 public Properties build() {
48 Properties props = new Properties();
49 props.putAll(properties);
55 * Adds a topic to the list of topics, configuring all of its properties with default
58 * @param topic the topic to be added
59 * @return this builder
61 public abstract TopicPropertyBuilder makeTopic(String topic);
64 * Adds a topic to the list of topics. Also sets the current topic so that subsequent
65 * invocations of property methods will manipulate the topic's properties.
67 * @param topic the topic to be added
68 * @return this builder
70 public TopicPropertyBuilder addTopic(String topic) {
71 // add topic to the list of topics
72 String topicList = properties.getProperty(prefix);
73 if (topicList == null || topicList.isEmpty()) {
76 topicList += "," + topic;
79 properties.setProperty(prefix, topicList);
87 * Sets the topic for which subsequent properties will be managed.
89 * @param topic the topic
90 * @return this builder
92 public TopicPropertyBuilder setTopic(String topic) {
93 this.topicPrefix = prefix + "." + topic;
98 * Sets a topic's property.
100 * @param name name of the property
101 * @param value value to which the property should be set
102 * @return this builder
104 public TopicPropertyBuilder setTopicProperty(String name, Object value) {
105 properties.setProperty(topicPrefix + name, value.toString());
110 * Removes a topic's property.
112 * @param name name of the property
113 * @return this builder
115 public TopicPropertyBuilder removeTopicProperty(String name) {
116 properties.remove(topicPrefix + name);