2 * ============LICENSE_START=======================================================
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
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.sdc.toscaparser.api;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.stream.Collectors;
29 public class CapabilityAssignments {
31 private Map<String, CapabilityAssignment> capabilityAssignments;
33 public CapabilityAssignments(Map<String, CapabilityAssignment> capabilityAssignments) {
34 this.capabilityAssignments = capabilityAssignments != null ? new HashMap<>(capabilityAssignments) : new HashMap<>();
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>
41 * @return list of capability assignments for the node template. <br>
42 * If there are no capability assignments, empty list is returned.
44 public List<CapabilityAssignment> getAll() {
45 return new ArrayList<>(capabilityAssignments.values());
49 * Filter capability assignments by capability tosca type.
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.
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));
59 return new CapabilityAssignments(capabilityAssignmentsMap);
63 * Get capability assignment by capability name.
65 * @param name - The name of capability assignment
66 * @return capability assignment with this name, or null if no such capability assignment was found.
68 public CapabilityAssignment getCapabilityByName(String name) {
69 return capabilityAssignments.get(name);