1fd0d31691ba32eb8b3fd98af1c3694842d867ec
[dcaegen2/collectors/ves.git] / src / main / java / org / onap / dcae / common / publishing / PublisherConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dcaegen2.collectors.ves
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.common.publishing;
21
22 import io.vavr.collection.List;
23 import io.vavr.control.Option;
24
25 import java.util.Objects;
26
27 /**
28  * @author Pawel Szalapski (pawel.szalapski@nokia.com)
29  */
30 public final class PublisherConfig {
31
32     private final List<String> destinations;
33     private final String topic;
34     private String userName;
35     private String password;
36
37     PublisherConfig(List<String> destinations, String topic) {
38         this.destinations = destinations;
39         this.topic = topic;
40     }
41
42     PublisherConfig(List<String> destinations, String topic, String userName, String password) {
43         this.destinations = destinations;
44         this.topic = topic;
45         this.userName = userName;
46         this.password = password;
47     }
48
49     List<String> destinations() {
50         return destinations;
51     }
52
53     String topic() {
54         return topic;
55     }
56
57     Option<String> userName() {
58         return Option.of(userName);
59     }
60
61     Option<String> password() {
62         return Option.of(password);
63     }
64
65     boolean isSecured() {
66         return userName().isDefined() && password().isDefined();
67     }
68
69
70     @Override
71     public boolean equals(Object o) {
72         if (this == o) {
73             return true;
74         }
75         if (o == null || getClass() != o.getClass()) {
76             return false;
77         }
78         PublisherConfig that = (PublisherConfig) o;
79         return Objects.equals(destinations, that.destinations) &&
80                 Objects.equals(topic, that.topic) &&
81                 Objects.equals(userName, that.userName) &&
82                 Objects.equals(password, that.password);
83     }
84
85     @Override
86     public int hashCode() {
87         return Objects.hash(destinations, topic, userName, password);
88     }
89
90     @Override
91     public String toString() {
92         return "PublisherConfig{" +
93                 "destinations=" + destinations +
94                 ", topic='" + topic + '\'' +
95                 ", userName='" + userName + '\'' +
96                 ", password='" + password + '\'' +
97                 '}';
98     }
99 }