blob: 5c8b40020368943a937590909e534753a2b58f02 [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Aihua Guo1ce2dd12016-08-12 23:37:44 -04003 *
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 */
16
17package org.onosproject.tetopology.management.api;
18
19import java.net.URI;
20import java.util.Objects;
21
22/**
23 * Representation of an key identifier in URI.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040024 */
25public class KeyId {
26 /**
27 * Represents either no uri, or an unspecified uri.
28 */
29 public static final KeyId NONE = keyId("none:none");
30
31 private final URI uri;
32 private final String str;
33
34 // Public construction is prohibited
35 private KeyId(URI uri) {
36 this.uri = uri;
37 //this.str = uri.toString().toLowerCase();
38 this.str = uri.toString();
39 }
40
41
42 /**
43 * Default constructor for serialization of KeyId.
44 */
45 protected KeyId() {
46 this.uri = null;
47 this.str = null;
48 }
49
50 /**
51 * Returns the backing URI.
52 *
53 * @return backing URI
54 */
55 public URI uri() {
56 return uri;
57 }
58
59 @Override
60 public int hashCode() {
61 return str.hashCode();
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (obj instanceof KeyId) {
70 KeyId that = (KeyId) obj;
71 return this.getClass() == that.getClass() &&
72 Objects.equals(this.str, that.str);
73 }
74 return false;
75 }
76
77 @Override
78 public String toString() {
79 return str;
80 }
81
82 /**
83 * Creates a uri id using the supplied URI.
84 *
85 * @param uri URI
86 * @return UriId
87 */
88 public static KeyId keyId(URI uri) {
89 return new KeyId(uri);
90 }
91
92 /**
93 * Creates a uri id using the supplied URI string.
94 *
95 * @param string URI string
96 * @return UriId
97 */
98 public static KeyId keyId(String string) {
99 return keyId(URI.create(string));
100 }
101
102}