@Test public void shouldVerifyOrQueryReturnsFalse(){ EntityBody entity = new EntityBody(); entity.put("date", "2005"); NeutralQuery query = new NeutralQuery(); query.addOrQuery(createQuery(new NeutralCriteria("date",NeutralCriteria.CRITERIA_GT,"2007"))); boolean result = eval.entitySatisfiesDateQuery(entity, query); Assert.assertEquals("Should match", false, result); }
public boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query) { for (NeutralCriteria andCriteria : query.getCriteria()) { String fieldName = andCriteria.getKey(); String operator = andCriteria.getOperator(); if (NeutralCriteria.CRITERIA_EXISTS.equals(operator)) { boolean shouldExist = (Boolean) andCriteria.getValue(); Object actualValue = entity.get(fieldName); if (shouldExist && actualValue == null) { return false; } else if (!shouldExist && actualValue != null) { return false; } } else { String fieldValue = (String) entity.get(fieldName); if (fieldValue == null) { return false; } String expectedValue = (String) andCriteria.getValue(); int comparison = fieldValue.compareTo(expectedValue); if (NeutralCriteria.CRITERIA_LT.equals(operator)) { if (comparison >= 0) { return false; } } else if (NeutralCriteria.CRITERIA_LTE.equals(operator)) { if (comparison > 0) { return false; } } else if (NeutralCriteria.CRITERIA_GT.equals(operator)) { if (comparison <= 0) { return false; } } else if (NeutralCriteria.CRITERIA_GTE.equals(operator)) { if (comparison < 0) { return false; } } } } if (query.getOrQueries().size() > 0) { for (NeutralQuery orQuery : query.getOrQueries()) { if (entitySatisfiesDateQuery(entity, orQuery)) { return true; } } return false; } else { return true; } }
InProcessDateQueryEvaluator { public boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query) { for (NeutralCriteria andCriteria : query.getCriteria()) { String fieldName = andCriteria.getKey(); String operator = andCriteria.getOperator(); if (NeutralCriteria.CRITERIA_EXISTS.equals(operator)) { boolean shouldExist = (Boolean) andCriteria.getValue(); Object actualValue = entity.get(fieldName); if (shouldExist && actualValue == null) { return false; } else if (!shouldExist && actualValue != null) { return false; } } else { String fieldValue = (String) entity.get(fieldName); if (fieldValue == null) { return false; } String expectedValue = (String) andCriteria.getValue(); int comparison = fieldValue.compareTo(expectedValue); if (NeutralCriteria.CRITERIA_LT.equals(operator)) { if (comparison >= 0) { return false; } } else if (NeutralCriteria.CRITERIA_LTE.equals(operator)) { if (comparison > 0) { return false; } } else if (NeutralCriteria.CRITERIA_GT.equals(operator)) { if (comparison <= 0) { return false; } } else if (NeutralCriteria.CRITERIA_GTE.equals(operator)) { if (comparison < 0) { return false; } } } } if (query.getOrQueries().size() > 0) { for (NeutralQuery orQuery : query.getOrQueries()) { if (entitySatisfiesDateQuery(entity, orQuery)) { return true; } } return false; } else { return true; } } }
InProcessDateQueryEvaluator { public boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query) { for (NeutralCriteria andCriteria : query.getCriteria()) { String fieldName = andCriteria.getKey(); String operator = andCriteria.getOperator(); if (NeutralCriteria.CRITERIA_EXISTS.equals(operator)) { boolean shouldExist = (Boolean) andCriteria.getValue(); Object actualValue = entity.get(fieldName); if (shouldExist && actualValue == null) { return false; } else if (!shouldExist && actualValue != null) { return false; } } else { String fieldValue = (String) entity.get(fieldName); if (fieldValue == null) { return false; } String expectedValue = (String) andCriteria.getValue(); int comparison = fieldValue.compareTo(expectedValue); if (NeutralCriteria.CRITERIA_LT.equals(operator)) { if (comparison >= 0) { return false; } } else if (NeutralCriteria.CRITERIA_LTE.equals(operator)) { if (comparison > 0) { return false; } } else if (NeutralCriteria.CRITERIA_GT.equals(operator)) { if (comparison <= 0) { return false; } } else if (NeutralCriteria.CRITERIA_GTE.equals(operator)) { if (comparison < 0) { return false; } } } } if (query.getOrQueries().size() > 0) { for (NeutralQuery orQuery : query.getOrQueries()) { if (entitySatisfiesDateQuery(entity, orQuery)) { return true; } } return false; } else { return true; } }  }
InProcessDateQueryEvaluator { public boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query) { for (NeutralCriteria andCriteria : query.getCriteria()) { String fieldName = andCriteria.getKey(); String operator = andCriteria.getOperator(); if (NeutralCriteria.CRITERIA_EXISTS.equals(operator)) { boolean shouldExist = (Boolean) andCriteria.getValue(); Object actualValue = entity.get(fieldName); if (shouldExist && actualValue == null) { return false; } else if (!shouldExist && actualValue != null) { return false; } } else { String fieldValue = (String) entity.get(fieldName); if (fieldValue == null) { return false; } String expectedValue = (String) andCriteria.getValue(); int comparison = fieldValue.compareTo(expectedValue); if (NeutralCriteria.CRITERIA_LT.equals(operator)) { if (comparison >= 0) { return false; } } else if (NeutralCriteria.CRITERIA_LTE.equals(operator)) { if (comparison > 0) { return false; } } else if (NeutralCriteria.CRITERIA_GT.equals(operator)) { if (comparison <= 0) { return false; } } else if (NeutralCriteria.CRITERIA_GTE.equals(operator)) { if (comparison < 0) { return false; } } } } if (query.getOrQueries().size() > 0) { for (NeutralQuery orQuery : query.getOrQueries()) { if (entitySatisfiesDateQuery(entity, orQuery)) { return true; } } return false; } else { return true; } }  boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query); }
InProcessDateQueryEvaluator { public boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query) { for (NeutralCriteria andCriteria : query.getCriteria()) { String fieldName = andCriteria.getKey(); String operator = andCriteria.getOperator(); if (NeutralCriteria.CRITERIA_EXISTS.equals(operator)) { boolean shouldExist = (Boolean) andCriteria.getValue(); Object actualValue = entity.get(fieldName); if (shouldExist && actualValue == null) { return false; } else if (!shouldExist && actualValue != null) { return false; } } else { String fieldValue = (String) entity.get(fieldName); if (fieldValue == null) { return false; } String expectedValue = (String) andCriteria.getValue(); int comparison = fieldValue.compareTo(expectedValue); if (NeutralCriteria.CRITERIA_LT.equals(operator)) { if (comparison >= 0) { return false; } } else if (NeutralCriteria.CRITERIA_LTE.equals(operator)) { if (comparison > 0) { return false; } } else if (NeutralCriteria.CRITERIA_GT.equals(operator)) { if (comparison <= 0) { return false; } } else if (NeutralCriteria.CRITERIA_GTE.equals(operator)) { if (comparison < 0) { return false; } } } } if (query.getOrQueries().size() > 0) { for (NeutralQuery orQuery : query.getOrQueries()) { if (entitySatisfiesDateQuery(entity, orQuery)) { return true; } } return false; } else { return true; } }  boolean entitySatisfiesDateQuery(EntityBody entity, NeutralQuery query);  }