Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / RequirementAssignments.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.List;
25 import java.util.stream.Collectors;
26
27 public class RequirementAssignments {
28
29     private List<RequirementAssignment> requirementAssignmentList;
30
31     public RequirementAssignments(List<RequirementAssignment> requirementAssignments) {
32         this.requirementAssignmentList = requirementAssignments != null ? new ArrayList<>(requirementAssignments) : new ArrayList<>();
33     }
34
35     /**
36      * Get all requirement assignments for Node Template.<br>
37      * This object can be either the original one, holding all requirement assignments for this node template,or a filtered one, holding a filtered subset.<br>
38      *
39      * @return list of requirement assignments for the node template. <br>
40      * If there are no requirement assignments, empty list is returned.
41      */
42     public List<RequirementAssignment> getAll() {
43         return new ArrayList<>(requirementAssignmentList);
44     }
45
46     /**
47      * Filter requirement assignments by requirement name.
48      *
49      * @param reqName - The name of requirement
50      * @return RequirementAssignments object, containing requirement assignments of this type.<br>
51      * If no such found, filtering will result in an empty collection.
52      */
53     public RequirementAssignments getRequirementsByName(String reqName) {
54         List<RequirementAssignment> requirementAssignments = requirementAssignmentList.stream()
55                 .filter(req -> req.getName().equals(reqName)).collect(Collectors.toList());
56
57         return new RequirementAssignments(requirementAssignments);
58     }
59 }