/** * Equality test based attributes values * * @param value * Value to compare */ public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof And)) { return false; } final And and = (And) other; if ((restrictions == null && and.getRestrictions() != null) || (restrictions != null && !restrictions.equals(and .getRestrictions()))) { return false; } return true; }
private String and2solr(And and, SolrServer solr) throws WikittyException { if (and.getRestrictions() == null) { throw new WikittyException( "and.restrictions is null" ); } if (and.getRestrictions().size() < 2) { throw new WikittyException( "AND is an operator that handle 2 operand at least"); } boolean first = true; StringBuffer result = new StringBuffer(); for (Restriction restriction : and.getRestrictions()) { if (first) { result.append("( ").append(toSolr(restriction, solr)); first = false; } else { result.append(" AND ").append(toSolr(restriction, solr)); } } return result.append(" )").toString(); }
private String and2solr(And and, SolrServer solr) throws WikittyException { if (and.getRestrictions() == null) { throw new WikittyException( "and.restrictions is null" ); } if (and.getRestrictions().size() < 2) { throw new WikittyException( "AND is an operator that handle 2 operand at least"); } boolean first = true; StringBuffer result = new StringBuffer(); for (Restriction restriction : and.getRestrictions()) { if (first) { result.append("( ").append(toSolr(restriction, solr)); first = false; } else { result.append(" AND ").append(toSolr(restriction, solr)); } } return result.append(" )").toString(); }
for (Restriction sub : and.getRestrictions()) { if (!checkRestriction(transaction, sub, w)) { return false;
if ( parent instanceof And ) { and = (And) parent; and.getRestrictions().add( generatedRestriction ); } else { and = RestrictionHelper.and( Arrays.asList(new Restriction[]{ associated.getParentRestrictionDto(), generatedRestriction }) );
@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"); }
@Test public void testAnd() throws Exception { Restriction dto = q() .eq(elementName + "0", value + "0") .gt(elementName + "1", value + "1") .ew(elementName + "2", value + "2") .criteria().getRestriction(); Assert.assertTrue( dto instanceof And ); And and = (And) dto; Restriction[] dtos = and.getRestrictions().toArray(new Restriction[]{}); checkRestriction(dtos[0], RestrictionName.EQUALS, elementName + "0", value + "0"); checkRestriction(dtos[1], RestrictionName.GREATER, elementName + "1", value + "1"); checkRestriction(dtos[2], RestrictionName.ENDS_WITH, elementName + "2", value + "2"); }