Improved: Refactoring ‘EntityCondition’ - Rewrite EntityConditionListBase class

(OFBIZ-10691)

Unecessary ‘this’ has been removed and the javadoc has been
expanded. The visibility of the class has been reduced to package
only.  The ‘conditionList’ field has been renamed to ‘conditions’ and
the subclasses has been adapted.


Thanks Mathieu for the contribution


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1850385 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gil Portenseigne
2019-01-04 15:02:45 +00:00
parent a8e986c7c4
commit 00ee97b23d
2 changed files with 35 additions and 18 deletions
@@ -47,7 +47,7 @@ public final class EntityConditionList<T extends EntityCondition> extends Entity
* @return the size of the internal list of condition expressions
*/
public int getConditionListSize() {
return conditionList.size();
return conditions.size();
}
/**
@@ -57,7 +57,7 @@ public final class EntityConditionList<T extends EntityCondition> extends Entity
*/
@SuppressWarnings("unchecked")
public Iterator<T> getConditionIterator() {
return (Iterator<T>)conditionList.iterator();
return (Iterator<T>)conditions.iterator();
}
@Override
@@ -28,54 +28,71 @@ import org.apache.ofbiz.entity.config.model.Datasource;
import org.apache.ofbiz.entity.model.ModelEntity;
/**
* Encapsulates a list of EntityConditions to be used as a single EntityCondition combined as specified
*
* Represents a combination of multiple condition expressions.
*/
@SuppressWarnings("serial")
public abstract class EntityConditionListBase<T extends EntityCondition> implements EntityCondition {
abstract class EntityConditionListBase<T extends EntityCondition> implements EntityCondition {
public static final String module = EntityConditionListBase.class.getName();
protected final List<? extends T> conditionList;
/** The list of condition expressions to combine. */
protected final List<? extends T> conditions;
/** The infix operator used to combine every elements in the list of conditions. */
protected final EntityJoinOperator operator;
protected EntityConditionListBase(List<? extends T> conditionList, EntityJoinOperator operator) {
this.conditionList = conditionList;
/**
* Constructs a combination of multiple condition expressions.
*
* @param conditions the list of condition expressions to combine
* @param operator the infix operator used to combine every elements in the list of conditions
*/
protected EntityConditionListBase(List<? extends T> conditions, EntityJoinOperator operator) {
this.conditions = conditions;
this.operator = operator;
}
/**
* Gets the infix operator used to combine every elements in the list of conditions.
*
* @return the infix operator used to combine every elements in the list of conditions.
*/
public EntityJoinOperator getOperator() {
return this.operator;
return operator;
}
/**
* Gets the condition expression stored at a particular of the internal list of conditions.
*
* @param index the index of the condition expression to find
* @return the corresponding condition expression
*/
public T getCondition(int index) {
return this.conditionList.get(index);
return conditions.get(index);
}
@Override
public boolean isEmpty() {
return operator.isEmpty(conditionList);
return operator.isEmpty(conditions);
}
@Override
public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, Datasource datasourceInfo) {
StringBuilder sql = new StringBuilder();
operator.addSqlValue(sql, modelEntity, entityConditionParams, conditionList, datasourceInfo);
operator.addSqlValue(sql, modelEntity, entityConditionParams, conditions, datasourceInfo);
return sql.toString();
}
@Override
public void checkCondition(ModelEntity modelEntity) throws GenericModelException {
operator.validateSql(modelEntity, conditionList);
operator.validateSql(modelEntity, conditions);
}
@Override
public boolean mapMatches(Delegator delegator, Map<String, ? extends Object> map) {
return operator.mapMatches(delegator, map, conditionList);
return operator.mapMatches(delegator, map, conditions);
}
@Override
public EntityCondition freeze() {
return operator.freeze(conditionList);
return operator.freeze(conditions);
}
@Override
@@ -85,12 +102,12 @@ public abstract class EntityConditionListBase<T extends EntityCondition> impleme
}
EntityConditionListBase<?> other = UtilGenerics.cast(obj);
return conditionList.equals(other.conditionList) && operator.equals(other.operator);
return conditions.equals(other.conditions) && operator.equals(other.operator);
}
@Override
public int hashCode() {
return conditionList.hashCode() + operator.hashCode();
return conditions.hashCode() + operator.hashCode();
}
@Override