KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > compose > Delta


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: Delta.java,v 1.9 2005/02/21 11:52:03 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.graph.compose;
8
9 import com.hp.hpl.jena.graph.*;
10 import com.hp.hpl.jena.util.iterator.*;
11
12 import com.hp.hpl.jena.mem.*;
13
14
15 /**
16     Graph operation for wrapping a base graph and leaving it unchanged while recording
17     all the attempted updates for later access.
18 <p>
19     TODO review in the light of GraphWrapper
20     @author hedgehog
21 */

22
23 public class Delta extends Dyadic implements Graph
24     {
25     private Graph base;
26     
27     public Delta( Graph base )
28         {
29         super( new GraphMem(), new GraphMem() );
30         this.base = base;
31         }
32         
33     /**
34         Answer the graph of all triples added
35     */

36     public Graph getAdditions()
37         { return L; }
38         
39     /**
40         Answer the graph of all triples removed
41     */

42     public Graph getDeletions()
43         { return R; }
44         
45     /**
46         Add the triple to the graph, ie add it to the additions, remove it from the removals.
47     */

48     public void performAdd( Triple t )
49         {
50         L.add( t );
51         R.delete( t );
52         }
53
54     /**
55         Remove the triple, ie, remove it from the adds, add it to the removals.
56     */

57     public void performDelete( Triple t )
58         {
59         L.delete( t );
60         R.add( t );
61         }
62          
63     /**
64         Find all the base triples matching tm, exclude the ones that are deleted, add the ones
65         that have been added.
66     */

67     public ExtendedIterator graphBaseFind( TripleMatch tm )
68         {
69         return base.find( tm ) .filterDrop( ifIn( GraphUtil.findAll( R ) ) ) .andThen( L.find( tm ) );
70         }
71
72     public void close()
73         {
74         super.close();
75         base.close();
76         }
77
78     public int graphBaseSize()
79         { return base.size() + L.size() - R.size(); }
80     }
81
82 /*
83     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
84     All rights reserved.
85
86     Redistribution and use in source and binary forms, with or without
87     modification, are permitted provided that the following conditions
88     are met:
89
90     1. Redistributions of source code must retain the above copyright
91        notice, this list of conditions and the following disclaimer.
92
93     2. Redistributions in binary form must reproduce the above copyright
94        notice, this list of conditions and the following disclaimer in the
95        documentation and/or other materials provided with the distribution.
96
97     3. The name of the author may not be used to endorse or promote products
98        derived from this software without specific prior written permission.
99
100     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
101     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
102     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
103     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
104     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
105     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
106     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
107     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
109     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110 */

111
Popular Tags