/** * Equality test based attributes values * * @param other Value to compare */ public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof Or)) { return false; } final Or or = (Or) other; if ((restrictions == null && or.getRestrictions() != null) || (restrictions != null && !restrictions.equals(or .getRestrictions()))) return false; return true; }
private String or2solr(Or or, SolrServer solr) throws WikittyException { if (or.getRestrictions() == null) { throw new WikittyException("or.restrictions is null"); } if (or.getRestrictions().size() < 2) { throw new WikittyException("OR is an operator that handle 2 operand at least"); } boolean first = true; StringBuffer result = new StringBuffer(); for (Restriction restriction : or.getRestrictions()) { if (first) { result.append("( "); first = false; } else { result.append(" OR "); } result.append(toSolr(restriction, solr)); } return result.append(" )").toString(); }
private String or2solr(Or or, SolrServer solr) throws WikittyException { if (or.getRestrictions() == null) { throw new WikittyException("or.restrictions is null"); } if (or.getRestrictions().size() < 2) { throw new WikittyException("OR is an operator that handle 2 operand at least"); } boolean first = true; StringBuffer result = new StringBuffer(); for (Restriction restriction : or.getRestrictions()) { if (first) { result.append("( "); first = false; } else { result.append(" OR "); } result.append(toSolr(restriction, solr)); } return result.append(" )").toString(); }
} else if (restriction instanceof Or) { Or or = (Or) restriction; for (Restriction sub : or.getRestrictions()) { if (checkRestriction(transaction, sub, w)) { return true;
@Test public void testOr() throws Exception { String[] elementNames = new String[4]; String[] values = new String[4]; for (int i = 0; i < elementNames.length; i++) { elementNames[i] = elementName + i; values[i] = value + i; } Search q = q().eq(elementNames[0], values[0]); Search qor = q.or() .gt(elementNames[1], values[1]) .ew(elementNames[2], values[2]) .lt(elementNames[3], values[3]); Restriction dto = q.criteria().getRestriction(); Assert.assertTrue( "Restriction is " + dto.getClass().getName(), dto instanceof And ); And and = (And) dto; Restriction[] dtos = and.getRestrictions().toArray(new Restriction[]{}); checkRestriction(dtos[0], RestrictionName.EQUALS, elementName + "0", value + "0"); Assert.assertTrue( "Restriction is " + dtos[1].getClass().getName(), dtos[1] instanceof Or ); Or or = (Or) dtos[1]; dtos = or.getRestrictions().toArray(new Restriction[]{}); checkRestriction(dtos[0], RestrictionName.GREATER, elementName + "1", value + "1"); checkRestriction(dtos[1], RestrictionName.ENDS_WITH, elementName + "2", value + "2"); checkRestriction(dtos[2], RestrictionName.LESS, elementName + "3", value + "3"); }