Open Kilda Java Documentation
Port.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.util.ArrayList;
19 import java.util.Map;
20 import java.util.concurrent.ConcurrentHashMap;
21 
22 public class Port implements ITopoSlug {
23 
25  private final Map<String, PortQueue> portQueues = new ConcurrentHashMap<String, PortQueue>(10);
26  private final String id;
27  private final Switch parent;
28  private String slug;
29 
30  public Port(Switch parent, String id) {
31  this.id = id;
32  this.parent = parent;
33  }
34 
35  public Map<String, PortQueue> getPortQueues() {
36  return portQueues;
37  }
38 
39  public String getId() {
40  return id;
41  }
42 
43  public Switch getParent() {
44  return parent;
45  }
46 
47  @Override
48  public boolean equals(Object o) {
49  if (this == o) return true;
50  if (o == null || getClass() != o.getClass()) return false;
51 
52  Port port = (Port) o;
53 
54  // TODO: does portQueues.equals work if the objects are equivalent (ie not same obj)
55  if (portQueues != null ? !portQueues.equals(port.portQueues) : port.portQueues != null)
56  return false;
57  if (id != null ? !id.equals(port.id) : port.id != null) return false;
58  return parent != null ? parent.equals(port.parent) : port.parent == null;
59  }
60 
61  @Override
62  public int hashCode() {
63  int result = portQueues != null ? portQueues.hashCode() : 0;
64  result = 31 * result + (id != null ? id.hashCode() : 0);
65  result = 31 * result + (parent != null ? parent.hashCode() : 0);
66  return result;
67  }
68 
69  @Override
70  public String getSlug() {
71  if (slug == null)
72  slug = TopoSlug.toString(this);
73  return slug;
74  }
75 }
Port(Switch parent, String id)
Definition: Port.java:30
boolean equals(Object o)
Definition: Port.java:48
static final String toString(Switch aSwitch)
Definition: TopoSlug.java:34
list result
Definition: plan-d.py:72
Map< String, PortQueue > getPortQueues()
Definition: Port.java:35
boolean equals(Object o)
Definition: Switch.java:52
Switch getParent()
Definition: Port.java:43