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