001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: Delta.java,v 1.14 2008/01/02 12:10:19 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.compose;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.util.iterator.*;
011:
012: /**
013: Graph operation for wrapping a base graph and leaving it unchanged while recording
014: all the attempted updates for later access.
015: <p>
016: TODO review in the light of GraphWrapper
017: @author hedgehog
018: */
019:
020: public class Delta extends Dyadic implements Graph {
021: private Graph base;
022:
023: public Delta(Graph base) {
024: super (Factory.createGraphMem(), Factory.createGraphMem());
025: this .base = base;
026: }
027:
028: /**
029: Answer the graph of all triples added
030: */
031: public Graph getAdditions() {
032: return L;
033: }
034:
035: /**
036: Answer the graph of all triples removed
037: */
038: public Graph getDeletions() {
039: return R;
040: }
041:
042: /**
043: Add the triple to the graph, ie add it to the additions, remove it from the removals.
044: */
045: public void performAdd(Triple t) {
046: L.add(t);
047: R.delete(t);
048: }
049:
050: /**
051: Remove the triple, ie, remove it from the adds, add it to the removals.
052: */
053: public void performDelete(Triple t) {
054: L.delete(t);
055: R.add(t);
056: }
057:
058: /**
059: Find all the base triples matching tm, exclude the ones that are deleted, add the ones
060: that have been added.
061: */
062: public ExtendedIterator graphBaseFind(TripleMatch tm) {
063: return base.find(tm).filterDrop(ifIn(GraphUtil.findAll(R)))
064: .andThen(L.find(tm));
065: }
066:
067: public void close() {
068: super .close();
069: base.close();
070: }
071:
072: public int graphBaseSize() {
073: return base.size() + L.size() - R.size();
074: }
075: }
076:
077: /*
078: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
079: All rights reserved.
080:
081: Redistribution and use in source and binary forms, with or without
082: modification, are permitted provided that the following conditions
083: are met:
084:
085: 1. Redistributions of source code must retain the above copyright
086: notice, this list of conditions and the following disclaimer.
087:
088: 2. Redistributions in binary form must reproduce the above copyright
089: notice, this list of conditions and the following disclaimer in the
090: documentation and/or other materials provided with the distribution.
091:
092: 3. The name of the author may not be used to endorse or promote products
093: derived from this software without specific prior written permission.
094:
095: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
096: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
097: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
098: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
099: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
104: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105: */
|