Skip to content

Method: toString()

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: * @author ledvima1
25: */
26: public class NamedResource implements Serializable {
27:
28: private static final long serialVersionUID = 5932515448919851871L;
29:
30: private final URI identifier;
31:
32: NamedResource(URI uri) {
33: this.identifier = Objects.requireNonNull(uri);
34: }
35:
36: /**
37: * Gets identifier of this resource. </p>
38: *
39: * @return URI
40: */
41: public URI getIdentifier() {
42: return identifier;
43: }
44:
45: @Override
46: public int hashCode() {
47: final int prime = 31;
48: int result = 1;
49: result = prime * result + identifier.hashCode();
50: return result;
51: }
52:
53: @Override
54: public boolean equals(Object obj) {
55: if (this == obj)
56: return true;
57: if (obj == null)
58: return false;
59: if (getClass() != obj.getClass())
60: return false;
61: NamedResource other = (NamedResource) obj;
62: if (!identifier.equals(other.identifier))
63: return false;
64: return true;
65: }
66:
67: @Override
68: public String toString() {
69: return identifier.toString();
70: }
71:
72: /**
73: * Creates new named resource from the specified URI.
74: *
75: * @param uri Resource identifier
76: * @return NamedResource instance
77: */
78: public static NamedResource create(URI uri) {
79: return new NamedResource(uri);
80: }
81:
82: /**
83: * Creates new named resource from the specified string identifier.
84: *
85: * @param iri Resource identifier
86: * @return NamedResource instance
87: */
88: public static NamedResource create(String iri) {
89: return new NamedResource(URI.create(iri));
90: }
91: }