Skip to contentPackage: NamedResource
NamedResource
Coverage
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.model;
16:
17: import java.io.Serializable;
18: import java.net.URI;
19: import java.util.Objects;
20:
21: /**
22: * Represents named resources, i. e. resources identified by an URI.
23: */
24: public class NamedResource implements Serializable {
25:
26: private static final long serialVersionUID = 5932515448919851871L;
27:
28: private final URI identifier;
29:
30: NamedResource(URI uri) {
31: this.identifier = Objects.requireNonNull(uri);
32: }
33:
34: /**
35: * Gets identifier of this resource.
36: *
37: * @return URI
38: */
39: public URI getIdentifier() {
40: return identifier;
41: }
42:
43: @Override
44: public int hashCode() {
45: final int prime = 31;
46: int result = 1;
47: result = prime * result + identifier.hashCode();
48: return result;
49: }
50:
51: @Override
52: public boolean equals(Object obj) {
53:• if (this == obj)
54: return true;
55:• if (obj == null)
56: return false;
57:• if (getClass() != obj.getClass())
58: return false;
59: NamedResource other = (NamedResource) obj;
60: return identifier.equals(other.identifier);
61: }
62:
63: @Override
64: public String toString() {
65: return identifier.toString();
66: }
67:
68: /**
69: * Creates new named resource from the specified URI.
70: *
71: * @param uri Resource identifier
72: * @return NamedResource instance
73: */
74: public static NamedResource create(URI uri) {
75: return new NamedResource(uri);
76: }
77:
78: /**
79: * Creates new named resource from the specified string identifier.
80: *
81: * @param iri Resource identifier
82: * @return NamedResource instance
83: */
84: public static NamedResource create(String iri) {
85: return new NamedResource(URI.create(iri));
86: }
87: }