Merge "Feature toggle for owning-entities filtering"
[vid.git] / vid-app-common / src / main / java / org / onap / vid / utils / Multival.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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
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
21 package org.onap.vid.utils;
22
23 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
24
25 import java.util.Collection;
26 import java.util.function.Function;
27
28 import static java.util.stream.Collectors.toSet;
29
30 @JsonPropertyOrder({"keyType", "valuesType"})
31 public class Multival<K, V> {
32     private final String keyType;
33     private final String valuesType;
34     private final K key;
35     private final Collection<V> values;
36
37     private Multival(String keyType, K key, String valuesType, Collection<V> values) {
38         this.keyType = keyType;
39         this.key = key;
40         this.valuesType = valuesType;
41         this.values = values;
42     }
43
44     public static <K, V> Multival<K, V> of(String keyType, K key, String valuesType, Collection<V> values) {
45         return new Multival<>(keyType, key, valuesType, values);
46     }
47
48     public String getKeyType() {
49         return keyType;
50     }
51
52     public String getValuesType() {
53         return valuesType;
54     }
55
56     public K getKey() {
57         return key;
58     }
59
60     public Collection<V> getValues() {
61         return values;
62     }
63
64     public <W> Multival<K, W> mapEachVal(Function<V, W> mapper) {
65         return Multival.of(
66                 this.getKeyType(),
67                 this.getKey(),
68                 this.getValuesType(),
69                 this.getValues().stream()
70                         .map(mapper)
71                         .collect(toSet())
72         );
73     }
74 }