Source code: com/hartmath/expression/HObject.java
1 /*
2 * HObject.java
3 * Copyright (C) 2000 Klaus Hartlage
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 package com.hartmath.expression;
20
21 import java.lang.*;
22 import java.io.DataInputStream;
23 import java.io.DataOutputStream;
24 import java.io.IOException;
25 import com.hartmath.prettyprint.PrettyPrintBox;
26 import com.hartmath.lib.Session;
27 /**
28 * Interface that represents a math object: integer, fraction, complex, string, symbol, pattern, function,...
29 *
30 *@see HDouble
31 *@see HDoubleComplex
32 *@see HInteger
33 *@see HFraction
34 *@see HComplex
35 *@see HString
36 *@see HSymbol
37 *@see HPattern
38 *@see HFunction
39 */
40 public interface HObject {
41 // ID's for the hierarchy function.
42 // define a bit for every type:
43 /**
44 * Description of the Field
45 */
46 public final static int DOUBLEID = 1;
47 /**
48 * Description of the Field
49 */
50 public final static int DOUBLECOMPLEXID = 2;
51 /**
52 * Description of the Field
53 */
54 public final static int INTEGERID = 4;
55 /**
56 * Description of the Field
57 */
58 public final static int FRACTIONID = 8;
59 /**
60 * Description of the Field
61 */
62 public final static int COMPLEXID = 16;
63 /**
64 * Description of the Field
65 */
66 public final static int STRINGID = 32;
67 /**
68 * Description of the Field
69 */
70 public final static int SYMBOLID = 64;
71 /**
72 * Description of the Field
73 */
74 public final static int FUNCTIONID = 128;
75 /**
76 * Description of the Field
77 */
78 public final static int PATTERNID = 256;
79 /**
80 * Description of the Field
81 */
82 public final static int OBJECTID = 512;
83 // ID's for init.hm file
84 /**
85 * Description of the Field
86 */
87 public final static byte DOUBLEFILEID = 2;
88 /**
89 * Description of the Field
90 */
91 public final static byte DOUBLECOMPLEXFILEID = 3;
92 /**
93 * Description of the Field
94 */
95 public final static byte INTEGERFILEID = 4;
96 /**
97 * Description of the Field
98 */
99 public final static byte FRACTIONFILEID = 5;
100 /**
101 * Description of the Field
102 */
103 public final static byte COMPLEXFILEID = 6;
104 /**
105 * Description of the Field
106 */
107 public final static byte STRINGFILEID = 16;
108 /**
109 * Description of the Field
110 */
111 public final static byte SYMBOLFILEID = 32;
112 /**
113 * Description of the Field
114 */
115 public final static byte FUNCTIONFILEID = 64;
116 /**
117 * Description of the Field
118 */
119 public final static byte PATTERNFILEID = 65;
120
121
122 /**
123 * Returns true if <code>this</code> is not equal to <code>obj</code>
124 *
125 *@param obj an object to compare with
126 *@return Description of the Returned Value
127 */
128 public abstract boolean unequals(Object obj);
129
130
131 /**
132 * Returns true if <code>this</code> is less to <code>obj</code>
133 *
134 *@param obj an object to compare with
135 *@param session Description of Parameter
136 *@return Description of the Returned Value
137 */
138 public abstract boolean less(Session session, Object obj);
139
140
141 /**
142 * Returns true if <code>this</code> is greater to <code>obj</code>
143 *
144 *@param obj an object to compare with
145 *@param session Description of Parameter
146 *@return Description of the Returned Value
147 */
148 public abstract boolean greater(Session session, Object obj);
149
150
151 /**
152 * Evaluate this.
153 *
154 *@param session Description of Parameter
155 *@return returns the evaluated math object otherwise returns <code>null</code>
156 * if the object could not be evaluated
157 */
158 public abstract HObject evaluate(Session session);
159
160
161 /**
162 * Returns true if <code>this</code> (pattern-)matches the object <code>obj</code>
163 *
164 *@param obj an object to compare with
165 *@param session Description of Parameter
166 *@return Description of the Returned Value
167 */
168 public abstract boolean matches(HObject obj, Session session);
169
170
171 /**
172 * Substitute the HObject obj in this with the HObject subst
173 *
174 *@param obj an object to compare with
175 *@param subst the substitution for the object
176 *@return Description of the Returned Value
177 */
178 public abstract HObject substitute(HObject obj, HObject subst);
179
180
181 /**
182 * Substitute all HPattern-objects in this with the HObject subst
183 *
184 *@param session Description of Parameter
185 *@return Description of the Returned Value
186 */
187 public abstract HObject substitutePattern(Session session);
188
189
190 /**
191 * Use this method instead of toString() to display the expression as a String
192 *
193 *@param buf result of the String conversin
194 *@param session session data
195 */
196 public abstract void toStringBuffer(StringBuffer buf, Session session);
197
198
199 // abstract public PrettyPrintBox prettyPrint(String font, int fontSize);
200 /*
201 * abstract public PrettyPrintBox prettyPrint(
202 * String font,
203 * int fontSize,
204 * int precedence);
205 */
206 /**
207 * Returns an specific integer value for each class in the HObject
208 * class-hierarchy
209 *
210 *@return Description of the Returned Value
211 */
212 public abstract int hierarchy();
213
214
215 /**
216 * Write a persistant object
217 *
218 *@return Description of the Returned Value
219 */
220 // abstract public void writeTo(DataOutputStream os) throws IOException;
221
222 /**
223 * Write a persistant object
224 *
225 * Returns the associated header-symbol of this HObject e.g for a HInteger
226 * object the symbol C.Integer will be returned and for a HFunction the
227 * special header-symbol will be retuned
228 *
229 *@return Description of the Returned Value
230 *@see HFunction
231 */
232 public abstract HSymbol head();
233
234
235 /**
236 * Method declaration
237 *
238 *@param head
239 *@param session Description of Parameter
240 *@return
241 *@see
242 */
243 public abstract HObject apply(HObject head, Session session);
244
245
246 /**
247 * Returns true if this is an instance of HFunction with the header symbol
248 * C.List @ see C
249 *
250 *@return The list value
251 */
252 public abstract boolean isList();
253
254
255 /**
256 * Returns true if this is a number e.g. HInteger, HFraction, HComplex,
257 * HDouble or HDoubleComplex
258 *
259 *@return The number value
260 */
261 public abstract boolean isNumber();
262
263
264 /**
265 * Returns true if this is a rational number e.g. HInteger, HFraction
266 *
267 *@return The rational value
268 */
269 public abstract boolean isRational();
270
271
272 /**
273 * Returns true if this contains the HObject obj
274 *
275 *@param obj Description of Parameter
276 *@return The member value
277 */
278 public abstract boolean isMember(HObject obj);
279
280
281 /**
282 * Returns true if this contains the HSymbol sym as a header
283 *
284 *@param sym Description of Parameter
285 *@return The headMember value
286 */
287 public abstract boolean isHeadMember(HSymbol sym);
288
289
290 /**
291 * Operator precedence of the mathematical object
292 *
293 *@return the precedence of the object (important for a function which
294 * should be displayed in operator notation
295 */
296 public abstract int precedence();
297 }
298
299