capture
[rrq/gorite.git] / com / intendico / data / Lost.java
1 /*********************************************************************
2 Copyright 2012, Ralph Ronnquist.
3
4 This file is part of GORITE.
5
6 GORITE is free software: you can redistribute it and/or modify it
7 under the terms of the Lesser GNU General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GORITE is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14 License for more details.
15
16 You should have received a copy of the Lesser GNU General Public
17 License along with GORITE.  If not, see <http://www.gnu.org/licenses/>.
18 **********************************************************************/
19
20 package com.intendico.data;
21
22 import java.util.Observer;
23 import java.util.Vector;
24
25 /**
26  * The Lost class is a {@link Snapshot} that enumerates the lost
27  * tuples rather than the added tuples, and it also treats adding and
28  * removing like {@link Not}.
29  */
30 public class Lost extends Snapshot {
31
32     /**
33      * Constructor;
34      */
35     public Lost(Query q) {
36         super( q );
37     }
38
39     /**
40      * Alternative constructor with synchronization object.
41      */
42     public Lost(Object s,Query q) {
43         super( s, q );
44     }
45
46     /**
47      * The {@link Query#copy} method implemented by creating a new
48      * Lost with a copy of the monitored {@link #query}, and sharing
49      * any {@link #sync} object.
50      */
51     public Query copy(Vector/*<Ref>*/ newrefs) throws Exception {
52         return new Lost( sync, query.copy( newrefs ) );
53     }
54
55     /**
56      * The {@link Query#reset} method implemented by forwarding to the
57      * wrapped query.
58      */
59     public void reset() throws Exception {
60         super.reset();
61         bindings = lost.iterator();
62     }
63
64     /**
65      * Implements {@link Query#addable} by calling {@link
66      * Query#removable} on the wrapped query.
67      */
68     public boolean addable() {
69         return query.removable();
70     }
71
72     /**
73      * Implements {@link Query#add} by calling {@link Query#remove} on
74      * the wrapped query.
75      */
76     public boolean add() {
77         return query.remove();
78     }
79
80     /**
81      * Implements {@link Query#removable} by calling {@link
82      * Query#addable} on the wrapped query.
83      */
84     public boolean removable() {
85         return query.addable();
86     }
87
88     /**
89      * Implements {@link Query#remove} by calling {@link Query#add} on
90      * the wrapped query.
91      */
92     public boolean remove() {
93         return query.add();
94     }
95
96     /**
97      * Returns the textual representation of the wrapped query, within
98      * parentheses.
99      */
100     public String toString() {
101         return "Lost(" + query + ")";
102     }
103 }