KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > mem > SmallGraphMem


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: SmallGraphMem.java,v 1.8 2005/02/21 12:03:46 andy_seaborne Exp $
5 */

6 package com.hp.hpl.jena.mem;
7
8 import java.util.Set JavaDoc;
9
10 import com.hp.hpl.jena.graph.*;
11 import com.hp.hpl.jena.graph.impl.SimpleEventManager;
12 import com.hp.hpl.jena.shared.ReificationStyle;
13 import com.hp.hpl.jena.util.CollectionFactory;
14 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
15
16 /**
17      A SmallGraphMem is a memory-based Graph suitable only for Small models
18      (a few triples, perhaps a few tens of triples), because it does no indexing,
19      but it stores onlya single flat set of triples and so is memory-cheap.
20      
21     @author kers
22 */

23
24 public class SmallGraphMem extends GraphMemBase
25     {
26     protected Set JavaDoc triples = CollectionFactory.createHashedSet();
27     
28     public SmallGraphMem()
29         { this( ReificationStyle.Minimal ); }
30     
31     public SmallGraphMem( ReificationStyle style )
32         { super( style ); }
33     
34     public void performAdd( Triple t )
35         { if (!getReifier().handledAdd( t )) triples.add( t ); }
36     
37     public void performDelete( Triple t )
38         { if (!getReifier().handledRemove( t )) triples.remove( t ); }
39     
40     public int graphBaseSize()
41         { return triples.size(); }
42
43     /**
44         Answer true iff t matches some triple in the graph. If t is concrete, we
45         can use a simple membership test; otherwise we resort to the generic
46         method using find.
47     */

48     public boolean graphBaseContains( Triple t )
49         { return t.isConcrete() ? triples.contains( t ) : containsByFind( t ); }
50     
51     protected void destroy()
52         { triples = null; }
53     
54     public BulkUpdateHandler getBulkUpdateHandler()
55         {
56         if (bulkHandler == null) bulkHandler = new GraphMemBulkUpdateHandler( this )
57             {
58             protected void clearComponents()
59                 {
60                 SmallGraphMem g = (SmallGraphMem) graph;
61                 g.triples.clear();
62                 }
63             };
64         return bulkHandler;
65         }
66     
67     public ExtendedIterator graphBaseFind( TripleMatch m )
68         {
69         return
70             SimpleEventManager.notifyingRemove( this, triples.iterator() )
71             .filterKeep ( new TripleMatchFilter( m.asTriple() ) );
72         }
73     }
74
75 /*
76     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
77     All rights reserved.
78     
79     Redistribution and use in source and binary forms, with or without
80     modification, are permitted provided that the following conditions
81     are met:
82     
83     1. Redistributions of source code must retain the above copyright
84        notice, this list of conditions and the following disclaimer.
85     
86     2. Redistributions in binary form must reproduce the above copyright
87        notice, this list of conditions and the following disclaimer in the
88        documentation and/or other materials provided with the distribution.
89     
90     3. The name of the author may not be used to endorse or promote products
91        derived from this software without specific prior written permission.
92     
93     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
94     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
95     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
96     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
97     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
99     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103 */
Popular Tags