75c013e657d21b43ede2744626b42ec5b6458046
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.dg.objects;
24
25 import java.util.*;
26
27 import org.openecomp.appc.domainmodel.Vnfc;
28
29
30 public class VnfcFlowModel {
31     private Map<Integer,List<Vnfc>> flowModelMap;
32
33     private VnfcFlowModel(VnfcFlowModelBuilder builder){
34         this.flowModelMap = builder.map;
35
36     }
37
38     @Override
39     public String toString() {
40         StringBuilder stringBuilder = new StringBuilder("Flow Model : ");
41         Iterator<List<Vnfc>> iterator = getModelIterator();
42         while(iterator.hasNext()){
43             for(Vnfc vnfc:iterator.next()){
44                 stringBuilder.append(vnfc.toString()).append(", \n");
45             }
46         }
47
48         return stringBuilder.toString();
49     }
50
51     public Iterator<List<Vnfc>> getModelIterator(){
52         return flowModelMap.values().iterator();
53     }
54
55     public static class VnfcFlowModelBuilder{
56
57         Map<Integer,List<Vnfc>> map;
58
59         public VnfcFlowModelBuilder(){
60             map = new HashMap<>();
61         }
62
63         public VnfcFlowModelBuilder addMetadata(Integer index,Vnfc vnfc){
64             List<Vnfc> vnfcList = this.map.get(index);
65             if(vnfcList == null){
66                 vnfcList = new LinkedList<>();
67                 map.put(index,vnfcList);
68             }
69             vnfcList.add(vnfc);
70             return this;
71         }
72
73         public VnfcFlowModelBuilder addMetadata(Integer index,List<Vnfc> vnfcs){
74             List<Vnfc> vnfcList = this.map.get(index);
75             if(vnfcList == null){
76                 vnfcList = new LinkedList<>();
77                 map.put(index,vnfcList);
78             }
79             vnfcList.addAll(vnfcs);
80             return this;
81         }
82
83         public VnfcFlowModel build(){
84             return new VnfcFlowModel(this);
85         }
86
87     }
88
89
90 }