1 /*
2  *  Avis event router.
3  *
4  *  Copyright (C) 2008 Matthew Phillips <avis@mattp.name>
5  *
6  *  This program is free software: you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  version 3 as published by the Free Software Foundation.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  *  General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.avis.subscription.ast;
19 
20 import java.util.Collection;
21 
22 /**
23  * Base class for parent nodes that evaluate to boolean from boolean
24  * children.
25  *
26  * @author Matthew Phillips
27  */
28 public abstract class BoolParentNode
29   extends ParentNode
30 {
BoolParentNode()31   public BoolParentNode ()
32   {
33     // zip
34   }
35 
BoolParentNode(Node node1)36   public BoolParentNode (Node node1)
37   {
38     super (node1);
39   }
40 
BoolParentNode(Node node1, Node node2)41   public BoolParentNode (Node node1,
42                          Node node2)
43   {
44     super (node1, node2);
45   }
46 
BoolParentNode(Node... children)47   public BoolParentNode (Node... children)
48   {
49     super (children);
50   }
51 
BoolParentNode(Collection<? extends Node> children)52   public BoolParentNode (Collection<? extends Node> children)
53   {
54     super (children);
55   }
56 
57   @Override
presentation()58   public String presentation ()
59   {
60     return name ();
61   }
62 
63   @Override
evalType()64   public Class<?> evalType ()
65   {
66     return Boolean.class;
67   }
68 
69   @Override
validateChild(Node child)70   public String validateChild (Node child)
71   {
72     if (child.evalType () != Boolean.class)
73       return expr () + " requires boolean arguments (" + child.expr () + ")";
74     else
75       return null;
76   }
77 }
78