001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: SmallGraphMem.java,v 1.15 2008/01/02 12:09:51 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.mem;
007:
008: import java.util.Set;
009:
010: import com.hp.hpl.jena.graph.*;
011: import com.hp.hpl.jena.graph.impl.*;
012: import com.hp.hpl.jena.shared.ReificationStyle;
013: import com.hp.hpl.jena.util.CollectionFactory;
014: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
015:
016: /**
017: A SmallGraphMem is a memory-based Graph suitable only for Small models
018: (a few triples, perhaps a few tens of triples), because it does no indexing,
019: but it stores onlya single flat set of triples and so is memory-cheap.
020:
021: @author kers
022: */
023:
024: public class SmallGraphMem extends GraphMemBase {
025: protected Set triples = CollectionFactory.createHashedSet();
026:
027: public SmallGraphMem() {
028: this (ReificationStyle.Minimal);
029: }
030:
031: public SmallGraphMem(ReificationStyle style) {
032: super (style);
033: }
034:
035: /**
036: SmallGraphMem's don't use TripleStore's at present.
037: */
038: protected TripleStore createTripleStore() {
039: return null;
040: }
041:
042: public void performAdd(Triple t) {
043: if (!getReifier().handledAdd(t))
044: triples.add(t);
045: }
046:
047: public void performDelete(Triple t) {
048: if (!getReifier().handledRemove(t))
049: triples.remove(t);
050: }
051:
052: public int graphBaseSize() {
053: return triples.size();
054: }
055:
056: /**
057: Answer true iff t matches some triple in the graph. If t is concrete, we
058: can use a simple membership test; otherwise we resort to the generic
059: method using find.
060: */
061: public boolean graphBaseContains(Triple t) {
062: return isSafeForEquality(t) ? triples.contains(t)
063: : containsByFind(t);
064: }
065:
066: protected void destroy() {
067: triples = null;
068: }
069:
070: public void clear() {
071: triples.clear();
072: ((SimpleReifier) getReifier()).clear();
073: }
074:
075: public BulkUpdateHandler getBulkUpdateHandler() {
076: if (bulkHandler == null)
077: bulkHandler = new GraphMemBulkUpdateHandler(this );
078: return bulkHandler;
079: }
080:
081: public ExtendedIterator graphBaseFind(TripleMatch m) {
082: return SimpleEventManager.notifyingRemove(this ,
083: triples.iterator()).filterKeep(
084: new TripleMatchFilter(m.asTriple()));
085: }
086: }
087:
088: /*
089: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
090: All rights reserved.
091:
092: Redistribution and use in source and binary forms, with or without
093: modification, are permitted provided that the following conditions
094: are met:
095:
096: 1. Redistributions of source code must retain the above copyright
097: notice, this list of conditions and the following disclaimer.
098:
099: 2. Redistributions in binary form must reproduce the above copyright
100: notice, this list of conditions and the following disclaimer in the
101: documentation and/or other materials provided with the distribution.
102:
103: 3. The name of the author may not be used to endorse or promote products
104: derived from this software without specific prior written permission.
105:
106: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
107: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
108: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
109: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
110: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
111: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
112: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
113: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
115: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116: */
|