001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.memory.model;
007:
008: import org.openrdf.model.impl.BNodeImpl;
009:
010: /**
011: * A MemoryStore-specific extension of BNodeImpl giving it node properties.
012: */
013: public class MemBNode extends BNodeImpl implements MemResource {
014:
015: /*-----------*
016: * Variables *
017: *-----------*/
018:
019: /**
020: *
021: */
022: private static final long serialVersionUID = -887382892580321647L;
023:
024: /**
025: * The object that created this MemBNode.
026: */
027: transient private Object creator;
028:
029: /**
030: * The list of statements for which this MemBNode is the subject.
031: */
032: transient private MemStatementList subjectStatements;
033:
034: /**
035: * The list of statements for which this MemBNode is the object.
036: */
037: transient private MemStatementList objectStatements;
038:
039: /**
040: * The list of statements for which this MemBNode represents the context.
041: */
042: transient private MemStatementList contextStatements;
043:
044: /*--------------*
045: * Constructors *
046: *--------------*/
047:
048: /**
049: * Creates a new MemBNode for a bnode ID.
050: *
051: * @param creator The object that is creating this MemBNode.
052: * @param id bnode ID.
053: */
054: public MemBNode(Object creator, String id) {
055: super (id);
056: this .creator = creator;
057: }
058:
059: /*---------*
060: * Methods *
061: *---------*/
062:
063: // Implements MemValue.getCreator()
064: public Object getCreator() {
065: return creator;
066: }
067:
068: // Implements MemResource.getSubjectStatementList()
069: public MemStatementList getSubjectStatementList() {
070: if (subjectStatements == null) {
071: return EMPTY_LIST;
072: } else {
073: return subjectStatements;
074: }
075: }
076:
077: // Implements MemResource.getSubjectStatementCount()
078: public int getSubjectStatementCount() {
079: if (subjectStatements == null) {
080: return 0;
081: } else {
082: return subjectStatements.size();
083: }
084: }
085:
086: // Implements MemResource.addSubjectStatement(MemStatement)
087: public void addSubjectStatement(MemStatement st) {
088: if (subjectStatements == null) {
089: subjectStatements = new MemStatementList(4);
090: }
091:
092: subjectStatements.add(st);
093: }
094:
095: // Implements MemResource.removeSubjectStatement(MemStatement)
096: public void removeSubjectStatement(MemStatement st) {
097: subjectStatements.remove(st);
098:
099: if (subjectStatements.isEmpty()) {
100: subjectStatements = null;
101: }
102: }
103:
104: // Implements MemValue.getObjectStatementList()
105: public MemStatementList getObjectStatementList() {
106: if (objectStatements == null) {
107: return EMPTY_LIST;
108: } else {
109: return objectStatements;
110: }
111: }
112:
113: // Implements MemValue.getObjectStatementCount()
114: public int getObjectStatementCount() {
115: if (objectStatements == null) {
116: return 0;
117: } else {
118: return objectStatements.size();
119: }
120: }
121:
122: // Implements MemValue.addObjectStatement(MemStatement)
123: public void addObjectStatement(MemStatement st) {
124: if (objectStatements == null) {
125: objectStatements = new MemStatementList(4);
126: }
127:
128: objectStatements.add(st);
129: }
130:
131: // Implements MemValue.removeObjectStatement(MemStatement)
132: public void removeObjectStatement(MemStatement st) {
133: objectStatements.remove(st);
134:
135: if (objectStatements.isEmpty()) {
136: objectStatements = null;
137: }
138: }
139:
140: // Implements MemResource.getContextStatementList()
141: public MemStatementList getContextStatementList() {
142: if (contextStatements == null) {
143: return EMPTY_LIST;
144: } else {
145: return contextStatements;
146: }
147: }
148:
149: // Implements MemResource.getContextStatementCount()
150: public int getContextStatementCount() {
151: if (contextStatements == null) {
152: return 0;
153: } else {
154: return contextStatements.size();
155: }
156: }
157:
158: // Implements MemResource.addContextStatement(MemStatement)
159: public void addContextStatement(MemStatement st) {
160: if (contextStatements == null) {
161: contextStatements = new MemStatementList(4);
162: }
163:
164: contextStatements.add(st);
165: }
166:
167: // Implements MemResource.removeContextStatement(MemStatement)
168: public void removeContextStatement(MemStatement st) {
169: contextStatements.remove(st);
170:
171: if (contextStatements.isEmpty()) {
172: contextStatements = null;
173: }
174: }
175: }
|