18ccba6510efb874d126a44d911dfbeb20ce2140
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * ECOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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  * ================================================================================
19  */
20 package org.openecomp.portalsdk.analytics.gmap.line;
21
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.Set;
25
26 public class LineCollection {
27         private Set<String> selectedLine; // all selected node
28         private String lineID; // last clicked node
29         private ArrayList<LineInfo> lineCollection;
30         
31         public LineCollection() {
32                 lineCollection = new ArrayList<LineInfo>(20000);
33                 selectedLine = new HashSet<String>();
34         }
35         
36         public void addSelectedLine(String lineID) {
37                 selectedLine.add(lineID);
38         }
39
40         public void removeSelectedLine(String lineID) {
41                 selectedLine.remove(lineID);
42         }
43
44         public Set<String> getSelectedLine() {
45                 return selectedLine;
46         }
47
48         public boolean containSelectedLine(String lineID) {
49                 return selectedLine.contains(lineID);
50         }
51
52         public void clearSelectedLine() {
53                 selectedLine.clear();
54         }
55         
56         public void addLine(LineInfo lineInfo) {
57                 lineCollection.add(lineInfo);
58         }
59         
60         public ArrayList<LineInfo> getLineCollection() {
61                 return lineCollection;
62         }
63         
64         public LineInfo getLine(String lineID) {
65                 for (LineInfo lineInfo : lineCollection) {
66                         if (lineInfo.getLineID().equalsIgnoreCase(lineID)) {
67                                 return lineInfo;
68                         }
69                 }
70                 
71                 return null;
72         }
73         
74         public LineInfo getLine(String lineID, String lineType) {
75                 for (LineInfo lineInfo : lineCollection) {
76                         if (lineInfo.getLineID().equalsIgnoreCase(lineID) && lineInfo.getLineType().equalsIgnoreCase(lineType)) {
77                                 return lineInfo;
78                         }
79                 }
80                 
81                 return null;
82         }
83         
84         public LineInfo getLine(String nodeID1, String nodeID2, boolean dummy) {
85                 for (LineInfo lineInfo : lineCollection) {
86                         if ((lineInfo.getNodeID1().equalsIgnoreCase(nodeID1) && lineInfo.getNodeID2().equalsIgnoreCase(nodeID2)) ||
87                                         (lineInfo.getNodeID1().equalsIgnoreCase(nodeID2) && lineInfo.getNodeID2().equalsIgnoreCase(nodeID1))) {
88                                 return lineInfo;
89                         }
90                 }
91                 
92                 return null;
93         }
94         
95         public LineInfo removeLine(String lineID) {
96                 for (int i = 0; i < lineCollection.size(); i++) {
97                         if (lineCollection.get(i).getLineID().equalsIgnoreCase(lineID)) {
98                                 return lineCollection.remove(i);
99                         }
100                 }
101                 
102                 removeSelectedLine(lineID);
103                 return null;
104         }
105
106         public LineInfo removeLine(String lineID, String lineType) {
107                 for (int i = 0; i < lineCollection.size(); i++) {
108                         if (lineCollection.get(i).getLineID().equalsIgnoreCase(lineID) && 
109                                         lineCollection.get(i).getLineType().equalsIgnoreCase(lineType)) {
110                                 return lineCollection.remove(i);
111                         }
112                 }
113                 
114                 removeSelectedLine(lineID);
115                 return null;
116         }
117
118         public void clearLine() {
119                 lineCollection.clear();
120                 selectedLine.clear();
121         }
122         
123         public int getSize() {
124                 return lineCollection.size();
125         }
126
127         public String getLineID() {
128                 return lineID;
129         }
130
131         public void setLineID(String lineID) {
132                 this.lineID = lineID;
133         }
134         
135         public void clearAllCollection () {
136                 clearLine();
137                 clearSelectedLine();
138                 this.lineID = null;
139         }
140         
141         public String[] getWildCardLine(String lineID) {
142                 ArrayList<String> list = new ArrayList<String>();
143
144                 for (LineInfo lineInfo : lineCollection) {
145                         if (lineInfo.getLineID().toLowerCase().indexOf(lineID.toLowerCase()) != -1) {
146                                 list.add(lineInfo.getLineID());
147                         }
148                 }
149
150                 String[] result = new String[list.size()];
151
152                 for (int i = 0; i < list.size(); i++) {
153                         result[i] = list.get(i);
154                 }
155
156                 return result;
157         }
158 }