KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > constraint > OrNode


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.constraint;
15
16 import java.io.*;
17
18
19 /** Represents logical "OR" */
20 public class OrNode extends ExprNode
21 {
22   private ExprNode m_left;
23   private ExprNode m_right;
24
25
26   private OrNode()
27   {
28   }
29
30
31   public OrNode(ExprNode left, ExprNode right)
32   {
33     m_left = left;
34     m_right = right;
35
36     setType(new ValueType(ValueType.BOOLEAN));
37   }
38
39
40   public void print(PrintStream ps)
41   {
42     ps.println("OrNode: type = " + getType());
43     ps.println("Left node:");
44     m_left.print(ps);
45     ps.println("Right node:");
46     m_right.print(ps);
47   }
48
49
50   public Value evaluate(PropertySource source)
51     throws MissingPropertyException
52   {
53     Value result = null;
54
55     int id = getType().getId();
56
57     Value left, right;
58
59     left = m_left.evaluate(source);
60     Boolean JavaDoc l = (Boolean JavaDoc)left.getValue();
61
62       // only evaluate the right side if the answer isn't already
63
// known after evaluating the left side
64
if (! l.booleanValue()) {
65       right = m_right.evaluate(source);
66       Boolean JavaDoc r = (Boolean JavaDoc)right.getValue();
67       result = ValueFactory.createBoolean(r.booleanValue());
68     }
69     else
70       result = ValueFactory.createBoolean(true);
71
72     return result;
73   }
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Popular Tags