01: /*
02: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: Union.java,v 1.13 2008/01/02 12:10:20 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.graph.compose;
08:
09: import com.hp.hpl.jena.graph.*;
10: import com.hp.hpl.jena.util.CollectionFactory;
11: import com.hp.hpl.jena.util.iterator.*;
12:
13: import java.util.*;
14:
15: /**
16: A class representing the dynamic union of two graphs. Addition only affects the left
17: operand, deletion affects both.
18: @see MultiUnion
19: @author hedgehog
20: */
21:
22: public class Union extends Dyadic implements Graph {
23: public Union(Graph L, Graph R) {
24: super (L, R);
25: }
26:
27: /**
28: To add a triple to the union, add it to the left operand; this is asymmetric.
29: */
30: public void performAdd(Triple t) {
31: L.add(t);
32: }
33:
34: /**
35: To remove a triple, remove it from <i>both</i> operands.
36: */
37: public void performDelete(Triple t) {
38: L.delete(t);
39: R.delete(t);
40: }
41:
42: public boolean graphBaseContains(Triple t) {
43: return L.contains(t) || R.contains(t);
44: }
45:
46: /**
47: To find in the union, find in the components, concatenate the results, and omit
48: duplicates. That last is a performance penalty, but I see no way to remove it
49: unless we know the graphs do not overlap.
50: */
51: public ExtendedIterator graphBaseFind(final TripleMatch t) {
52: Set seen = CollectionFactory.createHashedSet();
53: return recording(L.find(t), seen).andThen(
54: rejecting(R.find(t), seen));
55: // return L.find( t ) .andThen( rejecting( R.find( t ), L ) );
56: }
57: }
58:
59: /*
60: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: All rights reserved.
62:
63: Redistribution and use in source and binary forms, with or without
64: modification, are permitted provided that the following conditions
65: are met:
66:
67: 1. Redistributions of source code must retain the above copyright
68: notice, this list of conditions and the following disclaimer.
69:
70: 2. Redistributions in binary form must reproduce the above copyright
71: notice, this list of conditions and the following disclaimer in the
72: documentation and/or other materials provided with the distribution.
73:
74: 3. The name of the author may not be used to endorse or promote products
75: derived from this software without specific prior written permission.
76:
77: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
78: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
79: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
81: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
82: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
86: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87: */
|