Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / CapabilityAssignments.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 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.sdc.toscaparser.api;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.stream.Collectors;
28
29 public class CapabilityAssignments {
30
31     private Map<String, CapabilityAssignment> capabilityAssignments;
32
33     public CapabilityAssignments(Map<String, CapabilityAssignment> capabilityAssignments) {
34         this.capabilityAssignments = capabilityAssignments != null ? new HashMap<>(capabilityAssignments) : new HashMap<>();
35     }
36
37     /**
38      * Get all capability assignments for node template.<br>
39      * This object can be either the original one, holding all capability assignments for this node template,or a filtered one, holding a filtered subset.<br>
40      *
41      * @return list of capability assignments for the node template. <br>
42      * If there are no capability assignments, empty list is returned.
43      */
44     public List<CapabilityAssignment> getAll() {
45         return new ArrayList<>(capabilityAssignments.values());
46     }
47
48     /**
49      * Filter capability assignments by capability tosca type.
50      *
51      * @param type - The tosca type of capability assignments.
52      * @return CapabilityAssignments object, containing capability assignments of this type.<br>
53      * If no such found, filtering will result in an empty collection.
54      */
55     public CapabilityAssignments getCapabilitiesByType(String type) {
56         Map<String, CapabilityAssignment> capabilityAssignmentsMap = capabilityAssignments.entrySet().stream()
57                 .filter(cap -> cap.getValue().getDefinition().getType().equals(type)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
58
59         return new CapabilityAssignments(capabilityAssignmentsMap);
60     }
61
62     /**
63      * Get capability assignment by capability name.
64      *
65      * @param name - The name of capability assignment
66      * @return capability assignment with this name, or null if no such capability assignment was found.
67      */
68     public CapabilityAssignment getCapabilityByName(String name) {
69         return capabilityAssignments.get(name);
70     }
71
72 }