/////////////////////////////////////////////////////////////////////////////
// This file is part of the "Java-DAP" project, a Java implementation
// of the OPeNDAP Data Access Protocol.
//
// Copyright (c) 2010, OPeNDAP, Inc.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
//
// Author: James Gallagher <jgallagher@opendap.org>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms,
// with or without modification, are permitted provided
// that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the
//   documentation and/or other materials provided with the distribution.
//
// - Neither the name of the OPeNDAP nor the names of its contributors may
//   be used to endorse or promote products derived from this software
//   without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/////////////////////////////////////////////////////////////////////////////

package opendap.servers;

import opendap.servers.parsers.ExprParserConstants;
import opendap.dap.*;
//import gnu.regexp.*;
import java.util.regex.*;

/**
 * This class contains the code for performing relative
 * operations (RelOps) on BaseTypes. It contains one
 * heavily overloaded method that is smart enough to figure
 * out which actual BaseType were passed in and perform (if
 * appropriate) the RelOp comparison on the 2 types.
 *
 * @author ndp
 * @version $Revision: 22540 $
 */

public class Operator implements ExprParserConstants
{

    private static boolean _Debug = false;

    /**
     * Performs the Relatove Operation (RelOp) indicated by the
     * parameter oprtr on the 2 passed BaseTypes if
     * appropriate.
     *

     * Obviously some type don't compare logically, such as asking if
     * String is less than a Float. For these non sensical operations
     * and InvalidOperatorException is thrown.
     *
     * @param oprtr The operatoration to perform as defined in
     *              opendap.servers.parsers.ExprParserConstants
     * @param lop   A BaseType to be used as the left operand.
     * @param rop   A BaseType to be used as the right operand.
     * @return True is the operation evaluates as true, flase otherwise.
     * @throws InvalidOperatorException
     * @throws RegExpException
     * @throws SBHException
     * @see opendap.servers.parsers.ExprParserConstants
     */
    public static boolean op(int oprtr, BaseType lop, BaseType rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        if (lop instanceof DByte)
            return (op(oprtr, (DByte) lop, rop));
        else if (lop instanceof DFloat32)
            return (op(oprtr, (DFloat32) lop, rop));
        else if (lop instanceof DFloat64)
            return (op(oprtr, (DFloat64) lop, rop));
        else if (lop instanceof DInt16)
            return (op(oprtr, (DInt16) lop, rop));
        else if (lop instanceof DInt32)
            return (op(oprtr, (DInt32) lop, rop));
        else if (lop instanceof DString)
            return (op(oprtr, (DString) lop, rop));
        else if (lop instanceof DUInt16)
            return (op(oprtr, (DUInt16) lop, rop));
        else if (lop instanceof DUInt32)
            return (op(oprtr, (DUInt32) lop, rop));
        else if (lop instanceof DURL)
            return (op(oprtr, (DURL) lop, rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DByte lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DFloat32 lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DFloat64 lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DInt16 lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DInt32 lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DString lop, BaseType rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DUInt16 lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DUInt32 lop, BaseType rop) throws InvalidOperatorException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

    private static boolean op(int oprtr, DURL lop, BaseType rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        if (rop instanceof DByte)
            return (op(oprtr, lop, (DByte) rop));
        else if (rop instanceof DFloat32)
            return (op(oprtr, lop, (DFloat32) rop));
        else if (rop instanceof DFloat64)
            return (op(oprtr, lop, (DFloat64) rop));
        else if (rop instanceof DInt16)
            return (op(oprtr, lop, (DInt16) rop));
        else if (rop instanceof DInt32)
            return (op(oprtr, lop, (DInt32) rop));
        else if (rop instanceof DString)
            return (op(oprtr, lop, (DString) rop));
        else if (rop instanceof DUInt16)
            return (op(oprtr, lop, (DUInt16) rop));
        else if (rop instanceof DUInt32)
            return (op(oprtr, lop, (DUInt32) rop));
        else if (rop instanceof DURL)
            return (op(oprtr, lop, (DURL) rop));
        else
            throw new InvalidOperatorException("Binary operations not supported for the type:" + lop.getClass());
    }

//******************************************************************************************
//******************************************************************************************
//******************************************************************************************
//******************************************************************************************

    private static String opErrorMsg(int oprtr, String lop, String rop) {
        switch (oprtr) {
            case LESS:
                return ("Less Than (<) Operator not valid between types" + lop + "and" + rop + ".");
            case LESS_EQL:
                return ("Less Than Equal To (<=) Operator not valid between types" + lop + "and" + rop + ".");
            case GREATER:
                return ("Greater Than (>) Operator not valid between types" + lop + "and" + rop + ".");
            case GREATER_EQL:
                return ("Greater Than Equal To (>=) Operator not valid between types" + lop + "and" + rop + ".");
            case EQUAL:
                return ("Equal To (==) Operator not valid between types" + lop + "and" + rop + ".");
            case NOT_EQUAL:
                return ("Not Equal To (!=) Operator not valid between types" + lop + "and" + rop + ".");
            case REGEXP:
                return ("Regular Expression cannot beevaluated between types" + lop + "and" + rop + ".");
            default:
                return ("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              Byte Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DByte lop, DByte rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        int rval = ((int) rop.getValue()) & 0xFF;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DFloat32 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DFloat64 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DInt16 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DInt32 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DUInt16 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DUInt32 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFF;
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DByte lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              Float32 Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DFloat32 lop, DByte rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DFloat32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DFloat64 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DUInt16 rop) throws InvalidOperatorException {
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DUInt32 rop) throws InvalidOperatorException {
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat32 lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              Float64 Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DFloat64 lop, DByte rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DFloat32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DFloat64 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DUInt16 rop) throws InvalidOperatorException {
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DUInt32 rop) throws InvalidOperatorException {
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DFloat64 lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              Int16 Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DInt16 lop, DByte rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DFloat32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DFloat64 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DUInt16 rop) throws InvalidOperatorException {
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DUInt32 rop) throws InvalidOperatorException {
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt16 lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              Int32 Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DInt32 lop, DByte rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DFloat32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DFloat64 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rop.getValue());
            case LESS_EQL:
                return (lop.getValue() <= rop.getValue());
            case GREATER:
                return (lop.getValue() > rop.getValue());
            case GREATER_EQL:
                return (lop.getValue() >= rop.getValue());
            case EQUAL:
                return (lop.getValue() == rop.getValue());
            case NOT_EQUAL:
                return (lop.getValue() != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DUInt16 rop) throws InvalidOperatorException {
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DUInt32 rop) throws InvalidOperatorException {
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lop.getValue() < rval);
            case LESS_EQL:
                return (lop.getValue() <= rval);
            case GREATER:
                return (lop.getValue() > rval);
            case GREATER_EQL:
                return (lop.getValue() >= rval);
            case EQUAL:
                return (lop.getValue() == rval);
            case NOT_EQUAL:
                return (lop.getValue() != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DInt32 lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              String Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DString lop, DByte rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DFloat32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DFloat64 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DString rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        int cmp;
        switch (oprtr) {
            case LESS:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp < 0)
                    return (true);
                else
                    return (false);
            case LESS_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp <= 0)
                    return (true);
                else
                    return (false);
            case GREATER:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp > 0)
                    return (true);
                else
                    return (false);
            case GREATER_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp >= 0)
                    return (true);
                else
                    return (false);
            case EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp == 0)
                    return (true);
                else
                    return (false);
            case NOT_EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp != 0)
                    return (true);
                else
                    return (false);
            case REGEXP:
                if (_Debug)
                    System.out.println("Left Operand: '" + lop.getValue() + "'  Right Operand: '" + rop.getValue() + "'");
                try {
//                    RE regexp = new RE(lop.getValue());
//                    return (regexp.isMatch(rop.getValue()));
		      return rop.getValue().matches(lop.getValue());
                }
//		catch (REException e1) {
                catch (PatternSyntaxException e1) {
                    throw new RegExpException(e1.getMessage());
                }
                catch (Exception e2) {
                    throw new SBHException(e2.getMessage());
                }

            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DUInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DUInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DString lop, DURL rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        int cmp;
        switch (oprtr) {
            case LESS:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp < 0)
                    return (true);
                else
                    return (false);
            case LESS_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp <= 0)
                    return (true);
                else
                    return (false);
            case GREATER:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp > 0)
                    return (true);
                else
                    return (false);
            case GREATER_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp >= 0)
                    return (true);
                else
                    return (false);
            case EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp == 0)
                    return (true);
                else
                    return (false);
            case NOT_EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp != 0)
                    return (true);
                else
                    return (false);
            case REGEXP:
                if (_Debug)
                    System.out.println("Left Operand: '" + lop.getValue() + "'  Right Operand: '" + rop.getValue() + "'");
                try {
//                    RE regexp = new RE(lop.getValue());
//                    return (regexp.isMatch(rop.getValue()));
                    return rop.getValue().matches(lop.getValue());
                }
//		catch (REException e1) {
	        catch (PatternSyntaxException e1) {
                    throw new RegExpException(e1.getMessage());
                }
                catch (Exception e2) {
                    throw new SBHException(e2.getMessage());
                }

            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              UInt16 Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DUInt16 lop, DByte rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DFloat32 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DFloat64 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DInt16 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DInt32 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DUInt16 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DUInt32 rop) throws InvalidOperatorException {
        int lval = ((int) lop.getValue()) & 0xFFFF;
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt16 lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              UInt32 Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DUInt32 lop, DByte rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DFloat32 rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DFloat64 rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DInt16 rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DInt32 rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rop.getValue());
            case LESS_EQL:
                return (lval <= rop.getValue());
            case GREATER:
                return (lval > rop.getValue());
            case GREATER_EQL:
                return (lval >= rop.getValue());
            case EQUAL:
                return (lval == rop.getValue());
            case NOT_EQUAL:
                return (lval != rop.getValue());
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DString rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DUInt16 rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        int rval = ((int) rop.getValue()) & 0xFFFF;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DUInt32 rop) throws InvalidOperatorException {
        long lval = ((long) lop.getValue()) & 0xFFFFFFFFL;
        long rval = ((long) rop.getValue()) & 0xFFFFFFFFL;
        switch (oprtr) {
            case LESS:
                return (lval < rval);
            case LESS_EQL:
                return (lval <= rval);
            case GREATER:
                return (lval > rval);
            case GREATER_EQL:
                return (lval >= rval);
            case EQUAL:
                return (lval == rval);
            case NOT_EQUAL:
                return (lval != rval);
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DUInt32 lop, DURL rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

//******************************************************************************************
//***                              URL Vs The World                                 ****
//------------------------------------------------------------------------------------------

    private static boolean op(int oprtr, DURL lop, DByte rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DFloat32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DFloat64 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DString rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        int cmp;
        switch (oprtr) {
            case LESS:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp < 0)
                    return (true);
                else
                    return (false);
            case LESS_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp <= 0)
                    return (true);
                else
                    return (false);
            case GREATER:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp > 0)
                    return (true);
                else
                    return (false);
            case GREATER_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp >= 0)
                    return (true);
                else
                    return (false);
            case EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp == 0)
                    return (true);
                else
                    return (false);
            case NOT_EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp != 0)
                    return (true);
                else
                    return (false);
            case REGEXP:
                if (_Debug)
                    System.out.println("Left Operand: '" + lop.getValue() + "'  Right Operand: '" + rop.getValue() + "'");
                try {
//                    RE regexp = new RE(lop.getValue());
//                    return (regexp.isMatch(rop.getValue()));
                      return rop.getValue().matches(lop.getValue());
                }
//                catch (REException e1) {
                catch (PatternSyntaxException e1) {
                    throw new RegExpException(e1.getMessage());
                }
                catch (Exception e2) {
                    throw new SBHException(e2.getMessage());
                }

            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DUInt16 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DUInt32 rop) throws InvalidOperatorException {
        switch (oprtr) {
            case LESS:
            case LESS_EQL:
            case GREATER:
            case GREATER_EQL:
            case EQUAL:
            case NOT_EQUAL:
            case REGEXP:
                throw new InvalidOperatorException(opErrorMsg(oprtr, lop.getTypeName(), rop.getTypeName()));
            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

    private static boolean op(int oprtr, DURL lop, DURL rop) throws InvalidOperatorException,
            RegExpException,
            SBHException {
        int cmp;
        switch (oprtr) {
            case LESS:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp < 0)
                    return (true);
                else
                    return (false);
            case LESS_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp <= 0)
                    return (true);
                else
                    return (false);
            case GREATER:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp > 0)
                    return (true);
                else
                    return (false);
            case GREATER_EQL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp >= 0)
                    return (true);
                else
                    return (false);
            case EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp == 0)
                    return (true);
                else
                    return (false);
            case NOT_EQUAL:
                cmp = lop.getValue().compareTo(rop.getValue());
                if (cmp != 0)
                    return (true);
                else
                    return (false);
            case REGEXP:
                if (_Debug)
                    System.out.println("Left Operand: '" + lop.getValue() + "'  Right Operand: '" + rop.getValue() + "'");
                try {
//                    RE regexp = new RE(lop.getValue());
//                    return (regexp.isMatch(rop.getValue()));
                      return rop.getValue().matches(lop.getValue());
                }
//                catch (REException e1) {
                catch (PatternSyntaxException e1) {
                    throw new RegExpException(e1.getMessage());
                }
                catch (Exception e2) {
                    throw new SBHException(e2.getMessage());
                }

            default:
                throw new InvalidOperatorException("Unknown Operator Requested! RTFM!");
        }
    }

}


/* Copyright 2012, UCAR/Unidata.
   See the LICENSE file for more information.
*/

package dap4.d4ts;

import dap4.core.data.DSPRegistry;
import dap4.core.util.DapContext;
import dap4.core.util.DapException;
import dap4.core.util.DapUtil;
import dap4.dap4lib.DapCodes;
import dap4.dap4lib.DapLog;
import dap4.dap4lib.FileDSP;
import dap4.dap4lib.netcdf.Nc4DSP;
import dap4.servlet.*;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import static dap4.d4ts.FrontPage.Root;

public class D4TSServlet extends DapController
{

    //////////////////////////////////////////////////
    // Constants

    static final boolean DEBUG = false;

    static final boolean PARSEDEBUG = false;

    static protected final String RESOURCEPATH = "WEB-INF/resources";

    //////////////////////////////////////////////////
    // Type Decls

    static class D4TSFactory extends DSPFactory
    {

        public D4TSFactory()
        {
            // Register known DSP classes: order is important
            // in event that two or more dsps can match a given file
            // (e.q. FileDSP vs Nc4DSP).
            // Only used in server
            DapCache.dspregistry.register(Nc4DSP.class, DSPRegistry.LAST);
            DapCache.dspregistry.register(SynDSP.class, DSPRegistry.LAST);
            DapCache.dspregistry.register(FileDSP.class, DSPRegistry.LAST);
        }

    }

    //////////////////////////////////////////////////

    static {
        DapCache.setFactory(new D4TSFactory());
    }

    //////////////////////////////////////////////////
    // Instance variables

    protected List<Root> defaultroots = null;

    //////////////////////////////////////////////////
    // Constructor(s)

    public D4TSServlet()
    {
        super();
    }

    @Override
    public void initialize()
    {
        super.initialize();
        DapLog.info("Initializing d4ts servlet");
    }

    //////////////////////////////////////////////////

    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp)
            throws ServletException,
            java.io.IOException
    {
        super.handleRequest(req, resp);
    }

    //////////////////////////////////////////////////////////
    // Capabilities processors

    @Override
    protected void
    doFavicon(String icopath, DapContext cxt)
            throws IOException
    {
        DapRequest drq = (DapRequest)cxt.get(DapRequest.class);
        String favfile = getResourcePath(drq, icopath);
        if(favfile != null) {
            try (FileInputStream fav = new FileInputStream(favfile);) {
                byte[] content = DapUtil.readbinaryfile(fav);
                OutputStream out = drq.getOutputStream();
                out.write(content);
            }
        }
    }

    @Override
    protected void
    doCapabilities(DapRequest drq, DapContext cxt)
            throws IOException
    {
        addCommonHeaders(drq);

        // Generate the front page
        FrontPage front = getFrontPage(drq, cxt);
        String frontpage = front.buildPage();

        if(frontpage == null)
            throw new DapException("Cannot create front page")
                    .setCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

        // // Convert to UTF-8 and then to byte[]
        byte[] frontpage8 = DapUtil.extract(DapUtil.UTF8.encode(frontpage));
        OutputStream out = drq.getOutputStream();
        out.write(frontpage8);

    }

    @Override
    public String
    getResourcePath(DapRequest drq, String location)
            throws DapException
    {
        String prefix = drq.getResourceRoot();
        if(prefix == null)
            throw new DapException("Cannot find location resource: " + location)
                    .setCode(DapCodes.SC_NOT_FOUND);
        location = DapUtil.canonicalpath(location);
        String datasetfilepath = DapUtil.canonjoin(prefix, location);
        // See if it really exists and is readable and of proper type
        File dataset = new File(datasetfilepath);
        if(!dataset.exists()) {
            String msg = String.format("Requested file does not exist: prefix=%s location=%s datasetfilepath=%s",
                    prefix, location, datasetfilepath);
            throw new DapException(msg)
                    .setCode(HttpServletResponse.SC_NOT_FOUND);
        }
        if(!dataset.canRead())
            throw new DapException("Requested file not readable: " + datasetfilepath)
                    .setCode(HttpServletResponse.SC_FORBIDDEN);
        return datasetfilepath;
    }

    @Override
    public long getBinaryWriteLimit()
    {
        return DEFAULTBINARYWRITELIMIT;
    }

    @Override
    public String
    getServletID()
    {
        return "d4ts";
    }

    /**
     * Isolate front page builder so we can override if desired for testing.
     *
     * @param drq
     * @param cxt
     * @return  FrontPage object
     */
    protected FrontPage
    getFrontPage(DapRequest drq, DapContext cxt)
            throws DapException
    {
        if(this.defaultroots == null) {
            // Figure out the directory containing
            // the files to display.
            String pageroot;
            pageroot = getResourcePath(drq, "");
            if(pageroot == null)
                throw new DapException("Cannot locate resources directory");
            this.defaultroots = new ArrayList<>();
            this.defaultroots.add(
                    new Root("testfiles",pageroot));
        }
        return new FrontPage(this.defaultroots, drq);
    }

}