KickJava   Java API By Example, From Geeks To Geeks.

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


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 StringValue implements Value
18 {
19   private String JavaDoc m_value;
20
21
22   public StringValue()
23   {
24     this(null);
25   }
26
27
28   public StringValue(String JavaDoc value)
29   {
30     m_value = value;
31   }
32
33
34   public StringValue(Object JavaDoc value)
35   {
36     m_value = (String JavaDoc)value;
37   }
38
39
40   public void setValue(Object JavaDoc value)
41   {
42     m_value = (String JavaDoc)value;
43   }
44
45
46   public int getTypeId()
47   {
48     return ValueType.STRING;
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.STRING)
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.STRING) {
76       String JavaDoc s = (String JavaDoc)nv.getValue();
77       result = (m_value.compareTo(s) < 0);
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.STRING)
139       result = new StringValue(m_value);
140     else
141       throw new IllegalArgumentException JavaDoc();
142
143     return result;
144   }
145
146
147   public String JavaDoc toString()
148   {
149     return m_value;
150   }
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Popular Tags