riteinfotech
asked on
java classes and methods
In our java application we have a class Andlogical and the code is...........
package com.rite.framework.conditi on;
import com.rite.framework.excepti on.SystemE xception;
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.conditi on;
import com.rite.framework.excepti on.SystemE xception;
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,greaterthan condition, lessthanco ndition,li keconditio n,notlikec ondition,n otequalsco ndition 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
package com.rite.framework.conditi
import com.rite.framework.excepti
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.conditi
import com.rite.framework.excepti
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,greaterthan
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.