Merge of new rebased code
[appc.git] / appc-dg / appc-dg-shared / appc-dg-dependency-model / src / main / java / org / openecomp / appc / dg / objects / VnfcFlowModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.dg.objects;
23
24 import java.util.*;
25
26 import org.openecomp.appc.domainmodel.Vnfc;
27
28
29 public class VnfcFlowModel {
30     private Map<Integer,List<Vnfc>> flowModelMap;
31
32     private VnfcFlowModel(VnfcFlowModelBuilder builder){
33         this.flowModelMap = builder.map;
34
35     }
36
37     @Override
38     public String toString() {
39         StringBuilder stringBuilder = new StringBuilder("Flow Model : ");
40         Iterator<List<Vnfc>> iterator = getModelIterator();
41         while(iterator.hasNext()){
42             for(Vnfc vnfc:iterator.next()){
43                 stringBuilder.append(vnfc.toString()).append(", \n");
44             }
45         }
46
47         return stringBuilder.toString();
48     }
49
50     public Iterator<List<Vnfc>> getModelIterator(){
51         return flowModelMap.values().iterator();
52     }
53
54     public static class VnfcFlowModelBuilder{
55
56         Map<Integer,List<Vnfc>> map;
57
58         public VnfcFlowModelBuilder(){
59             map = new HashMap<>();
60         }
61
62         public VnfcFlowModelBuilder addMetadata(Integer index,Vnfc vnfc){
63             List<Vnfc> vnfcList = this.map.get(index);
64             if(vnfcList == null){
65                 vnfcList = new LinkedList<>();
66                 map.put(index,vnfcList);
67             }
68             vnfcList.add(vnfc);
69             return this;
70         }
71
72         public VnfcFlowModelBuilder addMetadata(Integer index,List<Vnfc> vnfcs){
73             List<Vnfc> vnfcList = this.map.get(index);
74             if(vnfcList == null){
75                 vnfcList = new LinkedList<>();
76                 map.put(index,vnfcList);
77             }
78             vnfcList.addAll(vnfcs);
79             return this;
80         }
81
82         public VnfcFlowModel build(){
83             return new VnfcFlowModel(this);
84         }
85
86     }
87
88
89 }