01: /*
02: * (c) Copyright 2000, 2001, 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: * [See end of file]
04: * $Id: Filter.java,v 1.10 2008/01/02 12:07:35 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.util.iterator;
08:
09: import java.util.Iterator;
10:
11: /**
12: boolean functions wrapped to be used in filtering iterators.
13:
14: @author jjc, kers
15: */
16: public abstract class Filter {
17: /**
18: Answer true iff the object <code>o</code> is acceptable. This method
19: may also throw an exception if the argument is of a wrong type; it
20: is not required to return <code>false</code> in such a case.
21: */
22: public abstract boolean accept(Object o);
23:
24: public ExtendedIterator filterKeep(Iterator it) {
25: return new FilterKeepIterator(this , it);
26: }
27:
28: public Filter and(final Filter other) {
29: return other == any ? this : new Filter() {
30: public boolean accept(Object x) {
31: return Filter.this .accept(x) && other.accept(x);
32: }
33: };
34: }
35:
36: /**
37: A Filter that accepts everything it's offered.
38: */
39: public static final Filter any = new Filter() {
40: public final boolean accept(Object o) {
41: return true;
42: }
43:
44: public Filter and(Filter other) {
45: return other;
46: }
47:
48: public ExtendedIterator filterKeep(Iterator it) {
49: return WrappedIterator.create(it);
50: }
51: };
52:
53: }
54:
55: /*
56: * (c) Copyright 2000, 2001, 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
57: * All rights reserved.
58: *
59: * Redistribution and use in source and binary forms, with or without
60: * modification, are permitted provided that the following conditions
61: * are met:
62: * 1. Redistributions of source code must retain the above copyright
63: * notice, this list of conditions and the following disclaimer.
64: * 2. Redistributions in binary form must reproduce the above copyright
65: * notice, this list of conditions and the following disclaimer in the
66: * documentation and/or other materials provided with the distribution.
67: * 3. The name of the author may not be used to endorse or promote products
68: * derived from this software without specific prior written permission.
69:
70: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
71: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
72: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
73: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
74: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
75: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
76: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
77: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
79: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80: *
81: * $Id: Filter.java,v 1.10 2008/01/02 12:07:35 andy_seaborne Exp $
82: *
83: */
|