incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r611261 [23/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 GMT
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MiddleSubstring.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MiddleSubstring.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MiddleSubstring.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MiddleSubstring.java Fri Jan 11 10:56:30 2008
@@ -1,703 +1,703 @@
-/*
- * 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 Xiping Wang
- *
- */
-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.QuadrupleArgumentExpression;
-import org.apache.imperius.spl.parser.expressions.StringExpression;
-import org.apache.imperius.spl.parser.util.TypeInfo;
-import org.apache.imperius.spl.parser.util.TypeResolver;
-import org.apache.imperius.util.SPLLogger;
-
-
-public class MiddleSubstring extends QuadrupleArgumentExpression implements
-        StringExpression
-{
-    
-    public static final String className = MiddleSubstring.class.getName();
-    
-    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-    private static final String sourceClass="MiddleSubstring";
-    
-    
-    
-    public MiddleSubstring(List exprList, boolean validateExpression)
-            throws SPLException
-    {
-        super(exprList);
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MiddleSubstring");
-
-        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.");
-            }
-        }
-        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MiddleSubstring");
-        
-    }
-    
-    public Object evaluate() throws SPLException
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-
-        try
-        {
-            String o1 = (String) _exp1.evaluate();
-            Object o2 = _exp2.evaluate();
-            Object o3 = _exp3.evaluate();
-            String o4 = (String) _exp4.evaluate();
-            
-            boolean leftToRight;
-            if (o4.equals("LeftToRight"))
-            {
-                leftToRight = true;
-            }
-            else if (o4.equals("RightToLeft"))
-            {
-                leftToRight = false;
-            }
-            else
-            {
-
-                logger.severe(
-                "Illegal direction argument.");
-             
-                throw new IllegalArgumentException(
-                        "Illegal direction argument.");
-            }
-            
-            if (o2 instanceof String)
-            {
-                if (o3 instanceof String)
-                {
-                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-                    
-                    return _middleSubstring(o1, (String) o2, (String) o3,
-                            leftToRight);
-                }
-                else
-                {
-                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-                    
-                    return _middleSubstring(o1, (String) o2, ((Number) o3)
-                            .intValue(), leftToRight);
-                }
-            }
-            else
-            {
-                if (o3 instanceof String)
-                {
-                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-                    
-                    return _middleSubstring(o1, ((Number) o2).intValue(),
-                            (String) o3, leftToRight);
-                }
-                else
-                {
-                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-                    
-                    return _middleSubstring(o1, ((Number) o2).intValue(),
-                            ((Number) o3).intValue(), leftToRight);
-                }
-            }
-        }
-        catch (Exception e)
-        {
-            logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString());
-            throw new SPLException("evaluation error: " + e.toString());
-        }
-    }
-    
-    /**
-     * Returns a specified middleSubstring from a string. With StringExpression,
-     * NumericExpression, NumericExpression, and Direction arguments, the
-     * arguments correspond to String, Offset, NumberChars, Direction. Offset
-     * indicates where you want the middle to begin, counting from left to right
-     * if Direction is LeftToRight, or counting from right to left if Direction
-     * is RightToLeft. For Direction LeftToRight, Offset 0 is just before the
-     * first character, offset 1 is between the first and the second character,
-     * and offset -1 is between the next-to-last and last character. For
-     * Direction RightToLeft, Offset 0 is one position after the last character
-     * (after the null character), Offset 1 is between the last character and
-     * the null character, and Offset -1 is between the second character and the
-     * third character. NumberChars indicates the number of characters that you
-     * want in the middle. If NumberChars is negative, the middle starts at
-     * Offset and continues from right to left. If NumberChars is positive, the
-     * middle starts at Offset and continues from left to right. Examples:
-     * MiddleSubstring(AutonomicComputing, 4,5, LeftToRight)=nomic,
-     * MiddleSubstring(AutonomicComputing, 4,5, RightToLeft)=ing,
-     * MiddleSubstring(AutonomicComputing, 4,-1, LeftToRight)=o,
-     * MiddleSubstring(AutonomicComputing, 8,-1, RightToLeft)=u,
-     * MiddleSubstring(AutonomicComputing, -1,5, LeftToRight)=g,
-     * MiddleSubstring(AutonomicComputing, -1,5, RightToLeft)=tonum,
-     * MiddleSubstring(AutonomicComputing, -1,-1, LeftToRight)=n,
-     * MiddleSubstring(AutonomicComputing, -1,-1, RightToLeft)=u,
-     * MiddleSubstring(AutonomicComputing, 19,5, LeftToRight)=,
-     * MiddleSubstring(AutonomicComputing, 19,5, RightToLeft)=Auton. Note that
-     * for MiddleSubstring(AutonomicComputing, -1,5, RightToLeft)=tonum, the
-     * offset is -1 corresponding to between "u" and "t"
-     * (there is an anomoly in the way wrapping occurs for RightToLeft). Then 5
-     * characters are taken from left to right starting at the offset.
-     * 
-     * @param string
-     * @param offset
-     * @param numberChars
-     * @param directionLeftToRight
-     * 
-     * @return the resulting substring
-     */
-    private String _middleSubstring(String string, int offset,
-            int numberChars, boolean directionLeftToRight)
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-
-        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-     
-        
-        int beginning;
-        int end;
-        int offsetpoint;
-        
-        if (directionLeftToRight)
-        {
-            if (offset < 0)
-            {
-                offsetpoint = string.length() + offset;
-                if (offsetpoint < 0)
-                {
-                    offsetpoint = 0;
-                }
-            }
-            else
-            {
-                offsetpoint = offset;
-            }
-        }
-        else
-        {
-            if (offset < 0)
-            {
-                offsetpoint = 1 - offset;
-            }
-            else
-            {
-                offsetpoint = string.length() - offset + 1;
-                if (offsetpoint < 0)
-                {
-                    offsetpoint = 0;
-                }
-            }
-        }
-        if (numberChars < 0)
-        {
-            beginning = offsetpoint + numberChars;
-            end = offsetpoint;
-        }
-        else
-        {
-            beginning = offsetpoint;
-            end = offsetpoint + numberChars;
-        }
-        
-        if (beginning < 0)
-        {
-            beginning = 0;
-        }
-        if (beginning > string.length())
-        {
-            beginning = string.length();
-        }
-        if (end > string.length())
-        {
-            end = string.length();
-        }
-        if (end < 0)
-        {
-            end = 0;
-        }
-        if (beginning > end){
-
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-            return "";
-         
-        }
-           
-
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-         
-        return string.substring(beginning, end);
-    }
-    
-    /**
-     * Returns a specified middleSubstring from a string. With StringExpression,
-     * StringExpression, NumericExpression, and Direction arguments, the
-     * arguments correspond to String, StartString, NumberChars, Direction.
-     * StartString is a string that indicates where you want the middle to
-     * begin, always taking the first occurrence scanning from left to right if
-     * Direction is LeftToRight, or the first occurrence in of the StartString
-     * string scanning from right to left if Direction is RightToLeft. If
-     * NumberChars is positive, the middle starts with the first character
-     * left-to-right after the end of the StartString and continues for
-     * NumberChars characters. If NumberChars is negative, the middle starts
-     * with the first character to the left of the StartString and continues for
-     * NumberChars characters from right-to-left. If the StartString is not
-     * found, an empty string is returned. Examples:
-     * MiddleSubstring("AutonomicComputing", "om",5, LeftToRight)="icCom",
-     * MiddleSubstring("AutonomicComputing", "om",5, RightToLeft)="putin",
-     * MiddleSubstring("AutonomicComputing", "om",18,
-     * LeftToRight)="icComputing", MiddleSubstring("AutonomicComputing",
-     * "om",18, RightToLeft)="puting", MiddleSubstring("AutonomicComputing",
-     * "om",-1, LeftToRight)="", MiddleSubstring("AutonomicComputing", "om",-1,
-     * RightToLeft)="C", MiddleSubstring("AutonomicComputing", "bz",5,
-     * LeftToRight)="", MiddleSubstring("AutonomicComputing", "bz",5,
-     * RightToLeft)="", MiddleSubstring("AutonomicComputing", "bz",-1,
-     * LeftToRight)="", MiddleSubstring("AutonomicComputing", "bz",-1,
-     * RightToLeft)="", MiddleSubstring("AutonomicComputing", "bz",20,
-     * LeftToRight)="", MiddleSubstring("AutonomicComputing", "bz",20,
-     * RightToLeft)="". <br>
-     * 
-     * @param string
-     * @param startString
-     * @param numberChars
-     * @param directionLeftToRight
-     * 
-     * @return the resulting substring
-     */
-    private String _middleSubstring(String string, String startString,
-            int numberChars, boolean directionLeftToRight)
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-
-        
-        int beginning;
-        int end;
-        int offsetpoint; // Position of the beginning of the startString
-        
-        if (directionLeftToRight)
-        {
-            offsetpoint = string.indexOf(startString);
-            if (offsetpoint < 0)
-            {
-                // Did not find the string
-                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-                
-                return "";
-            }
-            if (numberChars < 0)
-            {
-                beginning = offsetpoint + numberChars;
-                end = offsetpoint;
-            }
-            else
-            {
-                offsetpoint += startString.length();
-                beginning = offsetpoint;
-                end = offsetpoint + numberChars;
-            }
-        }
-        else
-        {
-            offsetpoint = string.lastIndexOf(startString);
-            if (offsetpoint < 0)
-            {
-                // Did not find the string
-                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-                
-                return "";
-            }
-            if (numberChars < 0)
-            {
-                beginning = offsetpoint + numberChars;
-                end = offsetpoint;
-            }
-            else
-            {
-                offsetpoint += startString.length();
-                beginning = offsetpoint;
-                end = offsetpoint + numberChars;
-            }
-        }
-        
-        if (beginning < 0)
-        {
-            beginning = 0;
-        }
-        if (beginning > string.length())
-        {
-            beginning = string.length();
-        }
-        if (end > string.length())
-        {
-            end = string.length();
-        }
-        if (end < 0)
-        {
-            end = 0;
-        }
-        if (beginning > end){
-
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-            return "";
-
-         
-        }
-          
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-         
-        return string.substring(beginning, end);
-    }
-    
-    /**
-     * Returns a specified middleSubstring from a string. With StringExpression,
-     * NumericExpression, StringExpression, and Direction arguments, the
-     * arguments correspond to String, Offset, EndString, Direction. Offset
-     * indicates where you want the middle to begin, counting from left to right
-     * if Direction is LeftToRight, or counting from right to left if Direction
-     * is RightToLeft. For Direction LeftToRight, Offset 0 is just before the
-     * first character, offset 1 is between the first and the second character,
-     * and offset -1 is between the next-to-last and last character. For
-     * Direction RightToLeft, Offset 0 is one position after the last character
-     * (after the null character), Offset 1 is between the last character and
-     * the null character, and Offset -1 is between the second character and the
-     * third character. EndString indicates the substring of the string that
-     * indicates the end of the middle and is searched in the given Direction
-     * from OffSet. MiddleSubstring returns all the characters between OffSet
-     * and EndString, not including any of the characters in EndString. If
-     * Direction is LeftToRight and EndString does not exist, then all
-     * characters from offset to the end of the string are returned. If
-     * Direction is RightToLeft and EndString is not found, then the empty
-     * string is returned. Examples: MiddleSubstring(AutonomicComputing, 4,om,
-     * LeftToRight)=n, MiddleSubstring(AutonomicComputing, 4,om,
-     * RightToLeft)=put, MiddleSubstring(AutonomicComputing, 7,om,
-     * LeftToRight)=icC, MiddleSubstring(AutonomicComputing, 7,om,
-     * RightToLeft)=, MiddleSubstring(AutonomicComputing, -1,om, LeftToRight)=g,
-     * MiddleSubstring(AutonomicComputing, -1,om, RightToLeft)=,
-     * MiddleSubstring(AutonomicComputing, -1,bz, LeftToRight)=g,
-     * MiddleSubstring(AutonomicComputing, -1,bz, RightToLeft)=,
-     * MiddleSubstring(AutonomicComputing, 4,bz, LeftToRight)=nomicComputing,
-     * MiddleSubstring(AutonomicComputing, 4,bz, RightToLeft)=,
-     * MiddleSubstring(AutonomicComputing, 20,om, LeftToRight)=,
-     * MiddleSubstring(AutonomicComputing, 20,om, RightToLeft)=,
-     * MiddleSubstring(AutonomicComputing, 20,bz, LeftToRight)=,
-     * MiddleSubstring(AutonomicComputing, 20,bz, RightToLeft)=<br> *
-     * 
-     * @param string
-     * @param offset
-     * @param endString
-     * @param directionLeftToRight
-     * 
-     * @return the resulting substring
-     */
-    private String _middleSubstring(String string, int offset,
-            String endString, boolean directionLeftToRight)
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-
-        
-        int beginning;
-        int end;
-        int offsetpoint;
-        
-        if (directionLeftToRight)
-        {
-            if (offset < 0)
-            {
-                offsetpoint = string.length() + offset;
-                if (offsetpoint < 0)
-                {
-                    offsetpoint = 0;
-                }
-            }
-            else
-            {
-                offsetpoint = offset;
-            }
-            if (offset > string.length()){
-
-                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-          
-                return "";
-            }
-            beginning = offsetpoint;
-            
-            end = string.indexOf(endString, offsetpoint);
-            if (end < 0)
-            {
-                end = string.length();
-            }
-            
-        }
-        else
-        {
-            if (offset < 0)
-            {
-                offsetpoint = 1 - offset;
-            }
-            else
-            {
-                offsetpoint = string.length() - offset;
-                if (offsetpoint < 0)
-                {
-                    offsetpoint = 0;
-                }
-            }
-            end = offsetpoint;
-            if (end < 0)
-            {
-                end = 0;
-            }
-            
-            int endStringLocation = string.lastIndexOf(endString, end);
-            if (endStringLocation < 0)
-            {
-                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-                
-                return "";
-            }
-            else
-            {
-                endStringLocation += endString.length();
-                if (endStringLocation > end)
-                {
-                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-                    
-                    return "";
-                }
-                else
-                {
-                    beginning = endStringLocation;
-                }
-            }
-        }
-        
-        if (beginning < 0)
-        {
-            beginning = 0;
-        }
-        if (beginning > string.length())
-        {
-            beginning = string.length();
-        }
-        if (end > string.length())
-        {
-            end = string.length();
-        }
-        if (end < 0)
-        {
-            end = 0;
-        }
-        if (beginning > end){
-
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-            return "";
-         
-        }
-           
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-            
-        return string.substring(beginning, end);
-    }
-    
-    /**
-     * Returns a specified middleSubstring from a string. With StringExpression,
-     * StringExpression, StringExpression, and Direction arguments, the
-     * arguments correspond to String, StartString, EndString, Direction.
-     * StartString is a string that indicates where you want the middle to
-     * begin, always taking the first occurrence scanning from left to right if
-     * Direction is LeftToRight, or the first occurrence in of the StartString
-     * string scanning from right to left if Direction is RightToLeft. The
-     * middle begins at the first character after the end of StartString in the
-     * given Direction. EndString indicates the substring of the string that
-     * indicates the end of the middle and is searched in the given Direction
-     * from StartString. MiddleSubstring returns all the characters between
-     * StartString and EndString, not including the StartString or EndString
-     * characters. If StartString is not found, an empty string is returned. If
-     * Direction is LeftToRight and EndString does not exist, then all
-     * characters from offset to the end of the string are returned. If
-     * Direction is RightToLeft and EndString is not found, all characters to
-     * the left of StartString are returned. Examples:
-     * MiddleSubstring(AutonomicComputing, om, om, LeftToRight)=icC,
-     * MiddleSubstring(AutonomicComputing, om, om, RightToLeft)=icC,
-     * MiddleSubstring(AutonomicComputing, bz, om, LeftToRight)=,
-     * MiddleSubstring(AutonomicComputing, bz, om, RightToLeft)=,
-     * MiddleSubstring(AutonomicComputing, om, bz, LeftToRight)=icComputing,
-     * MiddleSubstring(AutonomicComputing, om, bz, RightToLeft)=AutonomicC,
-     * MiddleSubstring(AutonomicComputing, bz, bz, LeftToRight)=,
-     * MiddleSubstring(AutonomicComputing, bz, bz, RightToLeft)=,
-     * MiddleSubstring(AutonomicComputing, om, icC, LeftToRight)=,
-     * MiddleSubstring(AutonomicComputing, om, icC, RightToLeft)=icC.
-     * <p>
-     * 
-     * @param string
-     * @param startString
-     * @param endString
-     * @param directionLeftToRight
-     * 
-     * @return the resulting substring
-     */
-    private String _middleSubstring(String string, String startString,
-            String endString, boolean directionLeftToRight)
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-
-        
-        int beginning;
-        int end;
-        int offsetpoint; // Position of the beginning of the startString
-        
-        if (directionLeftToRight)
-        {
-            offsetpoint = string.indexOf(startString);
-            if (offsetpoint < 0)
-            {
-                // Did not find the string
-                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-                
-                return "";
-            }
-            offsetpoint += startString.length();
-            beginning = offsetpoint;
-            end = string.indexOf(endString, offsetpoint);
-            if (end < 0)
-            {
-                // did not find endString
-                end = string.length();
-            }
-        }
-        else
-        {
-            offsetpoint = string.lastIndexOf(startString);
-            if (offsetpoint < 0)
-            {
-                // Did not find the startString
-                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-                
-                return "";
-            }
-            end = offsetpoint;
-            if (offsetpoint < endString.length())
-            {
-                beginning = 0;
-            }
-            else
-            {
-                beginning = string.lastIndexOf(endString, offsetpoint
-                        - endString.length());
-                if (beginning < 0)
-                {
-                    // Did not find end string
-                    beginning = 0;
-                }
-                else
-                {
-                    beginning += endString.length();
-                }
-            }
-        }
-        
-        if (beginning < 0)
-        {
-            beginning = 0;
-        }
-        if (beginning > string.length())
-        {
-            beginning = string.length();
-        }
-        if (end > string.length())
-        {
-            end = string.length();
-        }
-        if (end < 0)
-        {
-            end = 0;
-        }
-        if (beginning > end){
-
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-            return "";
-         
-        }
-        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
-           
-        return string.substring(beginning, end);
-    }
-    
-    public boolean validate() throws SPLException
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
-
-        TypeInfo eType1 = _exp1.getType();
-        TypeInfo eType2 = _exp2.getType();
-        TypeInfo eType3 = _exp3.getType();
-        TypeInfo eType4 = _exp4.getType();
-        
-        if ((TypeResolver.isString(eType1) && TypeResolver.isNumeric(eType2)
-                && TypeResolver.isNumeric(eType3) && TypeResolver
-                .isString(eType4))
-                || (TypeResolver.isString(eType1)
-                        && TypeResolver.isNumeric(eType2)
-                        && TypeResolver.isString(eType3) && TypeResolver
-                        .isString(eType4))
-                || (TypeResolver.isString(eType1)
-                        && TypeResolver.isString(eType2)
-                        && TypeResolver.isNumeric(eType3) && TypeResolver
-                        .isString(eType4))
-                || (TypeResolver.isString(eType1)
-                        && TypeResolver.isString(eType2)
-                        && TypeResolver.isString(eType3) && TypeResolver
-                        .isString(eType4)))
-        {
-            _dataType.setType(TypeConstants.stringType);
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
-            
-            return true;
-        }
-
-        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
-     
-        return false;
-    }
-    
-    public String toString()
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
-
-        String str = "MiddleSubstring(" + this._exp1.toString() + ","
-				+ this._exp2.toString() + "," + this._exp3.toString() + ","
-				+ this._exp4.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 Xiping Wang
+ *
+ */
+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.QuadrupleArgumentExpression;
+import org.apache.imperius.spl.parser.expressions.StringExpression;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.spl.parser.util.TypeResolver;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class MiddleSubstring extends QuadrupleArgumentExpression implements
+        StringExpression
+{
+    
+    public static final String className = MiddleSubstring.class.getName();
+    
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+    private static final String sourceClass="MiddleSubstring";
+    
+    
+    
+    public MiddleSubstring(List exprList, boolean validateExpression)
+            throws SPLException
+    {
+        super(exprList);
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MiddleSubstring");
+
+        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.");
+            }
+        }
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MiddleSubstring");
+        
+    }
+    
+    public Object evaluate() throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+        try
+        {
+            String o1 = (String) _exp1.evaluate();
+            Object o2 = _exp2.evaluate();
+            Object o3 = _exp3.evaluate();
+            String o4 = (String) _exp4.evaluate();
+            
+            boolean leftToRight;
+            if (o4.equals("LeftToRight"))
+            {
+                leftToRight = true;
+            }
+            else if (o4.equals("RightToLeft"))
+            {
+                leftToRight = false;
+            }
+            else
+            {
+
+                logger.severe(
+                "Illegal direction argument.");
+             
+                throw new IllegalArgumentException(
+                        "Illegal direction argument.");
+            }
+            
+            if (o2 instanceof String)
+            {
+                if (o3 instanceof String)
+                {
+                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+                    
+                    return _middleSubstring(o1, (String) o2, (String) o3,
+                            leftToRight);
+                }
+                else
+                {
+                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+                    
+                    return _middleSubstring(o1, (String) o2, ((Number) o3)
+                            .intValue(), leftToRight);
+                }
+            }
+            else
+            {
+                if (o3 instanceof String)
+                {
+                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+                    
+                    return _middleSubstring(o1, ((Number) o2).intValue(),
+                            (String) o3, leftToRight);
+                }
+                else
+                {
+                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+                    
+                    return _middleSubstring(o1, ((Number) o2).intValue(),
+                            ((Number) o3).intValue(), leftToRight);
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString());
+            throw new SPLException("evaluation error: " + e.toString());
+        }
+    }
+    
+    /**
+     * Returns a specified middleSubstring from a string. With StringExpression,
+     * NumericExpression, NumericExpression, and Direction arguments, the
+     * arguments correspond to String, Offset, NumberChars, Direction. Offset
+     * indicates where you want the middle to begin, counting from left to right
+     * if Direction is LeftToRight, or counting from right to left if Direction
+     * is RightToLeft. For Direction LeftToRight, Offset 0 is just before the
+     * first character, offset 1 is between the first and the second character,
+     * and offset -1 is between the next-to-last and last character. For
+     * Direction RightToLeft, Offset 0 is one position after the last character
+     * (after the null character), Offset 1 is between the last character and
+     * the null character, and Offset -1 is between the second character and the
+     * third character. NumberChars indicates the number of characters that you
+     * want in the middle. If NumberChars is negative, the middle starts at
+     * Offset and continues from right to left. If NumberChars is positive, the
+     * middle starts at Offset and continues from left to right. Examples:
+     * MiddleSubstring(AutonomicComputing, 4,5, LeftToRight)=nomic,
+     * MiddleSubstring(AutonomicComputing, 4,5, RightToLeft)=ing,
+     * MiddleSubstring(AutonomicComputing, 4,-1, LeftToRight)=o,
+     * MiddleSubstring(AutonomicComputing, 8,-1, RightToLeft)=u,
+     * MiddleSubstring(AutonomicComputing, -1,5, LeftToRight)=g,
+     * MiddleSubstring(AutonomicComputing, -1,5, RightToLeft)=tonum,
+     * MiddleSubstring(AutonomicComputing, -1,-1, LeftToRight)=n,
+     * MiddleSubstring(AutonomicComputing, -1,-1, RightToLeft)=u,
+     * MiddleSubstring(AutonomicComputing, 19,5, LeftToRight)=,
+     * MiddleSubstring(AutonomicComputing, 19,5, RightToLeft)=Auton. Note that
+     * for MiddleSubstring(AutonomicComputing, -1,5, RightToLeft)=tonum, the
+     * offset is -1 corresponding to between &quot;u&quot; and &quot;t&quot;
+     * (there is an anomoly in the way wrapping occurs for RightToLeft). Then 5
+     * characters are taken from left to right starting at the offset.
+     * 
+     * @param string
+     * @param offset
+     * @param numberChars
+     * @param directionLeftToRight
+     * 
+     * @return the resulting substring
+     */
+    private String _middleSubstring(String string, int offset,
+            int numberChars, boolean directionLeftToRight)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+     
+        
+        int beginning;
+        int end;
+        int offsetpoint;
+        
+        if (directionLeftToRight)
+        {
+            if (offset < 0)
+            {
+                offsetpoint = string.length() + offset;
+                if (offsetpoint < 0)
+                {
+                    offsetpoint = 0;
+                }
+            }
+            else
+            {
+                offsetpoint = offset;
+            }
+        }
+        else
+        {
+            if (offset < 0)
+            {
+                offsetpoint = 1 - offset;
+            }
+            else
+            {
+                offsetpoint = string.length() - offset + 1;
+                if (offsetpoint < 0)
+                {
+                    offsetpoint = 0;
+                }
+            }
+        }
+        if (numberChars < 0)
+        {
+            beginning = offsetpoint + numberChars;
+            end = offsetpoint;
+        }
+        else
+        {
+            beginning = offsetpoint;
+            end = offsetpoint + numberChars;
+        }
+        
+        if (beginning < 0)
+        {
+            beginning = 0;
+        }
+        if (beginning > string.length())
+        {
+            beginning = string.length();
+        }
+        if (end > string.length())
+        {
+            end = string.length();
+        }
+        if (end < 0)
+        {
+            end = 0;
+        }
+        if (beginning > end){
+
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+            return "";
+         
+        }
+           
+
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+         
+        return string.substring(beginning, end);
+    }
+    
+    /**
+     * Returns a specified middleSubstring from a string. With StringExpression,
+     * StringExpression, NumericExpression, and Direction arguments, the
+     * arguments correspond to String, StartString, NumberChars, Direction.
+     * StartString is a string that indicates where you want the middle to
+     * begin, always taking the first occurrence scanning from left to right if
+     * Direction is LeftToRight, or the first occurrence in of the StartString
+     * string scanning from right to left if Direction is RightToLeft. If
+     * NumberChars is positive, the middle starts with the first character
+     * left-to-right after the end of the StartString and continues for
+     * NumberChars characters. If NumberChars is negative, the middle starts
+     * with the first character to the left of the StartString and continues for
+     * NumberChars characters from right-to-left. If the StartString is not
+     * found, an empty string is returned. Examples:
+     * MiddleSubstring("AutonomicComputing", "om",5, LeftToRight)="icCom",
+     * MiddleSubstring("AutonomicComputing", "om",5, RightToLeft)="putin",
+     * MiddleSubstring("AutonomicComputing", "om",18,
+     * LeftToRight)="icComputing", MiddleSubstring("AutonomicComputing",
+     * "om",18, RightToLeft)="puting", MiddleSubstring("AutonomicComputing",
+     * "om",-1, LeftToRight)="", MiddleSubstring("AutonomicComputing", "om",-1,
+     * RightToLeft)="C", MiddleSubstring("AutonomicComputing", "bz",5,
+     * LeftToRight)="", MiddleSubstring("AutonomicComputing", "bz",5,
+     * RightToLeft)="", MiddleSubstring("AutonomicComputing", "bz",-1,
+     * LeftToRight)="", MiddleSubstring("AutonomicComputing", "bz",-1,
+     * RightToLeft)="", MiddleSubstring("AutonomicComputing", "bz",20,
+     * LeftToRight)="", MiddleSubstring("AutonomicComputing", "bz",20,
+     * RightToLeft)="". <br>
+     * 
+     * @param string
+     * @param startString
+     * @param numberChars
+     * @param directionLeftToRight
+     * 
+     * @return the resulting substring
+     */
+    private String _middleSubstring(String string, String startString,
+            int numberChars, boolean directionLeftToRight)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+
+        
+        int beginning;
+        int end;
+        int offsetpoint; // Position of the beginning of the startString
+        
+        if (directionLeftToRight)
+        {
+            offsetpoint = string.indexOf(startString);
+            if (offsetpoint < 0)
+            {
+                // Did not find the string
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+                
+                return "";
+            }
+            if (numberChars < 0)
+            {
+                beginning = offsetpoint + numberChars;
+                end = offsetpoint;
+            }
+            else
+            {
+                offsetpoint += startString.length();
+                beginning = offsetpoint;
+                end = offsetpoint + numberChars;
+            }
+        }
+        else
+        {
+            offsetpoint = string.lastIndexOf(startString);
+            if (offsetpoint < 0)
+            {
+                // Did not find the string
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+                
+                return "";
+            }
+            if (numberChars < 0)
+            {
+                beginning = offsetpoint + numberChars;
+                end = offsetpoint;
+            }
+            else
+            {
+                offsetpoint += startString.length();
+                beginning = offsetpoint;
+                end = offsetpoint + numberChars;
+            }
+        }
+        
+        if (beginning < 0)
+        {
+            beginning = 0;
+        }
+        if (beginning > string.length())
+        {
+            beginning = string.length();
+        }
+        if (end > string.length())
+        {
+            end = string.length();
+        }
+        if (end < 0)
+        {
+            end = 0;
+        }
+        if (beginning > end){
+
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+            return "";
+
+         
+        }
+          
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+         
+        return string.substring(beginning, end);
+    }
+    
+    /**
+     * Returns a specified middleSubstring from a string. With StringExpression,
+     * NumericExpression, StringExpression, and Direction arguments, the
+     * arguments correspond to String, Offset, EndString, Direction. Offset
+     * indicates where you want the middle to begin, counting from left to right
+     * if Direction is LeftToRight, or counting from right to left if Direction
+     * is RightToLeft. For Direction LeftToRight, Offset 0 is just before the
+     * first character, offset 1 is between the first and the second character,
+     * and offset -1 is between the next-to-last and last character. For
+     * Direction RightToLeft, Offset 0 is one position after the last character
+     * (after the null character), Offset 1 is between the last character and
+     * the null character, and Offset -1 is between the second character and the
+     * third character. EndString indicates the substring of the string that
+     * indicates the end of the middle and is searched in the given Direction
+     * from OffSet. MiddleSubstring returns all the characters between OffSet
+     * and EndString, not including any of the characters in EndString. If
+     * Direction is LeftToRight and EndString does not exist, then all
+     * characters from offset to the end of the string are returned. If
+     * Direction is RightToLeft and EndString is not found, then the empty
+     * string is returned. Examples: MiddleSubstring(AutonomicComputing, 4,om,
+     * LeftToRight)=n, MiddleSubstring(AutonomicComputing, 4,om,
+     * RightToLeft)=put, MiddleSubstring(AutonomicComputing, 7,om,
+     * LeftToRight)=icC, MiddleSubstring(AutonomicComputing, 7,om,
+     * RightToLeft)=, MiddleSubstring(AutonomicComputing, -1,om, LeftToRight)=g,
+     * MiddleSubstring(AutonomicComputing, -1,om, RightToLeft)=,
+     * MiddleSubstring(AutonomicComputing, -1,bz, LeftToRight)=g,
+     * MiddleSubstring(AutonomicComputing, -1,bz, RightToLeft)=,
+     * MiddleSubstring(AutonomicComputing, 4,bz, LeftToRight)=nomicComputing,
+     * MiddleSubstring(AutonomicComputing, 4,bz, RightToLeft)=,
+     * MiddleSubstring(AutonomicComputing, 20,om, LeftToRight)=,
+     * MiddleSubstring(AutonomicComputing, 20,om, RightToLeft)=,
+     * MiddleSubstring(AutonomicComputing, 20,bz, LeftToRight)=,
+     * MiddleSubstring(AutonomicComputing, 20,bz, RightToLeft)=<br> *
+     * 
+     * @param string
+     * @param offset
+     * @param endString
+     * @param directionLeftToRight
+     * 
+     * @return the resulting substring
+     */
+    private String _middleSubstring(String string, int offset,
+            String endString, boolean directionLeftToRight)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+
+        
+        int beginning;
+        int end;
+        int offsetpoint;
+        
+        if (directionLeftToRight)
+        {
+            if (offset < 0)
+            {
+                offsetpoint = string.length() + offset;
+                if (offsetpoint < 0)
+                {
+                    offsetpoint = 0;
+                }
+            }
+            else
+            {
+                offsetpoint = offset;
+            }
+            if (offset > string.length()){
+
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+          
+                return "";
+            }
+            beginning = offsetpoint;
+            
+            end = string.indexOf(endString, offsetpoint);
+            if (end < 0)
+            {
+                end = string.length();
+            }
+            
+        }
+        else
+        {
+            if (offset < 0)
+            {
+                offsetpoint = 1 - offset;
+            }
+            else
+            {
+                offsetpoint = string.length() - offset;
+                if (offsetpoint < 0)
+                {
+                    offsetpoint = 0;
+                }
+            }
+            end = offsetpoint;
+            if (end < 0)
+            {
+                end = 0;
+            }
+            
+            int endStringLocation = string.lastIndexOf(endString, end);
+            if (endStringLocation < 0)
+            {
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+                
+                return "";
+            }
+            else
+            {
+                endStringLocation += endString.length();
+                if (endStringLocation > end)
+                {
+                    logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+                    
+                    return "";
+                }
+                else
+                {
+                    beginning = endStringLocation;
+                }
+            }
+        }
+        
+        if (beginning < 0)
+        {
+            beginning = 0;
+        }
+        if (beginning > string.length())
+        {
+            beginning = string.length();
+        }
+        if (end > string.length())
+        {
+            end = string.length();
+        }
+        if (end < 0)
+        {
+            end = 0;
+        }
+        if (beginning > end){
+
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+            return "";
+         
+        }
+           
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+            
+        return string.substring(beginning, end);
+    }
+    
+    /**
+     * Returns a specified middleSubstring from a string. With StringExpression,
+     * StringExpression, StringExpression, and Direction arguments, the
+     * arguments correspond to String, StartString, EndString, Direction.
+     * StartString is a string that indicates where you want the middle to
+     * begin, always taking the first occurrence scanning from left to right if
+     * Direction is LeftToRight, or the first occurrence in of the StartString
+     * string scanning from right to left if Direction is RightToLeft. The
+     * middle begins at the first character after the end of StartString in the
+     * given Direction. EndString indicates the substring of the string that
+     * indicates the end of the middle and is searched in the given Direction
+     * from StartString. MiddleSubstring returns all the characters between
+     * StartString and EndString, not including the StartString or EndString
+     * characters. If StartString is not found, an empty string is returned. If
+     * Direction is LeftToRight and EndString does not exist, then all
+     * characters from offset to the end of the string are returned. If
+     * Direction is RightToLeft and EndString is not found, all characters to
+     * the left of StartString are returned. Examples:
+     * MiddleSubstring(AutonomicComputing, om, om, LeftToRight)=icC,
+     * MiddleSubstring(AutonomicComputing, om, om, RightToLeft)=icC,
+     * MiddleSubstring(AutonomicComputing, bz, om, LeftToRight)=,
+     * MiddleSubstring(AutonomicComputing, bz, om, RightToLeft)=,
+     * MiddleSubstring(AutonomicComputing, om, bz, LeftToRight)=icComputing,
+     * MiddleSubstring(AutonomicComputing, om, bz, RightToLeft)=AutonomicC,
+     * MiddleSubstring(AutonomicComputing, bz, bz, LeftToRight)=,
+     * MiddleSubstring(AutonomicComputing, bz, bz, RightToLeft)=,
+     * MiddleSubstring(AutonomicComputing, om, icC, LeftToRight)=,
+     * MiddleSubstring(AutonomicComputing, om, icC, RightToLeft)=icC.
+     * <p>
+     * 
+     * @param string
+     * @param startString
+     * @param endString
+     * @param directionLeftToRight
+     * 
+     * @return the resulting substring
+     */
+    private String _middleSubstring(String string, String startString,
+            String endString, boolean directionLeftToRight)
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+
+        
+        int beginning;
+        int end;
+        int offsetpoint; // Position of the beginning of the startString
+        
+        if (directionLeftToRight)
+        {
+            offsetpoint = string.indexOf(startString);
+            if (offsetpoint < 0)
+            {
+                // Did not find the string
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+                
+                return "";
+            }
+            offsetpoint += startString.length();
+            beginning = offsetpoint;
+            end = string.indexOf(endString, offsetpoint);
+            if (end < 0)
+            {
+                // did not find endString
+                end = string.length();
+            }
+        }
+        else
+        {
+            offsetpoint = string.lastIndexOf(startString);
+            if (offsetpoint < 0)
+            {
+                // Did not find the startString
+                logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+                
+                return "";
+            }
+            end = offsetpoint;
+            if (offsetpoint < endString.length())
+            {
+                beginning = 0;
+            }
+            else
+            {
+                beginning = string.lastIndexOf(endString, offsetpoint
+                        - endString.length());
+                if (beginning < 0)
+                {
+                    // Did not find end string
+                    beginning = 0;
+                }
+                else
+                {
+                    beginning += endString.length();
+                }
+            }
+        }
+        
+        if (beginning < 0)
+        {
+            beginning = 0;
+        }
+        if (beginning > string.length())
+        {
+            beginning = string.length();
+        }
+        if (end > string.length())
+        {
+            end = string.length();
+        }
+        if (end < 0)
+        {
+            end = 0;
+        }
+        if (beginning > end){
+
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+            return "";
+         
+        }
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "middleSubstring");
+           
+        return string.substring(beginning, end);
+    }
+    
+    public boolean validate() throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+        TypeInfo eType1 = _exp1.getType();
+        TypeInfo eType2 = _exp2.getType();
+        TypeInfo eType3 = _exp3.getType();
+        TypeInfo eType4 = _exp4.getType();
+        
+        if ((TypeResolver.isString(eType1) && TypeResolver.isNumeric(eType2)
+                && TypeResolver.isNumeric(eType3) && TypeResolver
+                .isString(eType4))
+                || (TypeResolver.isString(eType1)
+                        && TypeResolver.isNumeric(eType2)
+                        && TypeResolver.isString(eType3) && TypeResolver
+                        .isString(eType4))
+                || (TypeResolver.isString(eType1)
+                        && TypeResolver.isString(eType2)
+                        && TypeResolver.isNumeric(eType3) && TypeResolver
+                        .isString(eType4))
+                || (TypeResolver.isString(eType1)
+                        && TypeResolver.isString(eType2)
+                        && TypeResolver.isString(eType3) && TypeResolver
+                        .isString(eType4)))
+        {
+            _dataType.setType(TypeConstants.stringType);
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+            
+            return true;
+        }
+
+        logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+     
+        return false;
+    }
+    
+    public String toString()
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+        String str = "MiddleSubstring(" + this._exp1.toString() + ","
+				+ this._exp2.toString() + "," + this._exp3.toString() + ","
+				+ this._exp4.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/MiddleSubstring.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Min.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Min.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Min.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/Min.java Fri Jan 11 10:56:30 2008
@@ -1,160 +1,160 @@
-/*
- * 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;
-
-
-/**
- * 
- * @author Xiping Change Log: 1. 3/9/07: Neeraj Joshi: Changed constructor to
- *         take a list to facilitate reflection in the expression factory 2.
- *         3/9/07: Neeraj Joshi: Changed the method in which the return type is
- *         determined
- * 
- */
-public class Min extends MultipleArgumentExpression implements
-        NumericExpression
-{
-    
-    public static final String className = Min.class.getName();
-    
-    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-    private static final String sourceClass="Min";
-    
-    
-    
-    public Min(List exprList, boolean validateExpression)
-            throws SPLException
-    {
-        super(exprList);
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Min");
-
-        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()+" "+ "Min");
-        
-    }
-    
-    public Object evaluate() throws SPLException
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-
-        try
-        {
-            Iterator expIterator = this._expressions.iterator();
-            Number min = null;
-            while (expIterator.hasNext())
-            {
-                Expression exp = (Expression) expIterator.next();
-                Number evalResult = (Number) exp.evaluate();
-                
-                if (min == null)
-                {
-                    min = evalResult;
-                }
-                else
-                {
-                    if (ExpressionUtility.compare(evalResult, min) < 0)
-                    {
-                        min = evalResult;
-                    }
-                }
-            }
-
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-         
-            return min;
-            
-        }
-        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();
-        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 = "MIN[ ";
-        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;
+
+
+/**
+ * 
+ * @author Xiping Change Log: 1. 3/9/07: Neeraj Joshi: Changed constructor to
+ *         take a list to facilitate reflection in the expression factory 2.
+ *         3/9/07: Neeraj Joshi: Changed the method in which the return type is
+ *         determined
+ * 
+ */
+public class Min extends MultipleArgumentExpression implements
+        NumericExpression
+{
+    
+    public static final String className = Min.class.getName();
+    
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+    private static final String sourceClass="Min";
+    
+    
+    
+    public Min(List exprList, boolean validateExpression)
+            throws SPLException
+    {
+        super(exprList);
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Min");
+
+        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()+" "+ "Min");
+        
+    }
+    
+    public Object evaluate() throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+        try
+        {
+            Iterator expIterator = this._expressions.iterator();
+            Number min = null;
+            while (expIterator.hasNext())
+            {
+                Expression exp = (Expression) expIterator.next();
+                Number evalResult = (Number) exp.evaluate();
+                
+                if (min == null)
+                {
+                    min = evalResult;
+                }
+                else
+                {
+                    if (ExpressionUtility.compare(evalResult, min) < 0)
+                    {
+                        min = evalResult;
+                    }
+                }
+            }
+
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+         
+            return min;
+            
+        }
+        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();
+        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 = "MIN[ ";
+        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/Min.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MinInCollection.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MinInCollection.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MinInCollection.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/MinInCollection.java Fri Jan 11 10:56:30 2008
@@ -1,172 +1,172 @@
-/*
- * 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 <prabalig@in.ibm.com>
- *
- */
-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 MinInCollection extends SingleArgumentExpression implements
-        Expression
-{
-    
-    public String className = MinInCollection.class.toString();
-    
-    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-    private static final String sourceClass="MinInCollection";
-    
-    
-    
-    public MinInCollection(List exprList, boolean evaluateExpression)
-            throws SPLException
-    {
-        super(exprList);
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MinInCollection");
-
-       //System.out.println("MinInCollection");
-        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()+" "+ "MinInCollection");
-        
-        
-    }
-    
-    public Object evaluate() throws SPLException
-    {
-        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-       //System.out.println("MinInCollection: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 minimum = 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 (minimum == null)
-                {
-                    minimum = resultObject;
-                }
-                
-                if (ExpressionUtility.compare(minimum, resultObject) > 0)
-                {
-                   //System.out.println("resultObject " + resultObject+ " is lesser than minimum " + minimum+ "   so resetting minimum");
-                    minimum = resultObject;
-                }
-                else
-                {
-                   //System.out.println("resultObject " + resultObject + " minimum not reset" + minimum);
-                    
-                }
-                
-            }
-           //System.out.println(minimum);
-            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-            
-            return minimum;
-        }
-        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("MinInCollection : 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="MinInCollection("+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 <prabalig@in.ibm.com>
+ *
+ */
+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 MinInCollection extends SingleArgumentExpression implements
+        Expression
+{
+    
+    public String className = MinInCollection.class.toString();
+    
+    private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+    private static final String sourceClass="MinInCollection";
+    
+    
+    
+    public MinInCollection(List exprList, boolean evaluateExpression)
+            throws SPLException
+    {
+        super(exprList);
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MinInCollection");
+
+       //System.out.println("MinInCollection");
+        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()+" "+ "MinInCollection");
+        
+        
+    }
+    
+    public Object evaluate() throws SPLException
+    {
+        logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+       //System.out.println("MinInCollection: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 minimum = 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 (minimum == null)
+                {
+                    minimum = resultObject;
+                }
+                
+                if (ExpressionUtility.compare(minimum, resultObject) > 0)
+                {
+                   //System.out.println("resultObject " + resultObject+ " is lesser than minimum " + minimum+ "   so resetting minimum");
+                    minimum = resultObject;
+                }
+                else
+                {
+                   //System.out.println("resultObject " + resultObject + " minimum not reset" + minimum);
+                    
+                }
+                
+            }
+           //System.out.println(minimum);
+            logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+            
+            return minimum;
+        }
+        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("MinInCollection : 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="MinInCollection("+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/MinInCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message