KickJava   Java API By Example, From Geeks To Geeks.

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


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 CharValue implements Value
18 {
19   private Character JavaDoc m_value;
20
21
22   public CharValue()
23   {
24     this((char)0);
25   }
26
27
28   public CharValue(char value)
29   {
30     m_value = new Character JavaDoc(value);
31   }
32
33
34   public CharValue(Object JavaDoc value)
35   {
36     m_value = (Character JavaDoc)value;
37   }
38
39
40   public void setValue(Object JavaDoc value)
41   {
42     m_value = (Character JavaDoc)value;
43   }
44
45
46   public int getTypeId()
47   {
48     return ValueType.CHAR;
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.CHAR)
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.CHAR) {
76       Character JavaDoc c = (Character JavaDoc)nv.getValue();
77       result = (m_value.charValue() < c.charValue());
78     }
79     else
80       throw new IllegalArgumentException JavaDoc();
81
82     return result;
83   }
84
85
86   public boolean lessThanEqual(Value nv)
87   {
88     return (lessThan(nv) || equals(nv));
89   }
90
91
92   public boolean greaterThan(Value nv)
93   {
94     return (! lessThan(nv) && ! equals(nv));
95   }
96
97
98   public boolean greaterThanEqual(Value nv)
99   {
100     return (! lessThan(nv));
101   }
102
103
104   public Value plus(Value nv)
105   {
106     throw new ArithmeticException JavaDoc();
107   }
108
109
110   public Value minus(Value nv)
111   {
112     throw new ArithmeticException JavaDoc();
113   }
114
115
116   public Value multiply(Value nv)
117   {
118     throw new ArithmeticException JavaDoc();
119   }
120
121
122   public Value divide(Value nv)
123   {
124     throw new ArithmeticException JavaDoc();
125   }
126
127
128   public Value negate()
129   {
130     throw new ArithmeticException JavaDoc();
131   }
132
133
134   public Value convert(int typeId)
135   {
136     Value result = null;
137
138     if (typeId == ValueType.CHAR)
139       result = new CharValue(m_value);
140     else if (typeId == ValueType.STRING) {
141       char[] arr = new char[1];
142       arr[0] = m_value.charValue();
143       String JavaDoc s = new String JavaDoc(arr);
144       result = ValueFactory.createString(s);
145     }
146     else
147       throw new IllegalArgumentException JavaDoc();
148
149     return result;
150   }
151
152
153   public String JavaDoc toString()
154   {
155     return m_value.toString();
156   }
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Popular Tags