summaryrefslogtreecommitdiffstats
path: root/sample-apps/src/main/java/org/onap/integration/actninterfacetools/sampleapp/mpiconverter/model/TsLink.java
blob: 8ae82094b4368e63ae6882ef32a2a1733d8c1c7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 *   ============LICENSE_START=======================================================
 *   Actn Interface Tools
 *   ================================================================================
 *   Copyright (C) 2023 Huawei Canada Limited.
 *   ================================================================================
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *   ============LICENSE_END=========================================================
 */
package org.onap.integration.actninterfacetools.sampleapp.mpiconverter.model;

import org.onap.integration.actninterfacetools.actnclient.api.CustomerOtnTunnel;

import java.util.List;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;

public class TsLink extends CustomerOtnTunnel implements Link {

    private final String id;
    private final LTPoint src;
    private final LTPoint dst;
    private final State state;
    private final Type type;
    private String transportSliceId;
    private List<Integer> numberOfOdu;

    protected TsLink(LTPoint src, LTPoint dst, State state){
        this("Default", src, dst, state);
    }

    protected TsLink(String id, LTPoint src, LTPoint dst, State state){
        this(id, src, dst, state, Type.REGULAR);
    }

    public TsLink(String id, LTPoint src, LTPoint dst, State state, Type type){
        this.id = id;
        this.src = src;
        this.dst = dst;
        this.state = state;
        this.type = type;
    }

    public TsLink(LTPoint srcLtPoint, LTPoint dstLtPoint) {
        this.id = "defaultId";
        this.src = srcLtPoint;
        this.dst = dstLtPoint;
        this.state = State.ACTIVE;
        this.type = Type.REGULAR;
    }

    public String sliceId() {
        return transportSliceId;
    }

    public void sliceId(String id) {
        this.transportSliceId = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o instanceof TsLink){
            final TsLink other = (TsLink) o;
            return  Objects.equals(this.id, other.id) &&
                    Objects.equals(this.type, other.type) &&
                    Objects.equals(this.state, other.state);
        }
        return false;
    }

    public String id() {
        return this.id;
    }

    @Override
    public String toString(){
        return (src + "==>" + dst);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, type, src, dst, state);
    }

    @Override
    public LTPoint src() {
        return this.src;
    }

    @Override
    public LTPoint dst() {
        return this.dst;
    }

    @Override
    public State state() {
        return state;
    }

    @Override
    public Type type() {
        return type;
    }

    //===Builder========
    public static Builder builder() { return new Builder(); }

    public List<Integer> getNumberOfOdu() {
        return numberOfOdu;
    }

    public void setNumberOfOdu(List<Integer> numberOfOdu) {
        this.numberOfOdu = numberOfOdu;
    }

    public static class Builder {

        private String id;
        private LTPoint src;
        private LTPoint dst;
        private State state = State.ACTIVE;
        private Type type = Type.REGULAR;


        protected Builder() {

        }

        public Builder id(String id) {
            this.id = id;
            return this;
        }
        public Builder src(LTPoint src) {
            this.src = src;
            return this;
        }
        public Builder dst(LTPoint dst) {
            this.dst = dst;
            return this;
        }
        public Builder state(State state) {
            this.state = state;
            return this;
        }
        public Builder type(Type type) {
            this.type = type;
            return this;
        }
        public TsLink build(){
            if (type == Type.INGRESS){
                checkNotNull(dst, "Destination connect point cannot be null");
            } else if (type == Type.EGRESS) {
                checkNotNull(src, "Source connect point cannot be null");
            } else if (type == Type.REGULAR){
                checkNotNull(dst, "Destination connect point cannot be null");
                checkNotNull(src, "Source connect point cannot be null");
            }
            checkNotNull(state, "State cannot be null");
            return new TsLink(id, src, dst, state, type);
        }
    }



}