01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.model.impl;
07:
08: import org.openrdf.model.BNode;
09:
10: /**
11: * An implementation of the {@link BNode} interface.
12: *
13: * @author Arjohn Kampman
14: */
15: public class BNodeImpl implements BNode {
16:
17: private static final long serialVersionUID = 5273570771022125970L;
18:
19: /*-----------*
20: * Variables *
21: *-----------*/
22:
23: /**
24: * The blank node's identifier.
25: */
26: private final String id;
27:
28: /*--------------*
29: * Constructors *
30: *--------------*/
31:
32: /**
33: * Creates a new blank node with the supplied identifier.
34: *
35: * @param id
36: * The identifier for this blank node, must not be <tt>null</tt>.
37: */
38: public BNodeImpl(String id) {
39: assert id != null;
40:
41: this .id = id;
42: }
43:
44: /*---------*
45: * Methods *
46: *---------*/
47:
48: public String getID() {
49: return id;
50: }
51:
52: public String stringValue() {
53: return id;
54: }
55:
56: // Overrides Object.equals(Object), implements BNode.equals(Object)
57: @Override
58: public boolean equals(Object o) {
59: if (this == o) {
60: return true;
61: }
62:
63: if (o instanceof BNode) {
64: BNode otherNode = (BNode) o;
65: return this .getID().equals(otherNode.getID());
66: }
67:
68: return false;
69: }
70:
71: // Overrides Object.hashCode(), implements BNode.hashCode()
72: @Override
73: public int hashCode() {
74: return id.hashCode();
75: }
76:
77: // Overrides Object.toString()
78: @Override
79: public String toString() {
80: return "_:" + id;
81: }
82: }
|