KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > filter > lib > Avg


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, S. Chassande-Barrioz, A. Lefebvre
22  */

23
24 package org.objectweb.medor.filter.lib;
25
26 import org.objectweb.medor.expression.api.ExpressionException;
27 import org.objectweb.medor.expression.api.MalformedExpressionException;
28 import org.objectweb.medor.expression.api.Operator;
29 import org.objectweb.medor.expression.api.ParameterOperand;
30 import org.objectweb.medor.expression.api.Expression;
31 import org.objectweb.medor.expression.api.Operand;
32 import org.objectweb.medor.expression.lib.BasicVariableOperand;
33 import org.objectweb.jorm.type.api.PTypeSpace;
34
35 /**
36  * Avg aggregate function.
37  * <p>
38  * Avg applies to :
39  * <ol>
40  * <li>a FieldOperand, which is part of a NestedField.</li>
41  * <li>a Collection of values (TupleCollection), specifying which Field
42  * is to be aggregated</li>
43  * <li>a Collection of values (Java Collection)</li>
44  * </ol>
45  * @author Alexandre Lefebvre
46  */

47 public class Avg extends BasicAggregateOperator {
48
49     public Avg() {
50         super(PTypeSpace.FLOAT);
51     }
52
53     public Avg(Expression e) {
54         super(PTypeSpace.FLOAT, e);
55     }
56
57     public Avg(Expression e, boolean distinct) {
58         super(PTypeSpace.FLOAT, e, distinct);
59     }
60
61     public String JavaDoc getOperatorString() {
62         return Operator.AVG;
63     }
64
65     public Operand compileExpression()
66             throws ExpressionException, MalformedExpressionException {
67         if (expressions[0] != null) {
68             expressions[0].compileExpression();
69                 result = new BasicVariableOperand(PTypeSpace.FLOAT);
70                 verified = true;
71         }
72         else
73         // Operands not yet assigned
74
throw new MalformedExpressionException("null children value");
75         return result;
76     }
77
78     public Operand evaluate(ParameterOperand[] pos, Object JavaDoc o)
79             throws ExpressionException {
80         throw new ExpressionException("Implementation of Avg by MEDOR not yet implemented");
81     }
82 }
83
Popular Tags