From imperius-commits-return-125-apmail-incubator-imperius-commits-archive=incubator.apache.org@incubator.apache.org Sat Jan 12 18:10:02 2008 Return-Path: Delivered-To: apmail-incubator-imperius-commits-archive@locus.apache.org Received: (qmail 55473 invoked from network); 12 Jan 2008 18:10:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Jan 2008 18:10:02 -0000 Received: (qmail 73684 invoked by uid 500); 12 Jan 2008 18:09:52 -0000 Delivered-To: apmail-incubator-imperius-commits-archive@incubator.apache.org Received: (qmail 73672 invoked by uid 500); 12 Jan 2008 18:09:52 -0000 Mailing-List: contact imperius-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: imperius-dev@incubator.apache.org Delivered-To: mailing list imperius-commits@incubator.apache.org Delivered-To: moderator for imperius-commits@incubator.apache.org Received: (qmail 29827 invoked by uid 99); 11 Jan 2008 18:59:40 -0000 X-ASF-Spam-Status: No, hits=-99.3 required=10.0 tests=ALL_TRUSTED,FRT_LEVITRA X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r611261 [22/43] - in /incubator/imperius/trunk: ./ imperius-javaspl/ imperius-javaspl/src/main/java/org/apache/imperius/javaspl/ imperius-splcore/ imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/ imperius-splcore/src... Date: Fri, 11 Jan 2008 18:57:14 -0000 To: imperius-commits@incubator.apache.org From: kevan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080111185843.C4C721A984F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Max.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Max.java?rev=611261&r1=611260&r2=611261&view=diff ============================================================================== --- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Max.java (original) +++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Max.java Fri Jan 11 10:56:30 2008 @@ -1,152 +1,152 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// - -/** - * @author Neeraj Joshi - * - */ -package org.apache.imperius.spl.parser.expressions.impl; - -import java.util.Iterator; -import java.util.List; -import java.util.logging.Logger; - -import org.apache.imperius.spl.external.Expression; -import org.apache.imperius.spl.external.TypeConstants; -import org.apache.imperius.spl.parser.exceptions.SPLException; -import org.apache.imperius.spl.parser.expressions.MultipleArgumentExpression; -import org.apache.imperius.spl.parser.expressions.NumericExpression; -import org.apache.imperius.spl.parser.util.ExpressionUtility; -import org.apache.imperius.spl.parser.util.TypeInfo; -import org.apache.imperius.spl.parser.util.TypeResolver; -import org.apache.imperius.util.SPLLogger; - - -public class Max extends MultipleArgumentExpression implements - NumericExpression -{ - - public static final String className = Max.class.getName(); - - private static Logger logger = SPLLogger.getSPLLogger().getLogger(); - private static final String sourceClass="Max"; - - - - public Max(List exprList, boolean validateExpression) - throws SPLException - { - super(exprList); - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Max"); - - if (validateExpression) - { - if (!validate()) - { - logger.severe(Thread.currentThread().getName()+" "+"validation error: " + className - + " has wrong data type passed in."); - - throw new SPLException("validation error: " + className - + " has wrong data type passed in."); - } - } - this._dataType.setIsArray(false); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Max"); - - } - - public Object evaluate() throws SPLException - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - try - { - Iterator expIterator = this._expressions.iterator(); - Number max = null; - while (expIterator.hasNext()) - { - Expression exp = (Expression) expIterator.next(); - Number evalResult = (Number) exp.evaluate(); - - if (max == null) - { - max = evalResult; - } - else - { - if (ExpressionUtility.compare(evalResult, max) > 0) - { - max = evalResult; - } - } - } - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - return max; - - } - catch (Exception e) - { - logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString()); - - throw new SPLException("evaluation error: " + e.toString()); - } - } - - public boolean validate() throws SPLException - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - Iterator expIterator = this._expressions.iterator(); - TypeInfo currentDataType = new TypeInfo(TypeConstants.INVALID); - while (expIterator.hasNext()) - { - Expression exp = (Expression) expIterator.next(); - TypeInfo type = exp.getType(); - if (!TypeResolver.isNumeric(type)) - { - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return false; - } - if (currentDataType.getType() == TypeConstants.INVALID) - { - currentDataType = type; - } - _dataType = TypeResolver.binaryNumericPromotionResolver( - currentDataType, type); - - } - - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - } - - public String toString() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString"); - String str = "MAX[ "; - Iterator iter = this._expressions.iterator(); - while(iter.hasNext()) { - str = str + ((Expression)iter.next()).toString() + (iter.hasNext()?", ":" ]"); - } - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString"); - - return str; - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// + +/** + * @author Neeraj Joshi + * + */ +package org.apache.imperius.spl.parser.expressions.impl; + +import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; + +import org.apache.imperius.spl.external.Expression; +import org.apache.imperius.spl.external.TypeConstants; +import org.apache.imperius.spl.parser.exceptions.SPLException; +import org.apache.imperius.spl.parser.expressions.MultipleArgumentExpression; +import org.apache.imperius.spl.parser.expressions.NumericExpression; +import org.apache.imperius.spl.parser.util.ExpressionUtility; +import org.apache.imperius.spl.parser.util.TypeInfo; +import org.apache.imperius.spl.parser.util.TypeResolver; +import org.apache.imperius.util.SPLLogger; + + +public class Max extends MultipleArgumentExpression implements + NumericExpression +{ + + public static final String className = Max.class.getName(); + + private static Logger logger = SPLLogger.getSPLLogger().getLogger(); + private static final String sourceClass="Max"; + + + + public Max(List exprList, boolean validateExpression) + throws SPLException + { + super(exprList); + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Max"); + + if (validateExpression) + { + if (!validate()) + { + logger.severe(Thread.currentThread().getName()+" "+"validation error: " + className + + " has wrong data type passed in."); + + throw new SPLException("validation error: " + className + + " has wrong data type passed in."); + } + } + this._dataType.setIsArray(false); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Max"); + + } + + public Object evaluate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + try + { + Iterator expIterator = this._expressions.iterator(); + Number max = null; + while (expIterator.hasNext()) + { + Expression exp = (Expression) expIterator.next(); + Number evalResult = (Number) exp.evaluate(); + + if (max == null) + { + max = evalResult; + } + else + { + if (ExpressionUtility.compare(evalResult, max) > 0) + { + max = evalResult; + } + } + } + + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + return max; + + } + catch (Exception e) + { + logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString()); + + throw new SPLException("evaluation error: " + e.toString()); + } + } + + public boolean validate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + Iterator expIterator = this._expressions.iterator(); + TypeInfo currentDataType = new TypeInfo(TypeConstants.INVALID); + while (expIterator.hasNext()) + { + Expression exp = (Expression) expIterator.next(); + TypeInfo type = exp.getType(); + if (!TypeResolver.isNumeric(type)) + { + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return false; + } + if (currentDataType.getType() == TypeConstants.INVALID) + { + currentDataType = type; + } + _dataType = TypeResolver.binaryNumericPromotionResolver( + currentDataType, type); + + } + + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + } + + public String toString() + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString"); + String str = "MAX[ "; + Iterator iter = this._expressions.iterator(); + while(iter.hasNext()) { + str = str + ((Expression)iter.next()).toString() + (iter.hasNext()?", ":" ]"); + } + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString"); + + return str; + } + +} Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Max.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MaxInCollection.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MaxInCollection.java?rev=611261&r1=611260&r2=611261&view=diff ============================================================================== --- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MaxInCollection.java (original) +++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MaxInCollection.java Fri Jan 11 10:56:30 2008 @@ -1,182 +1,182 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// - -/** - * @author Neeraj Joshi - * - */ -package org.apache.imperius.spl.parser.expressions.impl; - -import java.util.Iterator; -import java.util.List; -import java.util.ArrayList; -import java.util.logging.Logger; - -import org.apache.imperius.spl.external.Expression; -import org.apache.imperius.spl.parser.exceptions.SPLException; -import org.apache.imperius.spl.parser.expressions.SingleArgumentExpression; -import org.apache.imperius.spl.parser.util.ExpressionUtility; -import org.apache.imperius.util.SPLLogger; - - -public class MaxInCollection extends SingleArgumentExpression implements - Expression -{ - - public String className = MaxInCollection.class.toString(); - - private static Logger logger = SPLLogger.getSPLLogger().getLogger(); - private static final String sourceClass="MaxInCollection"; - - - -// public boolean isArray() -// { -// logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); -// -// logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); -// -// -// return _dataType.getIsArray(); -// } - - public MaxInCollection(List exprList, boolean evaluateExpression) - throws SPLException - { - super(exprList); - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MaxInCollection"); - - //System.out.println("MaxInCollection"); - if (evaluateExpression) - { - //System.out.println("evaluateExpression " + evaluateExpression); - if (!validate()) - { - logger.severe( - "validation error: wrong data type passed in " - + this._dataType); - throw new SPLException( - "validation error: wrong data type passed in " - + this._dataType); - } - } - - this._dataType.copy(this._exp.getType()); - this._dataType.setIsArray(false); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MaxInCollection"); - - - } - - public Object evaluate() throws SPLException - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - //System.out.println("MaxInCollection:evaluate"); - // int type=this.dataType; - //System.out.println("this.exp class " + this.exp.getClass() + " type " + this.exp.getType()); - // Expression expression = (Expression) this._exp; - // Double minNumeric=null; - // String minString=null; - // DateTime MinInterval=null; - Object max = null; - Object expResult = this._exp.evaluate(); - if (!(expResult instanceof java.util.List)) - { - logger.severe(Thread.currentThread().getName()+" "+"result of expression is not of type List"); - throw new SPLException( - "result of expression is not of type List"); - } - ArrayList resultArray = (ArrayList) expResult; - //System.out.println("resultArray size " + resultArray.size()+ " to string " + resultArray.toString()); - ////System.out.println("resultArray is of type "+expression.getType()); - if ((resultArray != null) && (!resultArray.isEmpty())) - { - Iterator resultIt = resultArray.iterator(); - while (resultIt.hasNext()) - { - Object resultObject = resultIt.next(); - //System.out.println("resultObject,class " + resultObject + " "+ resultObject.getClass()); - if (max == null) - { - max = resultObject; - } - - if (ExpressionUtility.compare(max, resultObject) < 0) - { - //System.out.println("resultObject " + resultObject+ " is greater than max " + max+ " so resetting max"); - max = resultObject; - } - else - { - //System.out.println("resultObject " + resultObject+ " max not reset" + max); - - } - - } - //System.out.println(max); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - return max; - } - else - { - logger.severe(Thread.currentThread().getName()+" "+"result Array is empty"); - throw new SPLException("result Array is empty"); - } - - } - - /* - * public int getType() { - * - * return this.dataType; } - */ - - public boolean validate() throws SPLException - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - //System.out.println("MaxInCollection : validate "); - //System.out.println("this.exp.getClass() " + this.exp.getClass() + " type " + this.exp.getType()); - - if (!this._exp.isArray()) - { - //System.out.println("expression is not a valid BasicCollectExpression"); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return false; - } - else - { - //System.out.println("expression is a valid BasicCollectExpression"); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - } - - } - - public String toString() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString"); - - String str = "MaxInCollection("+this._exp.toString()+")"; - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString"); - - return str; - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// + +/** + * @author Neeraj Joshi + * + */ +package org.apache.imperius.spl.parser.expressions.impl; + +import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; +import java.util.logging.Logger; + +import org.apache.imperius.spl.external.Expression; +import org.apache.imperius.spl.parser.exceptions.SPLException; +import org.apache.imperius.spl.parser.expressions.SingleArgumentExpression; +import org.apache.imperius.spl.parser.util.ExpressionUtility; +import org.apache.imperius.util.SPLLogger; + + +public class MaxInCollection extends SingleArgumentExpression implements + Expression +{ + + public String className = MaxInCollection.class.toString(); + + private static Logger logger = SPLLogger.getSPLLogger().getLogger(); + private static final String sourceClass="MaxInCollection"; + + + +// public boolean isArray() +// { +// logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); +// +// logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); +// +// +// return _dataType.getIsArray(); +// } + + public MaxInCollection(List exprList, boolean evaluateExpression) + throws SPLException + { + super(exprList); + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MaxInCollection"); + + //System.out.println("MaxInCollection"); + if (evaluateExpression) + { + //System.out.println("evaluateExpression " + evaluateExpression); + if (!validate()) + { + logger.severe( + "validation error: wrong data type passed in " + + this._dataType); + throw new SPLException( + "validation error: wrong data type passed in " + + this._dataType); + } + } + + this._dataType.copy(this._exp.getType()); + this._dataType.setIsArray(false); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MaxInCollection"); + + + } + + public Object evaluate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + //System.out.println("MaxInCollection:evaluate"); + // int type=this.dataType; + //System.out.println("this.exp class " + this.exp.getClass() + " type " + this.exp.getType()); + // Expression expression = (Expression) this._exp; + // Double minNumeric=null; + // String minString=null; + // DateTime MinInterval=null; + Object max = null; + Object expResult = this._exp.evaluate(); + if (!(expResult instanceof java.util.List)) + { + logger.severe(Thread.currentThread().getName()+" "+"result of expression is not of type List"); + throw new SPLException( + "result of expression is not of type List"); + } + ArrayList resultArray = (ArrayList) expResult; + //System.out.println("resultArray size " + resultArray.size()+ " to string " + resultArray.toString()); + ////System.out.println("resultArray is of type "+expression.getType()); + if ((resultArray != null) && (!resultArray.isEmpty())) + { + Iterator resultIt = resultArray.iterator(); + while (resultIt.hasNext()) + { + Object resultObject = resultIt.next(); + //System.out.println("resultObject,class " + resultObject + " "+ resultObject.getClass()); + if (max == null) + { + max = resultObject; + } + + if (ExpressionUtility.compare(max, resultObject) < 0) + { + //System.out.println("resultObject " + resultObject+ " is greater than max " + max+ " so resetting max"); + max = resultObject; + } + else + { + //System.out.println("resultObject " + resultObject+ " max not reset" + max); + + } + + } + //System.out.println(max); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + return max; + } + else + { + logger.severe(Thread.currentThread().getName()+" "+"result Array is empty"); + throw new SPLException("result Array is empty"); + } + + } + + /* + * public int getType() { + * + * return this.dataType; } + */ + + public boolean validate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + //System.out.println("MaxInCollection : validate "); + //System.out.println("this.exp.getClass() " + this.exp.getClass() + " type " + this.exp.getType()); + + if (!this._exp.isArray()) + { + //System.out.println("expression is not a valid BasicCollectExpression"); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return false; + } + else + { + //System.out.println("expression is a valid BasicCollectExpression"); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + } + + } + + public String toString() + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString"); + + String str = "MaxInCollection("+this._exp.toString()+")"; + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString"); + + return str; + } + +} Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MaxInCollection.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MedianInCollection.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MedianInCollection.java?rev=611261&r1=611260&r2=611261&view=diff ============================================================================== --- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MedianInCollection.java (original) +++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MedianInCollection.java Fri Jan 11 10:56:30 2008 @@ -1,209 +1,209 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// - -/** - * @author Prashant Baliga - * - */ -package org.apache.imperius.spl.parser.expressions.impl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Logger; - -import org.apache.imperius.spl.external.Expression; -import org.apache.imperius.spl.external.TypeConstants; -import org.apache.imperius.spl.parser.exceptions.SPLException; -import org.apache.imperius.spl.parser.expressions.SingleArgumentExpression; -import org.apache.imperius.spl.parser.util.ExpressionUtility; -import org.apache.imperius.util.SPLLogger; - - -public class MedianInCollection extends SingleArgumentExpression implements - Expression -{ - - public String className = MedianInCollection.class.toString(); - - private static Logger logger = SPLLogger.getSPLLogger().getLogger(); - private static final String sourceClass="MedianInCollection"; - - - - public MedianInCollection(List exprList, boolean evaluateExpression) - throws SPLException - { - super(exprList); - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MedianInCollection"); - - //System.out.println("MedianInCollection"); - if (evaluateExpression) - { - //System.out.println("evaluateExpression " + evaluateExpression); - if (!validate()) - { - logger.severe(Thread.currentThread().getName()+" "+"validation error: wrong data type passed in"); - throw new SPLException( - "validation error: wrong data type passed in " - + this._dataType); - } - } - - this._dataType.copy(this._exp.getType()); - this._dataType.setIsArray(false); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MedianInCollection"); - - - } - - public Object evaluate() throws SPLException - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - //System.out.println("MedianInCollection:evaluate"); - //System.out.println("this.exp class " + this.exp.getClass() + " type " + this.exp.getType()); - - Object expResult = this._exp.evaluate(); - if (!(expResult instanceof java.util.List)) - { - logger.severe(Thread.currentThread().getName()+" "+"result of expression is not of type List"); - throw new SPLException( - "result of expression is not of type List"); - } - ArrayList resultArray = (ArrayList) expResult; - Integer count = new Integer(resultArray.size()); - //System.out.println("resultArray size " + resultArray.size()+ " to string " + resultArray.toString()); - ////System.out.println("resultArray is of type "+expression.getType()); - if (count.intValue() < 2) - { - logger.severe(Thread.currentThread().getName()+" "+"result of expression is of size less than 2 hence median cannot be calculated"); - throw new SPLException( - "result of expression is of size less than 2 hence median cannot be calculated"); - } - if ((resultArray != null) && (!resultArray.isEmpty())) - { - Collections.sort(resultArray); - if ((count.intValue() / 2) == (count.floatValue() / 2)) - { - //System.out.println("size of collection is even " + count); - int medianElementPosition1 = (count.intValue()) / 2; - int medianElementPosition2 = medianElementPosition1 - 1; - Object medianElement1 = resultArray.get(medianElementPosition1); - Object medianElement2 = resultArray.get(medianElementPosition2); - Number sum = ExpressionUtility.plus((Number) medianElement1, - (Number) medianElement2); - Number avg = ExpressionUtility.division(sum, - (Number) new Integer(2)); - //System.out.println("median is " + avg); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - return avg; - - } - else if (((count.intValue() / 2) != (count.floatValue() / 2))) - { - //System.out.println("size of collection is odd " + count); - int medianElementPosition = (count.intValue() + 1) / 2; - medianElementPosition = medianElementPosition - 1; - Object median = resultArray.get(medianElementPosition); - //System.out.println("median is " + median); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - return median; - } - - } - else - { - logger.severe(Thread.currentThread().getName()+" "+"result Array is empty"); - throw new SPLException("result Array is empty"); - } - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); - - return null; - - } - - public boolean validate() throws SPLException - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - //System.out.println("MedianInCollection : validate "); - //System.out.println("this.exp.getClass() " + this.exp.getClass() + " type " + this.exp.getType()); - - if (!this._exp.isArray()) - { - //System.out.println("expression is not a valid BasicCollectExpression"); - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return false; - } - - else - { - //System.out.println("expression is a valid BasicCollectExpression"); - switch (this._exp.getType().getType()) - { - case TypeConstants.byteType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - case TypeConstants.doubleType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - case TypeConstants.floatType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - case TypeConstants.intType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - case TypeConstants.longType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - case TypeConstants.numericType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - case TypeConstants.shortType: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return true; - default: - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); - - return false; - } - - } - - } - - public String toString() - { - logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString"); - - String str = "MedianInCollection("+this._exp.toString()+")"; - logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString"); - - return str; - } - -} +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// + +/** + * @author Prashant Baliga + * + */ +package org.apache.imperius.spl.parser.expressions.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; + +import org.apache.imperius.spl.external.Expression; +import org.apache.imperius.spl.external.TypeConstants; +import org.apache.imperius.spl.parser.exceptions.SPLException; +import org.apache.imperius.spl.parser.expressions.SingleArgumentExpression; +import org.apache.imperius.spl.parser.util.ExpressionUtility; +import org.apache.imperius.util.SPLLogger; + + +public class MedianInCollection extends SingleArgumentExpression implements + Expression +{ + + public String className = MedianInCollection.class.toString(); + + private static Logger logger = SPLLogger.getSPLLogger().getLogger(); + private static final String sourceClass="MedianInCollection"; + + + + public MedianInCollection(List exprList, boolean evaluateExpression) + throws SPLException + { + super(exprList); + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MedianInCollection"); + + //System.out.println("MedianInCollection"); + if (evaluateExpression) + { + //System.out.println("evaluateExpression " + evaluateExpression); + if (!validate()) + { + logger.severe(Thread.currentThread().getName()+" "+"validation error: wrong data type passed in"); + throw new SPLException( + "validation error: wrong data type passed in " + + this._dataType); + } + } + + this._dataType.copy(this._exp.getType()); + this._dataType.setIsArray(false); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MedianInCollection"); + + + } + + public Object evaluate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + //System.out.println("MedianInCollection:evaluate"); + //System.out.println("this.exp class " + this.exp.getClass() + " type " + this.exp.getType()); + + Object expResult = this._exp.evaluate(); + if (!(expResult instanceof java.util.List)) + { + logger.severe(Thread.currentThread().getName()+" "+"result of expression is not of type List"); + throw new SPLException( + "result of expression is not of type List"); + } + ArrayList resultArray = (ArrayList) expResult; + Integer count = new Integer(resultArray.size()); + //System.out.println("resultArray size " + resultArray.size()+ " to string " + resultArray.toString()); + ////System.out.println("resultArray is of type "+expression.getType()); + if (count.intValue() < 2) + { + logger.severe(Thread.currentThread().getName()+" "+"result of expression is of size less than 2 hence median cannot be calculated"); + throw new SPLException( + "result of expression is of size less than 2 hence median cannot be calculated"); + } + if ((resultArray != null) && (!resultArray.isEmpty())) + { + Collections.sort(resultArray); + if ((count.intValue() / 2) == (count.floatValue() / 2)) + { + //System.out.println("size of collection is even " + count); + int medianElementPosition1 = (count.intValue()) / 2; + int medianElementPosition2 = medianElementPosition1 - 1; + Object medianElement1 = resultArray.get(medianElementPosition1); + Object medianElement2 = resultArray.get(medianElementPosition2); + Number sum = ExpressionUtility.plus((Number) medianElement1, + (Number) medianElement2); + Number avg = ExpressionUtility.division(sum, + (Number) new Integer(2)); + //System.out.println("median is " + avg); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + return avg; + + } + else if (((count.intValue() / 2) != (count.floatValue() / 2))) + { + //System.out.println("size of collection is odd " + count); + int medianElementPosition = (count.intValue() + 1) / 2; + medianElementPosition = medianElementPosition - 1; + Object median = resultArray.get(medianElementPosition); + //System.out.println("median is " + median); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + return median; + } + + } + else + { + logger.severe(Thread.currentThread().getName()+" "+"result Array is empty"); + throw new SPLException("result Array is empty"); + } + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate"); + + return null; + + } + + public boolean validate() throws SPLException + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + //System.out.println("MedianInCollection : validate "); + //System.out.println("this.exp.getClass() " + this.exp.getClass() + " type " + this.exp.getType()); + + if (!this._exp.isArray()) + { + //System.out.println("expression is not a valid BasicCollectExpression"); + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return false; + } + + else + { + //System.out.println("expression is a valid BasicCollectExpression"); + switch (this._exp.getType().getType()) + { + case TypeConstants.byteType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + case TypeConstants.doubleType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + case TypeConstants.floatType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + case TypeConstants.intType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + case TypeConstants.longType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + case TypeConstants.numericType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + case TypeConstants.shortType: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return true; + default: + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate"); + + return false; + } + + } + + } + + public String toString() + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString"); + + String str = "MedianInCollection("+this._exp.toString()+")"; + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString"); + + return str; + } + +} Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MedianInCollection.java ------------------------------------------------------------------------------ svn:eol-style = native