KickJava   Java API By Example, From Geeks To Geeks.

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


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
17 public class BooleanValue implements Value
18 {
19   private Boolean JavaDoc m_value;
20
21
22   public BooleanValue()
23   {
24     this(false);
25   }
26
27
28   public BooleanValue(boolean value)
29   {
30     m_value = new Boolean JavaDoc(value);
31   }
32
33
34   public BooleanValue(Object JavaDoc value)
35   {
36     m_value = (Boolean JavaDoc)value;
37   }
38
39
40   public void setValue(Object JavaDoc value)
41   {
42     m_value = (Boolean JavaDoc)value;
43   }
44
45
46   public int getTypeId()
47   {
48     return ValueType.BOOLEAN;
49   }
50
51
52   public Object JavaDoc getValue()
53   {
54     return m_value;
55   }
56
57
58   public boolean equals(Value nv)
59   {
60     boolean result = false;
61
62     if (nv.getTypeId() == ValueType.BOOLEAN)
63       result = m_value.equals(nv.getValue());
64     else
65       throw new IllegalArgumentException JavaDoc();
66
67     return result;
68   }
69
70
71   public boolean lessThan(Value nv)
72   {
73     boolean result = false;
74
75     if (nv.getTypeId() == ValueType.BOOLEAN) {
76       Boolean JavaDoc b = (Boolean JavaDoc)nv.getValue();
77         // FALSE is considered less than TRUE
78
result = (m_value.booleanValue() == false && b.booleanValue() == true);
79     }
80     else
81       throw new IllegalArgumentException JavaDoc();
82
83     return result;
84   }
85
86
87   public boolean lessThanEqual(Value nv)
88   {
89     return (lessThan(nv) || equals(nv));
90   }
91
92
93   public boolean greaterThan(Value nv)
94   {
95     return (! lessThan(nv) && ! equals(nv));
96   }
97
98
99   public boolean greaterThanEqual(Value nv)
100   {
101     return (! lessThan(nv));
102   }
103
104
105   public Value plus(Value nv)
106   {
107     throw new ArithmeticException JavaDoc();
108   }
109
110
111   public Value minus(Value nv)
112   {
113     throw new ArithmeticException JavaDoc();
114   }
115
116
117   public Value multiply(Value nv)
118   {
119     throw new ArithmeticException JavaDoc();
120   }
121
122
123   public Value divide(Value nv)
124   {
125     throw new ArithmeticException JavaDoc();
126   }
127
128
129   public Value negate()
130   {
131     throw new ArithmeticException JavaDoc();
132   }
133
134
135   public Value convert(int typeId)
136   {
137     Value result = null;
138
139     if (typeId == ValueType.BOOLEAN)
140       result = new BooleanValue(m_value);
141     else
142       throw new IllegalArgumentException JavaDoc();
143
144     return result;
145   }
146
147
148   public String JavaDoc toString()
149   {
150     return m_value.toString();
151   }
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Popular Tags