1 6 package com.hp.hpl.jena.mem; 7 8 import com.hp.hpl.jena.graph.*; 9 import com.hp.hpl.jena.graph.impl.TripleStore; 10 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 11 import com.hp.hpl.jena.util.iterator.WrappedIterator; 12 13 20 public class GraphTripleStore implements TripleStore 21 { 22 protected NodeToTriplesMap subjects = new NodeToTriplesMap() 23 { public Node getIndexNode( Triple t ) { return t.getSubject(); } }; 24 25 protected NodeToTriplesMap predicates = new NodeToTriplesMap() 26 { public Node getIndexNode( Triple t ) { return t.getPredicate(); } }; 27 28 protected NodeToTriplesMap objects = new NodeToTriplesMap() 29 { public Node getIndexNode( Triple t ) { return t.getObject(); } }; 30 31 protected Graph parent; 32 33 public GraphTripleStore( Graph parent ) 34 { this.parent = parent; } 35 36 39 public void close() 40 { subjects = predicates = objects = null; } 41 42 45 public void add( Triple t ) 46 { 47 if (subjects.add( t.getSubject(), t )) 48 { 49 predicates.add( t.getPredicate(), t ); 50 objects.add( t.getObject(), t ); 51 } 52 } 53 54 57 public void delete( Triple t ) 58 { 59 if (subjects.remove( t.getSubject(), t )) 60 { 61 predicates.remove( t.getPredicate(), t ); 62 objects.remove( t.getObject(), t ); 63 } 64 } 65 66 69 public int size() 70 { return subjects.size(); } 71 72 75 public boolean isEmpty() 76 { return subjects.isEmpty(); } 77 78 public ExtendedIterator listSubjects() 79 { return WrappedIterator.createNoRemove( subjects.domain() ); } 80 81 public ExtendedIterator listPredicates() 82 { return WrappedIterator.createNoRemove( predicates.domain() ); } 83 84 public ExtendedIterator listObjects() 85 { return WrappedIterator.createNoRemove( objects.domain() ); } 86 87 90 public boolean contains( Triple t ) 91 { return subjects.contains( t ); } 92 93 110 public ExtendedIterator find( TripleMatch tm ) 111 { 112 Triple t = tm.asTriple(); 113 Node pm = t.getPredicate(); 114 Node om = t.getObject(); 115 Node sm = t.getSubject(); 116 if (sm.isConcrete()) 117 return new StoreTripleIterator( parent, subjects.iterator( sm , t ), predicates, objects ); 118 else if (om.isConcrete() && !om.isLiteral()) 119 return new StoreTripleIterator( parent, objects.iterator( om, t ), subjects, predicates ); 120 else if (pm.isConcrete()) 121 return new StoreTripleIterator( parent, predicates.iterator( pm, t ), subjects, objects ); 122 else 123 return new StoreTripleIterator( parent, subjects.iterator( t ), predicates, objects ); 124 } 125 126 129 public void clear() 130 { 131 subjects.clear(); 132 predicates.clear(); 133 objects.clear(); 134 } 135 136 } 137 138 | Popular Tags |