Link to home
Start Free TrialLog in
Avatar of riteinfotech
riteinfotech

asked on

java classes and methods

In our java application we have a class Andlogical and the code is...........


package com.rite.framework.condition;

import com.rite.framework.exception.SystemException;

public class AndLogical
    implements Logical
{

    public AndLogical(Logical lhsLogical, Logical rhsLogical)
    {
        this(lhsLogical, rhsLogical, false);
    }

    public AndLogical(Logical lhsLogical, Logical rhsLogical, boolean withBrackets)
    {
        logicals = (new Logical[] {
            lhsLogical, rhsLogical
        });
        this.withBrackets = withBrackets;
    }

    public AndLogical(Logical logicals[])
    {
        this(logicals, false);
    }

    public AndLogical(Logical logicals[], boolean withBrackets)
    {
        this.logicals = logicals;
        this.withBrackets = withBrackets;
    }

    public String evaluate()
        throws SystemException
    {
        String str = "";
        if(logicals != null)
        {
            for(int i = 0; i < logicals.length; i++)
            {
                Logical logical = logicals[i];
                if(logical != null)
                    str = str + logical.evaluate();
                if(i < logicals.length - 1)
                    str = str + " and ";
            }

        }
        if(withBrackets)
            str = "(" + str + ")";
        return str;
    }

    private Logical logicals[];
    private boolean withBrackets;
}



OrLogical Class .......................

package com.rite.framework.condition;

import com.rite.framework.exception.SystemException;

public class OrLogical
    implements Logical
{

    public OrLogical(Logical lhsLogical, Logical rhsLogical)
    {
        this(lhsLogical, rhsLogical, false);
    }

    public OrLogical(Logical lhsLogical, Logical rhsLogical, boolean withBrackets)
    {
        logicals = (new Logical[] {
            lhsLogical, rhsLogical
        });
        this.withBrackets = withBrackets;
    }

    public OrLogical(Logical logicals[])
    {
        this(logicals, false);
    }

    public OrLogical(Logical logicals[], boolean withBrackets)
    {
        this.logicals = logicals;
        this.withBrackets = withBrackets;
    }

    public String evaluate()
        throws SystemException
    {
        String str = "";
        if(logicals != null)
        {
            for(int i = 0; i < logicals.length; i++)
            {
                Logical logical = logicals[i];
                if(logical != null)
                    str = str + logical.evaluate();
                if(i < logicals.length - 1)
                    str = str + " or ";
            }

        }
        if(withBrackets)
            str = "(" + str + ")";
        return str;
    }

    private Logical logicals[];
    private boolean withBrackets;
}


and like this equalcondition,greaterthancondition,lessthancondition,likecondition,notlikecondition,notequalscondition  and other classes(implementing database query operators and conditions).
we are using these classes to generate sql queries(generic based on user input) for reporting purpose.

what's going on in the constructors,what is the functionality of this evaluate method,i m not getting these things
please explain and help.
thanks
ASKER CERTIFIED SOLUTION
Avatar of gauravkrtomar
gauravkrtomar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial