Replace cambria with DmaaP client
[dcaegen2/collectors/ves.git] / src / main / java / org / onap / dcae / multiplestreamreducer / MultipleStreamReducer.java
1 /*
2  * ============LICENSE_START=======================================================
3  * PROJECT
4  * ================================================================================
5  * Copyright (C) 2021 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.multiplestreamreducer;
21
22 import io.vavr.Tuple2;
23 import io.vavr.collection.Map;
24
25 public class MultipleStreamReducer {
26
27     /**
28      * Converts configuration from: "one domain many streams"
29      * to: "one domain one stream"
30      *
31      * @param map domain to streams configuration
32      * @return configuration - one domain one stream
33      */
34     public Map<String, String> reduce(Map<String, String[]> map) {
35         return map.toStream()
36                 .toMap(Tuple2::_1, v -> v._2[0]);
37     }
38
39     /**
40      * Information about the current match: domain to stream
41      *
42      * @param domainToStreamConfig domain to stream configuration
43      * @return current domain to stream information
44      */
45     public String getDomainToStreamsInfo(Map<String, String> domainToStreamConfig) {
46         return domainToStreamConfig.map(v -> "Domain: " +
47                 v._1 + " has active stream: " + v._2 + System.lineSeparator())
48                 .reduce((a, b) -> a + b);
49     }
50 }