Open Kilda Java Documentation
LinkEndpoint.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 
18 import java.beans.Transient;
19 
23 public class LinkEndpoint implements ITopoSlug {
24 
25  private final Switch topoSwitch;
26  private final Port switchPort;
27  private final PortQueue portQueue;
28  private transient String slug;
29 
30  private static final String NULL_ID = "0";
31 
32 
38  public LinkEndpoint(Switch topoSwitch, Port switchPort, PortQueue portQueue) {
39  if (topoSwitch == null) throw new IllegalArgumentException("Switch can't be null");
40  this.topoSwitch = topoSwitch;
41  this.switchPort = (switchPort != null) ? switchPort: new Port(this.topoSwitch,NULL_ID);
42  this.portQueue = (portQueue != null) ? portQueue: new PortQueue(this.switchPort,NULL_ID);
43  }
44 
45  public LinkEndpoint(PortQueue portQueue) {
46  // check for nulls all the way up
47  this( (portQueue == null) ?
48  null : (portQueue.getParent() == null) ?
49  null : portQueue.getParent().getParent(),
50  (portQueue == null) ? null : portQueue.getParent(),
51  portQueue);
52  }
53 
54 
55  public Switch getTopoSwitch() {
56  return topoSwitch;
57  }
58 
59  public Port getSwitchPort() {
60  return switchPort;
61  }
62 
64  return portQueue;
65  }
66 
67  public String getSlug() {
68  if (slug == null)
69  slug = TopoSlug.toString(this);
70  return slug;
71  }
72 
73  @Override
74  public boolean equals(Object o) {
75  if (this == o) return true;
76  if (!(o instanceof LinkEndpoint)) return false;
77 
78  LinkEndpoint that = (LinkEndpoint) o;
79 
80  if (topoSwitch != null ? !topoSwitch.equals(that.topoSwitch) : that.topoSwitch != null)
81  return false;
82  if (switchPort != null ? !switchPort.equals(that.switchPort) : that.switchPort != null)
83  return false;
84  return portQueue != null ? portQueue.equals(that.portQueue) : that.portQueue == null;
85  }
86 
87  @Override
88  public int hashCode() {
89  int result = topoSwitch != null ? topoSwitch.hashCode() : 0;
90  result = 31 * result + (switchPort != null ? switchPort.hashCode() : 0);
91  result = 31 * result + (portQueue != null ? portQueue.hashCode() : 0);
92  return result;
93  }
94 
95  public static void main(String[] args) {
96  }
97 
98 }
boolean equals(Object o)
Definition: Port.java:48
static final String toString(Switch aSwitch)
Definition: TopoSlug.java:34
boolean equals(Object o)
Definition: PortQueue.java:63
list result
Definition: plan-d.py:72
boolean equals(Object o)
Definition: Switch.java:52
Switch getParent()
Definition: Port.java:43