1 24 package org.objectweb.jalisto.se.query.constraint; 25 26 import org.objectweb.jalisto.se.api.Session; 27 import org.objectweb.jalisto.se.api.query.FielComparator; 28 import org.objectweb.jalisto.se.api.query.Constraint; 29 import org.objectweb.jalisto.se.query.exception.QueryEngineException; 30 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.Set ; 34 35 public class ConstraintImpl implements Constraint { 36 public ConstraintImpl() { 37 this.fathers = new HashSet (); 38 } 39 40 public Constraint and(Constraint with) { 41 BinaryBooleanOperatorConstraint binaryConstraint = 42 new BinaryBooleanOperatorConstraint(this, with, BinaryBooleanOperatorConstraint.AND_OP); 43 fathers.add(binaryConstraint); 44 ((ConstraintImpl) with).addBinaryConstraint(binaryConstraint); 45 return binaryConstraint; 46 } 47 48 public Constraint or(Constraint with) { 49 BinaryBooleanOperatorConstraint binaryConstraint = 50 new BinaryBooleanOperatorConstraint(this, with, BinaryBooleanOperatorConstraint.OR_OP); 51 fathers.add(binaryConstraint); 52 ((ConstraintImpl) with).addBinaryConstraint(binaryConstraint); 53 return binaryConstraint; 54 } 55 56 public Constraint equal() { 57 throw new QueryEngineException(); 58 } 59 60 public Constraint greater() { 61 throw new QueryEngineException(); 62 } 63 64 public Constraint smaller() { 65 throw new QueryEngineException(); 66 } 67 68 public Constraint identity() { 69 throw new QueryEngineException(); 70 } 71 72 public Constraint like() { 73 throw new QueryEngineException(); 74 } 75 76 public Constraint contains() { 77 throw new QueryEngineException(); 78 } 79 80 public Constraint not() { 81 throw new QueryEngineException(); 82 } 83 84 public Object getObject() { 85 throw new QueryEngineException(); 86 } 87 88 public boolean execute(Session session, FielComparator comparator, Object candidate) { 89 return false; 90 } 91 92 protected void addBinaryConstraint(BinaryBooleanOperatorConstraint binaryConstraint) { 93 if (!fathers.contains(binaryConstraint)) { 94 fathers.add(binaryConstraint); 95 } 96 } 97 98 public Set getRootFathers() { 99 HashSet result = new HashSet (); 100 if (!fathers.isEmpty()) { 101 Iterator bcIt = fathers.iterator(); 102 while (bcIt.hasNext()) { 103 BinaryBooleanOperatorConstraint bc = (BinaryBooleanOperatorConstraint) bcIt.next(); 104 result.addAll(bc.getRootFathers()); 105 } 106 } else { 107 result.add(this); 108 } 109 return result; 110 } 111 112 113 protected Set fathers; 114 } 115 | Popular Tags |