001// Copyright 2004, 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.hivemind.conditional; 016 017import org.apache.hivemind.util.Defense; 018 019/** 020 * Implementation of {@link org.apache.hivemind.conditional.Node}. 021 * 022 * @author Howard M. Lewis Ship 023 * @since 1.1 024 */ 025public class NodeImpl implements Node 026{ 027 private Node _left; 028 029 private Node _right; 030 031 private Evaluator _evaluator; 032 033 public NodeImpl(Node left, Node right, Evaluator evaluator) 034 { 035 Defense.notNull(evaluator, "evaluator"); 036 037 _left = left; 038 _right = right; 039 _evaluator = evaluator; 040 } 041 042 /** 043 * Alternate constructor used for terminal nodes. 044 */ 045 046 public NodeImpl(Evaluator evaluator) 047 { 048 this(null, null, evaluator); 049 } 050 051 public Node getLeft() 052 { 053 return _left; 054 } 055 056 public Node getRight() 057 { 058 return _right; 059 } 060 061 // For testing 062 063 Evaluator getEvaluator() 064 { 065 return _evaluator; 066 } 067 068 public boolean evaluate(EvaluationContext context) 069 { 070 return _evaluator.evaluate(context, this); 071 } 072 073}