01: /*______________________________________________________________________________
02: *
03: * Macker http://innig.net/macker/
04: *
05: * Copyright 2002 Paul Cantrell
06: *
07: * This program is free software; you can redistribute it and/or modify it under
08: * the terms of the GNU General Public License version 2, as published by the
09: * Free Software Foundation. See the file LICENSE.html for more information.
10: *
11: * This program is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
13: * FOR A PARTICULAR PURPOSE. See the license for more details.
14: *
15: * You should have received a copy of the GNU General Public License along with
16: * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
17: * Place, Suite 330 / Boston, MA 02111-1307 / USA.
18: *______________________________________________________________________________
19: */
20:
21: package net.innig.macker.util;
22:
23: import net.innig.macker.rule.RulesException;
24:
25: public class IncludeExcludeLogic {
26: public static boolean apply(IncludeExcludeNode node)
27: throws RulesException {
28: return applyNext(node, node.isInclude() ? false // include starts with all excluded, and
29: : true); // exclude starts with all included
30: }
31:
32: private static boolean applyNext(IncludeExcludeNode node,
33: boolean prevMatches) throws RulesException {
34: IncludeExcludeNode child = node.getChild(), next = node
35: .getNext();
36: boolean curMatches = node.matches();
37: boolean matchesSoFar = node.isInclude() ? prevMatches
38: || (curMatches && (child == null || apply(child)))
39: : prevMatches
40: && (!curMatches || (child != null && apply(child)));
41: return (next == null) ? matchesSoFar : applyNext(next,
42: matchesSoFar);
43: }
44: }
|