Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart6.png 69% of files have more coverage
54   347   32   3
16   149   0,59   18
18     1,78  
1    
 
  Operator       Line # 29 54 32 58% 0.57954544
 
  (92)
 
1    /* $Id: Operator.java,v 1.1 2008/07/26 07:58:30 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.bo.parser;
19   
20   
21    /**
22    * This class describes an term or logical operator. An operator is of either
23    * prefix, infix or postfix type and has a minimum and maximum number of operands.
24    * It has a symbol or token that enables to recognize it and a QEDEQ representation.
25    *
26    * @version $Revision: 1.1 $
27    * @author Michael Meyling
28    */
 
29    public final class Operator {
30   
31    /** Marks infix operator. */
32    public static final int INFIX = 0;
33   
34    /** Marks prefix operator. */
35    public static final int SIMPLE_PREFIX = 1;
36   
37    /** Marks postfix operator. */
38    public static final int POSTFIX = 2;
39   
40    /** Marks function operator. */
41    public static final int FUNCTION = 4;
42   
43    /** Prefix, function, infix or postfix. See {@link #SIMPLE_PREFIX}, {@link #FUNCTION},
44    * {@link #INFIX} and {@link #POSTFIX}. */
45    private final int type;
46   
47    /** Start symbol or token for this operator. */
48    private final String startSymbol;
49   
50    /** Separator symbol or token for this operator. This could be a comma for example. */
51    private final String separatorSymbol;
52   
53    /** End symbol or token for this operator. */
54    private final String endSymbol;
55   
56    /** Operator priority. Highest is 0. */
57    private final int priority;
58   
59    /** QEDEQ token for this operator. */
60    private final String qedeq;
61   
62    /** First QEDEQ argument. Can be <code>null</code>. */
63    private final String qedeqArgument;
64   
65    /** Minimum number of arguments. */
66    private final int min;
67   
68    /** Maximum number of arguments. */
69    private final int max;
70   
71   
72    /**
73    * Constructor.
74    *
75    * @param symbol Symbol or token for this operator.
76    * @param qedeq QEDEQ operator symbol.
77    * @param qedeqArgument First Argument in QEDEQ-Syntax - if any.
78    * @param priority Operator priority, highest is 0.
79    * @param type Prefix, infix or postfix. See {@link #SIMPLE_PREFIX}, {@link #FUNCTION},
80    * {@link #INFIX} and {@link #POSTFIX}.
81    * @param min Minimum number of arguments for this operator.
82    */
 
83  544 toggle public Operator(final String symbol,
84    final String qedeq,
85    final String qedeqArgument,
86    final int priority,
87    final int type,
88    final int min) {
89  544 this(symbol, qedeq, qedeqArgument, priority, type, min, -1);
90    }
91   
92    /**
93    * Constructor.
94    *
95    * @param symbol Symbol or token for this operator.
96    * @param qedeq QEDEQ operator symbol.
97    * @param qedeqArgument First Argument in QEDEQ-Syntax - if any.
98    * @param priority Operator priority, highest is 0.
99    * @param type Prefix, infix or postfix. See {@link #SIMPLE_PREFIX},
100    * {@link #FUNCTION},
101    * {@link #INFIX} and {@link #POSTFIX}.
102    * @param min Minimum number of arguments for this operator.
103    * @param max Maximum number of arguments for this operator.
104    */
 
105  1338 toggle public Operator(final String symbol,
106    final String qedeq,
107    final String qedeqArgument,
108    final int priority,
109    final int type,
110    final int min,
111    final int max) {
112  1338 this(symbol, null, null, qedeq, qedeqArgument, priority, type, min, max);
113    }
114   
115    /**
116    * Constructor for prefix operators like <code>{x | x > 0}</code>.
117    *
118    * @param startSymbol Starting symbol or token for this operator.
119    * @param separatorSymbol Symbol or token that separates arguments for this operator.
120    * @param endSymbol End symbol or token for this operator.
121    * @param qedeq QEDEQ operator symbol.
122    * @param qedeqArgument First Argument in QEDEQ-Syntax - if any
123    * @param priority Operator priority, highest is 0.
124    * @param min Minimum number of arguments for this operator.
125    */
 
126  92 toggle public Operator(final String startSymbol,
127    final String separatorSymbol,
128    final String endSymbol,
129    final String qedeq,
130    final String qedeqArgument,
131    final int priority,
132    final int min) {
133  92 this(startSymbol, separatorSymbol, endSymbol, qedeq, qedeqArgument, priority, SIMPLE_PREFIX,
134    min, -1);
135    }
136   
137    /**
138    * Constructor for prefix operators like <code>{x, y, z}</code>.
139    *
140    * @param startSymbol Starting symbol or token for this operator.
141    * @param separatorSymbol Symbol or token that separates arguments for this operator.
142    * @param endSymbol End symbol or token for this operator.
143    * @param qedeq QEDEQ operator symbol.
144    * @param qedeqArgument First Argument in QEDEQ-Syntax - if any.
145    * @param priority Operator priority, highest is 0.
146    * @param min Minimum number of arguments for this operator.
147    * @param max Maximum number of arguments for this operator.
148    */
 
149  92 toggle public Operator(final String startSymbol,
150    final String separatorSymbol,
151    final String endSymbol,
152    final String qedeq,
153    final String qedeqArgument,
154    final int priority,
155    final int min,
156    final int max) {
157  92 this(startSymbol, separatorSymbol, endSymbol, qedeq, qedeqArgument, priority, SIMPLE_PREFIX,
158    min, max);
159    }
160   
161    /**
162    * Constructor.
163    *
164    * @param startSymbol Starting symbol or token for this operator.
165    * @param separatorSymbol Symbol or token that separates arguments for this operator.
166    * @param endSymbol End symbol or token for this operator.
167    * @param qedeq QEDEQ operator symbol.
168    * @param qedeqArgument First Argument in QEDEQ-Syntax - if any.
169    * @param priority Operator priority, highest is 0.
170    * @param type Prefix, infix or postfix. See {@link #SIMPLE_PREFIX},
171    * {@link #FUNCTION}, {@link #INFIX} and {@link #POSTFIX}.
172    * @param min Minimum number of arguments for this operator.
173    * @param max Maximum number of arguments for this operator.
174    */
 
175  1522 toggle public Operator(final String startSymbol, final String separatorSymbol, final String endSymbol,
176    final String qedeq,
177    final String qedeqArgument,
178    final int priority,
179    final int type,
180    final int min,
181    final int max) {
182  1522 this.startSymbol = startSymbol;
183  1522 this.separatorSymbol = separatorSymbol;
184  1522 this.endSymbol = endSymbol;
185  1522 this.type = type;
186  1522 this.qedeq = qedeq;
187  1522 this.qedeqArgument = qedeqArgument;
188  1522 this.priority = priority;
189  1522 this.min = min;
190  1522 this.max = max;
191  1522 switch (type) {
192  747 case INFIX:
193  687 case SIMPLE_PREFIX:
194  88 case FUNCTION:
195  0 case POSTFIX:
196  1522 break;
197  0 default:
198  0 throw new IllegalArgumentException("unknown operator type: "
199    + type);
200    }
201  1522 if (max != -1 && min > max) {
202  0 throw new IllegalArgumentException("Min greater than max: " + min + " > " + max);
203    }
204  1522 if (isInfix() && min < 2) {
205  0 throw new IllegalArgumentException("Infix needs at least two arguments");
206    }
207    }
208   
209    /**
210    * Returns symbol or token to identify this operator.
211    *
212    * @return Symbol or token to identify a start of this operator.
213    */
 
214  144522 toggle public final String getStartSymbol() {
215  144522 return startSymbol;
216    }
217   
218    /**
219    * Returns symbol or token to separate different arguments for this operator. Can only be
220    * different from <code>null</code> if this is a prefix operator.
221    *
222    * @return Symbol or token to identify the start of a new argument of this operator.
223    */
 
224  292 toggle public String getSeparatorSymbol() {
225  292 return separatorSymbol;
226    }
227   
228    /**
229    * Returns symbol or token to identify the end of this operator. Can only be different from
230    * <code>null</code> if this is a prefix operator.
231    *
232    * @return Symbol or token to identify the end of this operator. Maybe <code>null</code>.
233    */
 
234  566 toggle public String getEndSymbol() {
235  566 return endSymbol;
236    }
237   
238    /**
239    * Is this an infix operator?
240    *
241    * @return Is this an infix operator?
242    */
 
243  1522 toggle public final boolean isInfix() {
244  1522 return type == INFIX;
245    }
246   
247    /**
248    * Is this a prefix operator?
249    *
250    * @return Is this a prefix operator?
251    */
 
252  1105 toggle public final boolean isPrefix() {
253  1105 return type == SIMPLE_PREFIX || type == FUNCTION;
254    }
255   
256    /**
257    * Is this a function operator?
258    *
259    * @return Is this a function operator?
260    */
 
261  436 toggle public final boolean isFunction() {
262  436 return type == FUNCTION;
263    }
264   
265    /**
266    * Is this a postfix operator?
267    *
268    * @return Is this a postfix operator?
269    */
 
270  613 toggle public final boolean isPostfix() {
271  613 return type == POSTFIX;
272    }
273   
274    /**
275    * Get operator priority. 0 is the highest priority.
276    *
277    * @return Priority.
278    */
 
279  2368 toggle public final int getPriority() {
280  2368 return this.priority;
281    }
282   
283    /**
284    * Get minimum argument number.
285    *
286    * @return Minimum argument number.
287    */
 
288  830 toggle public final int getMin() {
289  830 return this.min;
290    }
291   
292    /**
293    * Get maximum argument number.
294    *
295    * @return Maximum argument number.
296    */
 
297  3482 toggle public final int getMax() {
298  3482 return max;
299    }
300   
301    /**
302    * Get QEDEQ operator name.
303    *
304    * @return QEDEQ operator name.
305    */
 
306  11343 toggle public final String getQedeq() {
307  11343 return qedeq;
308    }
309   
310    /**
311    * Get first QEDEQ argument.
312    *
313    * @return First QEDEQ argument. Can be <code>null</code>.
314    */
 
315  18096 toggle public final String getQedeqArgument() {
316  18096 return qedeqArgument;
317    }
318   
 
319  0 toggle public final String toString() {
320  0 final StringBuffer buffer = new StringBuffer(getStartSymbol());
321  0 buffer.append("[" + getMin() + ", ");
322  0 if (getMax() == -1) {
323  0 buffer.append("..");
324    } else {
325  0 buffer.append(getMax());
326    }
327  0 buffer.append("]");
328  0 if (getSeparatorSymbol() != null) {
329  0 buffer.append(" ").append(getSeparatorSymbol());
330    }
331  0 if (getEndSymbol() != null) {
332  0 buffer.append(" ").append(getEndSymbol());
333    }
334  0 if (isFunction()) {
335  0 buffer.append(", is function");
336    }
337  0 if (isPrefix()) {
338  0 buffer.append(", is prefix");
339    }
340  0 if (isInfix()) {
341  0 buffer.append(", is infix");
342    }
343  0 return buffer.toString();
344    }
345   
346    }
347