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
riteinfotechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gauravkrtomarCommented:
I have tried to explain the code for AndLogical and for the OrLogical it is almost same. I think this will be helpfull.

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);
      //calls AndLogical(Logical lhsLogical, Logical rhsLogical, boolean withBrackets)
    }

    public AndLogical(Logical lhsLogical, Logical rhsLogical, boolean withBrackets)
    {
        logicals = (new Logical[] {
            lhsLogical, rhsLogical
        });
      //creates a 2 element array and assigns the lhsLogical to logicals[0]
      //and rhsLogical to logicals[1]
        this.withBrackets = withBrackets;
    }

    public AndLogical(Logical logicals[])
    {
        this(logicals, false);
      //calls AndLogical(Logical logicals[], boolean withBrackets)
    }

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

    public String evaluate()
        throws SystemException
    {
        String str = "";
        if(logicals != null)//checks if the logical array is null
        {
            for(int i = 0; i < logicals.length; i++)//iterates till the length of the array
            {
                Logical logical = logicals[i];
                if(logical != null)
                    str = str + logical.evaluate();//uses a recursive call here
                                       //calls the corrsponding evaluate method of the Logical
                                       //till the logical does not contain any child logical element.
                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;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
Depends upon what is defined in the logical.evaluate () method.

>> str = str + logical.evaluate();

Looks like some code to evaluate expressions. BTW, this is the way it is done:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21347495.html#13524450
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.