blob: 1ee0a3674a8928d9d91c3b6806475491919e6c0e [file] [log] [blame]
CNlucius74fd4942015-07-20 14:28:04 +08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ovsdb.controller;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23/**
24 * The class representing a ovsdb bridge. This class is immutable.
25 */
26public final class OvsdbBridge {
27
28 private final OvsdbBridgeName bridgeName;
29 private final OvsdbDatapathId datapathId;
30
31 /**
32 * Constructor from a OvsdbBridgeName bridgeName and a OvsdbDatapathId
33 * datapathId.
34 *
35 * @param bridgeName the bridgeName to use
36 * @param datapathId the datapathId to use
37 */
38 public OvsdbBridge(OvsdbBridgeName bridgeName, OvsdbDatapathId datapathId) {
39 checkNotNull(bridgeName, "bridgeName is not null");
40 checkNotNull(datapathId, "datapathId is not null");
41 this.bridgeName = bridgeName;
42 this.datapathId = datapathId;
43 }
44
45 /**
46 * Gets the bridge name of the bridge.
47 *
48 * @return the bridge name of the bridge
49 */
50 public OvsdbBridgeName bridgeName() {
51 return bridgeName;
52 }
53
54 /**
55 * Gets the datapathId of the bridge.
56 *
57 * @return datapathId the datapathId to use
58 */
59 public OvsdbDatapathId datapathId() {
60 return datapathId;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(bridgeName, datapathId);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj instanceof OvsdbBridge) {
74 final OvsdbBridge otherOvsdbBridge = (OvsdbBridge) obj;
75 return Objects.equals(this.bridgeName, otherOvsdbBridge.bridgeName)
76 && Objects.equals(this.datapathId,
77 otherOvsdbBridge.datapathId);
78 }
79 return false;
80 }
81
82 @Override
83 public String toString() {
84 return toStringHelper(this).add("bridgeName", bridgeName.value())
85 .add("datapathId", datapathId.value()).toString();
86 }
87}