Open Kilda Java Documentation
Switch.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 com.fasterxml.jackson.annotation.JsonIgnore;
19 
20 import java.util.Map;
21 import java.util.concurrent.ConcurrentHashMap;
22 
23 public class Switch implements ITopoSlug {
24 
26  @JsonIgnore
27  private final Map<String, Port> ports = new ConcurrentHashMap<String, Port>(48);
28  private final String id;
29  @JsonIgnore
30  private String slug;
31 
32  public Switch(String id) {
33  this.id = id;
34  }
35 
36  public String getId() {
37  return id;
38  }
39 
40  public Map<String, Port> getPorts() {
41  return ports;
42  }
43 
44  @Override
45  public String getSlug() {
46  if (slug == null)
47  slug = TopoSlug.toString(this);
48  return slug;
49  }
50 
51  @Override
52  public boolean equals(Object o) {
53  if (this == o) return true;
54  if (!(o instanceof Switch)) return false;
55 
56  Switch aSwitch = (Switch) o;
57 
58  if (!ports.equals(aSwitch.ports)) return false;
59  return id != null ? id.equals(aSwitch.id) : aSwitch.id == null;
60  }
61 
62  @Override
63  public int hashCode() {
64  int result = ports.hashCode();
65  result = 31 * result + (id != null ? id.hashCode() : 0);
66  return result;
67  }
68 }
static final String toString(Switch aSwitch)
Definition: TopoSlug.java:34
list result
Definition: plan-d.py:72
Map< String, Port > getPorts()
Definition: Switch.java:40
boolean equals(Object o)
Definition: Switch.java:52