RIC:1060: Change in PTL
[ric-plt/xapp-frame.git] / pkg / xapp / rmrendpointlist.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package xapp
21
22 import (
23         "strings"
24 )
25
26 //-----------------------------------------------------------------------------
27 //
28 //-----------------------------------------------------------------------------
29 type RmrEndpointList struct {
30         Endpoints []RmrEndpoint
31 }
32
33 func (eplist *RmrEndpointList) String() string {
34         valuesText := eplist.StringList()
35         return strings.Join(valuesText, ",")
36 }
37
38 func (eplist *RmrEndpointList) StringList() []string {
39         tmpList := eplist.Endpoints
40         valuesText := []string{}
41         for i := range tmpList {
42                 valuesText = append(valuesText, tmpList[i].String())
43         }
44         return valuesText
45 }
46
47 func (eplist *RmrEndpointList) Size() int {
48         return len(eplist.Endpoints)
49 }
50
51 func (eplist *RmrEndpointList) AddEndpoint(ep *RmrEndpoint) bool {
52         for i := range eplist.Endpoints {
53                 if eplist.Endpoints[i].Equal(ep) {
54                         return false
55                 }
56         }
57         eplist.Endpoints = append(eplist.Endpoints, *ep)
58         return true
59 }
60
61 func (eplist *RmrEndpointList) DelEndpoint(ep *RmrEndpoint) bool {
62         for i := range eplist.Endpoints {
63                 if eplist.Endpoints[i].Equal(ep) {
64                         eplist.Endpoints[i] = eplist.Endpoints[len(eplist.Endpoints)-1]
65                         eplist.Endpoints[len(eplist.Endpoints)-1] = RmrEndpoint{"", 0}
66                         eplist.Endpoints = eplist.Endpoints[:len(eplist.Endpoints)-1]
67                         return true
68                 }
69         }
70         return false
71 }
72
73 func (eplist *RmrEndpointList) DelEndpoints(otheplist *RmrEndpointList) bool {
74         var retval bool = false
75         for i := range otheplist.Endpoints {
76                 if eplist.DelEndpoint(&otheplist.Endpoints[i]) {
77                         retval = true
78                 }
79         }
80         return retval
81 }
82
83 func (eplist *RmrEndpointList) HasEndpoint(ep *RmrEndpoint) bool {
84         for i := range eplist.Endpoints {
85                 if eplist.Endpoints[i].Equal(ep) {
86                         return true
87                 }
88         }
89         return false
90 }
91
92 func NewRmrEndpointList() *RmrEndpointList {
93         return &RmrEndpointList{}
94 }