
net.cassite.daf4j.And Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of daf4j-api Show documentation
Show all versions of daf4j-api Show documentation
A library provides facade api for data accessing.
The newest version!
package net.cassite.daf4j;
import java.util.ArrayList;
import java.util.List;
/**
* 查询条件中的与操作
* 该对象中存储的对象应当以"与"逻辑操作连接起来
*/
public class And implements Where, AndOr {
final List conditions = new ArrayList();
final List ors = new ArrayList();
final List expBools = new ArrayList();
@Override
public And and(Condition condition) {
conditions.add(condition);
return this;
}
@Override
public And and(And a) {
this.conditions.addAll(a.conditions);
this.ors.addAll(a.ors);
return this;
}
@Override
public And and(Or o) {
ors.add(o);
return this;
}
@Override
public And and(ExpressionBoolean expBool) {
this.expBools.add(expBool);
return this;
}
@Override
public Or or(Condition condition) {
Or o = new Or();
o.conditions.add(condition);
o.ands.add(this);
return o;
}
@Override
public Or or(Or o) {
o.ands.add(this);
return o;
}
@Override
public Or or(ExpressionBoolean expBool) {
Or o = new Or();
o.ands.add(this);
o.expBools.add(expBool);
return o;
}
@Override
public Or or(And a) {
Or o = new Or();
o.ands.add(this);
o.ands.add(a);
return o;
}
/**
* 获取存储的"或"逻辑操作对象
*
* @return 存放Or的List
*/
public List getOrList() {
return ors;
}
/**
* 获取存储的"条件"对象
*
* @return 存放Condition的List
*/
public List getConditionList() {
return conditions;
}
/**
* 获取存储的"返回布尔值的表达式"对象
*
* @return 存放ExpressionBoolean的List
*/
public List getExpBoolList() {
return expBools;
}
@Override
public boolean isAnd() {
return true;
}
@Override
public boolean isOr() {
return false;
}
@Override
public boolean isCondition() {
return false;
}
@Override
public boolean isExpression() {
return false;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (Condition c : conditions) {
if (isFirst) {
isFirst = false;
} else {
sb.append(" and ");
}
sb.append(c.toString());
}
for (Or o : ors) {
if (isFirst) {
isFirst = false;
} else {
sb.append(" and ");
}
sb.append("(").append(o.toString()).append(")");
}
for (ExpressionBoolean expBool : expBools) {
if (isFirst) {
isFirst = false;
} else {
sb.append(" and ");
}
sb.append(expBool);
}
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy