01: /*
02: * LICENSE INFORMATION
03: * Copyright 2005-2007 by FZI (http://www.fzi.de).
04: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
05: * <OWNER> = Max Völkel
06: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
07: * <YEAR> = 2007
08: *
09: * Project information at http://semweb4j.org/rdf2go
10: */
11: package org.ontoware.rdf2go.model.node.impl;
12:
13: import org.ontoware.rdf2go.model.node.DatatypeLiteral;
14: import org.ontoware.rdf2go.model.node.LanguageTagLiteral;
15: import org.ontoware.rdf2go.model.node.Node;
16: import org.ontoware.rdf2go.model.node.PlainLiteral;
17:
18: public class PlainLiteralImpl extends LiteralImpl implements
19: PlainLiteral {
20:
21: private String value;
22:
23: public PlainLiteralImpl(String value) {
24: this .value = value;
25: }
26:
27: @Override
28: public String getValue() {
29: return this .value;
30: }
31:
32: @Override
33: public String toString() {
34: return this .value;
35: }
36:
37: public DatatypeLiteral asDatatypeLiteral()
38: throws ClassCastException {
39: throw new ClassCastException(
40: "Cannot call this on a plain literal");
41: }
42:
43: public LanguageTagLiteral asLanguageTagLiteral()
44: throws ClassCastException {
45: throw new ClassCastException(
46: "Cannot call this on a plain literal");
47: }
48:
49: @Override
50: public boolean equals(Object other) {
51: if (other instanceof PlainLiteral) {
52: return ((PlainLiteral) other).getValue().equals(this .value);
53: } else if (other instanceof String) {
54: return this .value.equals(other);
55: } else
56: return false;
57: }
58:
59: @Override
60: public int hashCode() {
61: return this .value.hashCode();
62: }
63:
64: public int compareTo(Node other) {
65: if (other instanceof PlainLiteral) {
66: return this .value.compareTo(((PlainLiteral) other)
67: .getValue());
68: }
69: //else sort by type
70: return NodeUtils.compareByType(this , other);
71: }
72:
73: public String toSPARQL() {
74: return "'''" + sparqlEncode(this .value) + "'''";
75: }
76:
77: }
|