blob: 27123287f207cd93225040a8da2c9172d872dd68 [file] [log] [blame]
Thomas Vachuska7b438af2015-07-07 09:52:07 -07001/*
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.incubator.net.virtual;
17
18import com.google.common.annotations.Beta;
19
20import java.util.Objects;
21
22/**
23 * Representation of network identity.
24 */
25@Beta
26public final class NetworkId {
27
28 /**
29 * Represents no network, or an unspecified network.
30 */
31 public static final NetworkId NONE = networkId(-1L);
32
33 /**
34 * Represents the underlying physical network.
35 */
36 public static final NetworkId PHYSICAL = networkId(0L);
37
38
39 private final long id;
40
41 // Public construction is prohibited
42 private NetworkId(long id) {
43 this.id = id;
44 }
45
46
47 // Default constructor for serialization
48 protected NetworkId() {
49 this.id = -1;
50 }
51
52 /**
53 * Creates a network id using the supplied backing id.
54 *
55 * @param id network id
56 * @return network identifier
57 */
58 public static NetworkId networkId(long id) {
59 return new NetworkId(id);
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(id);
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj instanceof NetworkId) {
73 final NetworkId that = (NetworkId) obj;
74 return this.getClass() == that.getClass() && this.id == that.id;
75 }
76 return false;
77 }
78
79 @Override
80 public String toString() {
81 return Long.toString(id);
82 }
83
84}