Debian Codegraph @

commons-rdf-simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java

raw
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.commons.rdf.simple;
19
20 import org.apache.commons.rdf.api.IRI;
21
22 import java.net.URI;
23
24 /**
25 * A simple implementation of IRI.
26 */
27 final class IRIImpl implements IRI, SimpleRDF.SimpleRDFTerm {
28
29 private final String iri;
30
31 public IRIImpl(final String iri) {
32 // should throw IllegalArgumentException on most illegal IRIs
33 URI.create(iri);
34 // NOTE: We don't keep the URI as it uses outdated RFC2396 and will get
35 // some IDNs wrong
36 this.iri = iri;
37 }
38
39 @Override
40 public String getIRIString() {
41 return iri;
42 }
43
44 @Override
45 public String ntriplesString() {
46 return "<" + getIRIString() + ">";
47 }
48
49 @Override
50 public String toString() {
51 return ntriplesString();
52 }
53
54 @Override
55 public boolean equals(final Object obj) {
56 if (this == obj) {
57 return true;
58 }
59 if (obj == null || !(obj instanceof IRI)) {
60 return false;
61 }
62 final IRI other = (IRI) obj;
63 return getIRIString().equals(other.getIRIString());
64 }
65
66 @Override
67 public int hashCode() {
68 return iri.hashCode();
69 }
70
71 }