Open Kilda Java Documentation
Link.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.topo;
17 
22 public class Link implements ITopoSlug {
23 
24  private final LinkEndpoint src;
25  private final LinkEndpoint dst;
26  private String slug;
27  private String shortSlug;
28 
29  public Link(LinkEndpoint src, LinkEndpoint dst) {
30  this.src = src;
31  this.dst = dst;
32  }
33 
34  public LinkEndpoint getSrc() {
35  return src;
36  }
37 
38  public LinkEndpoint getDst() {
39  return dst;
40  }
41 
42  @Override
43  public String getSlug() {
44  if (slug == null)
45  slug = TopoSlug.toString(this,false);
46  return slug;
47  }
48 
49  public String getShortSlug() {
50  if (shortSlug == null)
51  shortSlug = TopoSlug.toString(this,true);
52  return shortSlug;
53  }
54 
55  @Override
56  public boolean equals(Object o) {
57  if (this == o) return true;
58  if (!(o instanceof Link)) return false;
59 
60  Link link = (Link) o;
61 
62  if (src != null ? !src.equals(link.src) : link.src != null) return false;
63  return dst != null ? dst.equals(link.dst) : link.dst == null;
64  }
65 
66  @Override
67  public int hashCode() {
68  int result = src != null ? src.hashCode() : 0;
69  result = 31 * result + (dst != null ? dst.hashCode() : 0);
70  return result;
71  }
72 
73  public static void main(String[] args) {
74  LinkEndpoint ep1 = new LinkEndpoint(null,null, null);
75  LinkEndpoint ep2 = new LinkEndpoint(null,null, null);
76  Link link1 = new Link(ep1,ep2);
77  System.out.println("link1.getSlug() = " + link1.getSlug());
78  }
79 }
static final String toString(Switch aSwitch)
Definition: TopoSlug.java:34
list result
Definition: plan-d.py:72