KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   (c) Copyright 2002, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: Union.java,v 1.10 2005/02/21 11:52:05 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.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     {
24     public Union( Graph L, Graph R )
25         { super( L, R ); }
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         To remove a triple, remove it from <i>both</i> operands.
35     */

36     public void performDelete( Triple t )
37         {
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         To find in the union, find in the components, concatenate the results, and omit
47         duplicates. That last is a performance penalty, but I see no way to remove it
48         unless we know the graphs do not overlap.
49     */

50     public ExtendedIterator graphBaseFind( final TripleMatch t )
51         {
52         Set seen = CollectionFactory.createHashedSet();
53         return recording( L.find( t ), seen ).andThen( rejecting( R.find( t ), seen ) );
54         // return L.find( t ) .andThen( rejecting( R.find( t ), L ) );
55
}
56     }
57
58 /*
59     (c) Copyright 2002, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
60     All rights reserved.
61
62     Redistribution and use in source and binary forms, with or without
63     modification, are permitted provided that the following conditions
64     are met:
65
66     1. Redistributions of source code must retain the above copyright
67        notice, this list of conditions and the following disclaimer.
68
69     2. Redistributions in binary form must reproduce the above copyright
70        notice, this list of conditions and the following disclaimer in the
71        documentation and/or other materials provided with the distribution.
72
73     3. The name of the author may not be used to endorse or promote products
74        derived from this software without specific prior written permission.
75
76     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
77     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
78     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
79     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
80     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
81     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
85     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86 */

87
Popular Tags