blob: cdb69137f567abdd227b26d13c6b921df09f873a [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/*
2 * Copyright 2016 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.tetopology.management.api.node;
17
18import org.onosproject.tetopology.management.api.KeyId;
19
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22
23/**
24 * Representation of a node key or node reference.
25 */
26public class NetworkNodeKey {
27 private final KeyId networkId;
28 private final KeyId nodeId;
29
30 /**
31 * Creates an instance of NetworkNodeKey.
32 *
33 * @param networkId network identifier
34 * @param nodeId node identifier
35 */
36 public NetworkNodeKey(KeyId networkId, KeyId nodeId) {
37 this.networkId = networkId;
38 this.nodeId = nodeId;
39 }
40
41 /**
42 * Returns the network identifier.
43 *
44 * @return network identifier
45 */
46 public KeyId networkId() {
47 return networkId;
48 }
49
50 /**
51 * Returns the node identifier.
52 *
53 * @return node identifier
54 */
55 public KeyId nodeId() {
56 return nodeId;
57 }
58
59 @Override
60 public int hashCode() {
61 return Objects.hashCode(networkId, nodeId);
62 }
63
64 @Override
65 public boolean equals(Object object) {
66 if (this == object) {
67 return true;
68 }
69 if (object instanceof NetworkNodeKey) {
70 NetworkNodeKey that = (NetworkNodeKey) object;
71 return Objects.equal(this.networkId, that.networkId) &&
72 Objects.equal(this.nodeId, that.nodeId);
73 }
74 return false;
75 }
76
77 @Override
78 public String toString() {
79 return MoreObjects.toStringHelper(this)
80 .add("networkId", networkId)
81 .add("nodeId", nodeId)
82 .toString();
83 }
84
85}