summaryrefslogtreecommitdiffstats
path: root/sample-apps/src/main/java/org/onap/integration/actninterfacetools/sampleapp/mpiconverter/model/TsLinkKey.java
blob: b83b5f1df12f9d7cbdd17be0615a0f3689136987 (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
/*
 *   ============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 com.google.common.base.MoreObjects;

import java.util.Objects;

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

public final class TsLinkKey {


    private static final String DELIM = "-";

    private final LTPoint src = null;
    private final LTPoint dst = null;
    private final String id;

    /**
     * Creates a link identifier with source and destination LTPoint point.
     *
     * @param src source LTPoint point
     * @param dst destination LTPoint point
     */
    private TsLinkKey(LTPoint src, LTPoint dst) {
        this(src, dst, src + DELIM + dst);
    }

    /**
     * Creates a link identifier with source and destination LTPoint point.
     *
     * @param src source LTPoint point
     * @param dst destination LTPoint point
     */
    public TsLinkKey(LTPoint src, LTPoint dst, String id) {
        this.id = checkNotNull(id);
        //this.src = checkNotNull(src);
        //this.dst = checkNotNull(dst);
    }

    /**
     * Returns source connection point.
     *
     * @return source connection point
     */
    public LTPoint src() {
        return src;
    }

    /**
     * Returns destination connection point.
     *
     * @return destination connection point
     */
    public LTPoint dst() {
        return dst;
    }

    /**
     * Returns a string suitable to be used as an identifier.
     *
     * @return string as identifier
     */
    public String asId() {
        return src + DELIM + dst;
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.id);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof TsLinkKey) {
            final TsLinkKey other = (TsLinkKey) obj;
            return  Objects.equals(this.id, other.id) &&
                    Objects.equals(this.src, other.src) &&
                    Objects.equals(this.dst, other.dst);
        }
        return false;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(getClass())
                .add("src", src)
                .add("dst", dst)
                .toString();
    }

    /**
     * Creates a link identifier with source and destination connection point.
     *
     * @param src source connection point
     * @param dst destination connection point
     * @return a link identifier
     */
    public static TsLinkKey tsLinkKey(LTPoint src, LTPoint dst) {
        return new TsLinkKey(src, dst);
    }

    /**
     * Creates a link identifier for the specified link.
     *
     * @param link link descriptor
     * @return a link identifier
     */
    public static TsLinkKey tsLinkKey(Link link) {
        if (link.src() == null || link.dst() == null) {
            checkArgument(link.type() != Link.Type.REGULAR,
                    "TsLinkKey invalid; only ingress/egress link can have null src/dst");
        }
        return new TsLinkKey(link.src(), link.dst(), link.id() );
    }

}