4f8d34e5873472c34214cbadb6a944abfab47d93
[portal/ric-dashboard.git] / webapp-backend / src / main / java / org / oransc / ric / portal / dashboard / model / RicInstanceList.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 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  * ========================LICENSE_END===================================
19  */
20
21 package org.oransc.ric.portal.dashboard.model;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.oransc.ric.portal.dashboard.exception.UnknownInstanceException;
27
28 public class RicInstanceList {
29
30         private final List<RicInstance> instances;
31
32         public RicInstanceList() {
33                 this.instances = new ArrayList<>();
34         }
35
36         public RicInstanceList(List<RicInstance> list) {
37                 this.instances = list;
38         }
39
40         public List<RicInstance> getInstances() {
41                 return instances;
42         }
43
44         /**
45          * Gets a list of key-name pairs.
46          * 
47          * @return List of RicInstanceKeyName objects.
48          */
49         public List<RicInstanceKeyName> getKeyNameList() {
50                 List<RicInstanceKeyName> list = new ArrayList<>();
51                 for (RicInstance i : instances)
52                         list.add(i.toKeyName());
53                 return list;
54         }
55
56         /**
57          * Gets the instance with the specified key
58          * 
59          * @param instanceKey
60          *                        Key to fetch
61          * @return Instance
62          * @throws UnknownInstanceException
63          *                                      If the key is not known
64          */
65         public RicInstance getInstance(String instanceKey) {
66                 for (RicInstance i : instances)
67                         if (i.getKey().equals(instanceKey))
68                                 return i;
69                 throw new UnknownInstanceException(instanceKey);
70         }
71 }