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 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) {
40 properties.setProperty(prefix, "");
44 * Constructs the properties from the builder.
46 * @return a copy of the properties
48 public Properties build() {
49 Properties props = new Properties();
50 props.putAll(properties);
56 * Adds a topic to the list of topics. Also sets the current topic so that subsequent
57 * invocations of property methods will manipulate the topic's properties.
59 * @param topic the topic to be added
60 * @return this builder
62 public TopicPropertyBuilder addTopic(String topic) {
63 // add topic to the list of topics
64 String topicList = properties.getProperty(prefix);
65 if (!topicList.isEmpty()) {
69 properties.setProperty(prefix, topicList);
77 * Sets the topic for which subsequent properties will be managed.
79 * @param topic the topic
80 * @return this builder
82 public TopicPropertyBuilder setTopic(String topic) {
83 this.topicPrefix = prefix + "." + topic;
88 * Sets a topic's property.
90 * @param name name of the property
91 * @param value value to which the property should be set
92 * @return this builder
94 public TopicPropertyBuilder setTopicProperty(String name, Object value) {
95 properties.setProperty(topicPrefix + name, value.toString());
100 * Removes a topic's property.
102 * @param name name of the property
103 * @return this builder
105 public TopicPropertyBuilder removeTopicProperty(String name) {
106 properties.remove(topicPrefix + name);