incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject svn commit: r1482411 - in /incubator/ambari/trunk/ambari-server/src: main/java/org/apache/ambari/server/api/predicate/expressions/ main/java/org/apache/ambari/server/api/predicate/operators/ main/java/org/apache/ambari/server/api/query/ main/java/org/a...
Date Tue, 14 May 2013 15:55:57 GMT
Author: tbeerbower
Date: Tue May 14 15:55:56 2013
New Revision: 1482411

URL: http://svn.apache.org/r1482411
Log:
AMBARI-1404 - Clean up Predicate code around BasePredicate to remove need for casting

Modified:
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/expressions/NotLogicalExpression.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/AndOperator.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/InOperator.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/NotOperator.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/OrOperator.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitor.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/SQLPredicateVisitor.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/AndPredicate.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ArrayPredicate.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/NotPredicate.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/OrPredicate.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/UnaryPredicate.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PredicateBuilder.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitorTest.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitorTest.java

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/expressions/NotLogicalExpression.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/expressions/NotLogicalExpression.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/expressions/NotLogicalExpression.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/expressions/NotLogicalExpression.java Tue May 14 15:55:56 2013
@@ -20,7 +20,6 @@ package org.apache.ambari.server.api.pre
 
 import org.apache.ambari.server.api.predicate.InvalidQueryException;
 import org.apache.ambari.server.api.predicate.operators.LogicalOperator;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.NotPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 
@@ -59,7 +58,6 @@ public class NotLogicalExpression extend
 
   @Override
   public Predicate toPredicate() throws InvalidQueryException {
-    //todo: remove need to down cast to BasePredicate
-    return new NotPredicate((BasePredicate) getRightOperand().toPredicate());
+    return new NotPredicate(getRightOperand().toPredicate());
   }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/AndOperator.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/AndOperator.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/AndOperator.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/AndOperator.java Tue May 14 15:55:56 2013
@@ -19,7 +19,6 @@
 package org.apache.ambari.server.api.predicate.operators;
 
 import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 
 /**
@@ -54,7 +53,7 @@ public class AndOperator extends Abstrac
   @Override
   public Predicate toPredicate(Predicate left, Predicate right) {
     //todo: refactor to not need down casts
-    return new AndPredicate((BasePredicate) left, (BasePredicate) right);
+    return new AndPredicate(left, right);
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/InOperator.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/InOperator.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/InOperator.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/InOperator.java Tue May 14 15:55:56 2013
@@ -18,7 +18,6 @@
 package org.apache.ambari.server.api.predicate.operators;
 
 import org.apache.ambari.server.api.predicate.InvalidQueryException;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.EqualsPredicate;
 import org.apache.ambari.server.controller.predicate.OrPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -61,7 +60,7 @@ public class InOperator extends Abstract
   }
 
   private OrPredicate buildOrPredicate(List<EqualsPredicate> listPredicates) {
-    return new OrPredicate(listPredicates.toArray(new BasePredicate[listPredicates.size()]));
+    return new OrPredicate(listPredicates.toArray(new Predicate[listPredicates.size()]));
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/NotOperator.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/NotOperator.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/NotOperator.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/NotOperator.java Tue May 14 15:55:56 2013
@@ -18,7 +18,6 @@
 
 package org.apache.ambari.server.api.predicate.operators;
 
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.NotPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 
@@ -53,7 +52,7 @@ public class NotOperator extends Abstrac
 
   @Override
   public Predicate toPredicate(Predicate left, Predicate right) {
-    return new NotPredicate((BasePredicate) right);
+    return new NotPredicate(right);
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/OrOperator.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/OrOperator.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/OrOperator.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/predicate/operators/OrOperator.java Tue May 14 15:55:56 2013
@@ -18,7 +18,6 @@
 
 package org.apache.ambari.server.api.predicate.operators;
 
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.OrPredicate;
 import org.apache.ambari.server.controller.spi.Predicate;
 
@@ -54,7 +53,7 @@ public class OrOperator extends Abstract
   @Override
   public Predicate toPredicate(Predicate left, Predicate right) {
     //todo: refactor to remove down casts
-    return new OrPredicate((BasePredicate) left, (BasePredicate) right);
+    return new OrPredicate(left, right);
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java Tue May 14 15:55:56 2013
@@ -23,7 +23,6 @@ import org.apache.ambari.server.api.serv
 import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.EqualsPredicate;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.controller.spi.*;
@@ -245,12 +244,12 @@ public class QueryImpl implements Query 
     return resourceAdded;
   }
 
-  private BasePredicate createInternalPredicate(ResourceInstance resource) {
+  private Predicate createInternalPredicate(ResourceInstance resource) {
     Resource.Type resourceType = resource.getResourceDefinition().getType();
     Map<Resource.Type, String> mapResourceIds = resource.getIds();
     Schema schema = getClusterController().getSchema(resourceType);
 
-    Set<BasePredicate> setPredicates = new HashSet<BasePredicate>();
+    Set<Predicate> setPredicates = new HashSet<Predicate>();
     for (Map.Entry<Resource.Type, String> entry : mapResourceIds.entrySet()) {
       if (entry.getValue() != null) {
         String keyPropertyId = schema.getKeyPropertyId(entry.getKey());
@@ -263,7 +262,7 @@ public class QueryImpl implements Query 
     if (setPredicates.size() == 1) {
       return setPredicates.iterator().next();
     } else if (setPredicates.size() > 1) {
-      return new AndPredicate(setPredicates.toArray(new BasePredicate[setPredicates.size()]));
+      return new AndPredicate(setPredicates.toArray(new Predicate[setPredicates.size()]));
     } else {
       return null;
     }
@@ -272,14 +271,14 @@ public class QueryImpl implements Query 
   private Predicate createPredicate(ResourceInstance resource) {
     Predicate predicate = null;
     //todo: change reference type to Predicate when predicate hierarchy is fixed
-    BasePredicate internalPredicate = createInternalPredicate(resource);
+    Predicate internalPredicate = createInternalPredicate(resource);
     if (internalPredicate == null) {
       if (m_userPredicate != null) {
         predicate = m_userPredicate;
       }
     } else {
       predicate = (m_userPredicate == null ? internalPredicate :
-          new AndPredicate((BasePredicate) m_userPredicate, internalPredicate));
+          new AndPredicate(m_userPredicate, internalPredicate));
     }
     return predicate;
   }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java Tue May 14 15:55:56 2013
@@ -31,7 +31,6 @@ import org.apache.ambari.server.ObjectNo
 import org.apache.ambari.server.ParentObjectNotFoundException;
 import org.apache.ambari.server.controller.ConfigurationRequest;
 import org.apache.ambari.server.controller.RequestStatusResponse;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.spi.*;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
@@ -150,11 +149,11 @@ public abstract class AbstractResourcePr
 
     SimplifyingPredicateVisitor visitor = new SimplifyingPredicateVisitor(this);
     PredicateHelper.visit(givenPredicate, visitor);
-    List<BasePredicate> predicates = visitor.getSimplifiedPredicates();
+    List<Predicate> predicates = visitor.getSimplifiedPredicates();
 
     Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>();
 
-    for (BasePredicate predicate : predicates) {
+    for (Predicate predicate : predicates) {
       propertyMaps.add(PredicateHelper.getProperties(predicate));
     }
     return propertyMaps;

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java Tue May 14 15:55:56 2013
@@ -20,12 +20,13 @@ package org.apache.ambari.server.control
 
 import org.apache.ambari.server.controller.predicate.AlwaysPredicate;
 import org.apache.ambari.server.controller.predicate.ArrayPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.CategoryPredicate;
 import org.apache.ambari.server.controller.predicate.ComparisonPredicate;
 import org.apache.ambari.server.controller.predicate.PropertyPredicate;
 import org.apache.ambari.server.controller.predicate.PredicateVisitor;
 import org.apache.ambari.server.controller.predicate.UnaryPredicate;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -43,9 +44,9 @@ public class PropertyPredicateVisitor im
 
   @Override
   public void acceptArrayPredicate(ArrayPredicate predicate) {
-    BasePredicate[] predicates = predicate.getPredicates();
-    for (BasePredicate predicate1 : predicates) {
-      predicate1.accept(this);
+    Predicate[] predicates = predicate.getPredicates();
+    for (Predicate predicate1 : predicates) {
+      PredicateHelper.visit(predicate1, this);
     }
   }
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitor.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitor.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitor.java Tue May 14 15:55:56 2013
@@ -21,14 +21,15 @@ package org.apache.ambari.server.control
 import org.apache.ambari.server.controller.predicate.AlwaysPredicate;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
 import org.apache.ambari.server.controller.predicate.ArrayPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.CategoryPredicate;
 import org.apache.ambari.server.controller.predicate.ComparisonPredicate;
 import org.apache.ambari.server.controller.predicate.EqualsPredicate;
 import org.apache.ambari.server.controller.predicate.OrPredicate;
 import org.apache.ambari.server.controller.predicate.PredicateVisitor;
 import org.apache.ambari.server.controller.predicate.UnaryPredicate;
+import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -66,7 +67,7 @@ public class SimplifyingPredicateVisitor
   /**
    * The last visited predicate.
    */
-  private BasePredicate lastVisited = null;
+  private Predicate lastVisited = null;
 
 
   /**
@@ -83,7 +84,7 @@ public class SimplifyingPredicateVisitor
    *
    * @return a list of simplified predicates
    */
-  public List<BasePredicate> getSimplifiedPredicates() {
+  public List<Predicate> getSimplifiedPredicates() {
     if (lastVisited == null) {
       return Collections.emptyList();
     }
@@ -106,13 +107,13 @@ public class SimplifyingPredicateVisitor
 
   @Override
   public void acceptArrayPredicate(ArrayPredicate arrayPredicate) {
-    List<BasePredicate> predicateList = new LinkedList<BasePredicate>();
+    List<Predicate> predicateList = new LinkedList<Predicate>();
     boolean hasOrs = false;
 
-    BasePredicate[] predicates = arrayPredicate.getPredicates();
+    Predicate[] predicates = arrayPredicate.getPredicates();
     if (predicates.length > 0) {
-      for (BasePredicate predicate : predicates) {
-        predicate.accept(this);
+      for (Predicate predicate : predicates) {
+        PredicateHelper.visit(predicate, this);
         predicateList.add(lastVisited);
         if (lastVisited instanceof OrPredicate) {
           hasOrs = true;
@@ -122,17 +123,17 @@ public class SimplifyingPredicateVisitor
     // distribute so that A && ( B || C ) becomes ( A && B ) || ( A && C )
     if (hasOrs && arrayPredicate instanceof AndPredicate) {
       int size = predicateList.size();
-      List<BasePredicate> andPredicateList = new LinkedList<BasePredicate>();
+      List<Predicate> andPredicateList = new LinkedList<Predicate>();
 
       for (int i = 0; i < size; ++i) {
         for (int j = i + 1; j < size; ++j) {
           andPredicateList.addAll(distribute(predicateList.get(i), predicateList.get(j)));
         }
       }
-      lastVisited = OrPredicate.instance(andPredicateList.toArray(new BasePredicate[andPredicateList.size()]));
+      lastVisited = OrPredicate.instance(andPredicateList.toArray(new Predicate[andPredicateList.size()]));
     }
     else {
-      lastVisited = arrayPredicate.create(predicateList.toArray(new BasePredicate[predicateList.size()]));
+      lastVisited = arrayPredicate.create(predicateList.toArray(new Predicate[predicateList.size()]));
     }
   }
 
@@ -146,7 +147,7 @@ public class SimplifyingPredicateVisitor
     lastVisited = predicate;
   }
 
-  private static List<BasePredicate> distribute(BasePredicate left, BasePredicate right) {
+  private static List<Predicate> distribute(Predicate left, Predicate right) {
 
     if (left instanceof OrPredicate) {
       return distributeOr((OrPredicate) left, right);
@@ -159,15 +160,15 @@ public class SimplifyingPredicateVisitor
         left : AndPredicate.instance(left, right));
   }
 
-  private static List<BasePredicate> distributeOr(OrPredicate orPredicate, BasePredicate other) {
-    List<BasePredicate> andPredicateList = new LinkedList<BasePredicate>();
+  private static List<Predicate> distributeOr(OrPredicate orPredicate, Predicate other) {
+    List<Predicate> andPredicateList = new LinkedList<Predicate>();
     OrPredicate otherOr = null;
 
     if (other instanceof OrPredicate) {
       otherOr = (OrPredicate) other;
     }
 
-    for (BasePredicate basePredicate : orPredicate.getPredicates()) {
+    for (Predicate basePredicate : orPredicate.getPredicates()) {
 
       if (otherOr != null) {
         andPredicateList.addAll(distributeOr(otherOr, basePredicate));

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/SQLPredicateVisitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/SQLPredicateVisitor.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/SQLPredicateVisitor.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/SQLPredicateVisitor.java Tue May 14 15:55:56 2013
@@ -20,11 +20,12 @@ package org.apache.ambari.server.control
 
 import org.apache.ambari.server.controller.predicate.AlwaysPredicate;
 import org.apache.ambari.server.controller.predicate.ArrayPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.CategoryPredicate;
 import org.apache.ambari.server.controller.predicate.ComparisonPredicate;
 import org.apache.ambari.server.controller.predicate.PredicateVisitor;
 import org.apache.ambari.server.controller.predicate.UnaryPredicate;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 
 /**
@@ -58,7 +59,7 @@ public class SQLPredicateVisitor impleme
 
   @Override
   public void acceptArrayPredicate(ArrayPredicate predicate) {
-    BasePredicate[] predicates = predicate.getPredicates();
+    Predicate[] predicates = predicate.getPredicates();
     if (predicates.length > 0) {
 
       stringBuilder.append("(");
@@ -66,7 +67,7 @@ public class SQLPredicateVisitor impleme
         if (i > 0) {
           stringBuilder.append(" ").append(predicate.getOperator()).append(" ");
         }
-        predicates[i].accept(this);
+        PredicateHelper.visit(predicates[i], this);
       }
       stringBuilder.append(")");
     }
@@ -75,7 +76,7 @@ public class SQLPredicateVisitor impleme
   @Override
   public void acceptUnaryPredicate(UnaryPredicate predicate) {
     stringBuilder.append(predicate.getOperator()).append("(");
-    predicate.getPredicate().accept(this);
+    PredicateHelper.visit(predicate.getPredicate(), this);
     stringBuilder.append(")");
   }
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/AndPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/AndPredicate.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/AndPredicate.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/AndPredicate.java Tue May 14 15:55:56 2013
@@ -32,20 +32,20 @@ import java.util.List;
  */
 public class AndPredicate extends ArrayPredicate {
 
-  public AndPredicate(BasePredicate... predicates) {
+  public AndPredicate(Predicate... predicates) {
     super(predicates);
   }
 
   @Override
-  public BasePredicate create(BasePredicate... predicates) {
+  public Predicate create(Predicate... predicates) {
     return instance(predicates);
   }
 
-  public static BasePredicate instance(BasePredicate... predicates) {
-    List<BasePredicate> predicateList = new LinkedList<BasePredicate>();
+  public static Predicate instance(Predicate... predicates) {
+    List<Predicate> predicateList = new LinkedList<Predicate>();
 
     // Simplify the predicate array
-    for (BasePredicate predicate : predicates) {
+    for (Predicate predicate : predicates) {
       if (!(predicate instanceof AlwaysPredicate)) {
         if (predicate instanceof AndPredicate) {
           predicateList.addAll(Arrays.asList(((AndPredicate) predicate).getPredicates()));
@@ -58,7 +58,7 @@ public class AndPredicate extends ArrayP
 
     return predicateList.size() == 1 ?
         predicateList.get(0) :
-        new AndPredicate(predicateList.toArray(new BasePredicate[predicateList.size()]));
+        new AndPredicate(predicateList.toArray(new Predicate[predicateList.size()]));
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ArrayPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ArrayPredicate.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ArrayPredicate.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ArrayPredicate.java Tue May 14 15:55:56 2013
@@ -18,6 +18,9 @@
 
 package org.apache.ambari.server.controller.predicate;
 
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
+
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -26,13 +29,13 @@ import java.util.Set;
  * Predicate which evaluates an array of predicates.
  */
 public abstract class ArrayPredicate implements BasePredicate {
-  private final BasePredicate[] predicates;
+  private final Predicate[] predicates;
   private final Set<String> propertyIds = new HashSet<String>();
 
-  public ArrayPredicate(BasePredicate... predicates) {
+  public ArrayPredicate(Predicate... predicates) {
     this.predicates = predicates;
-    for (BasePredicate predicate : predicates) {
-      propertyIds.addAll(predicate.getPropertyIds());
+    for (Predicate predicate : predicates) {
+      propertyIds.addAll(PredicateHelper.getPropertyIds(predicate));
     }
   }
 
@@ -43,10 +46,10 @@ public abstract class ArrayPredicate imp
    *
    * @return a new ArrayPredicate
    */
-  public abstract BasePredicate create(BasePredicate... predicates);
+  public abstract Predicate create(Predicate... predicates);
 
 
-  public BasePredicate[] getPredicates() {
+  public Predicate[] getPredicates() {
     return predicates;
   }
 
@@ -65,15 +68,15 @@ public abstract class ArrayPredicate imp
     if (propertyIds != null ? !propertyIds.equals(that.propertyIds) : that.propertyIds != null) return false;
 
     // don't care about array order
-    Set<BasePredicate> setThisPredicates = new HashSet<BasePredicate>(Arrays.asList(predicates));
-    Set<BasePredicate> setThatPredicates = new HashSet<BasePredicate>(Arrays.asList(that.predicates));
+    Set<Predicate> setThisPredicates = new HashSet<Predicate>(Arrays.asList(predicates));
+    Set<Predicate> setThatPredicates = new HashSet<Predicate>(Arrays.asList(that.predicates));
     return setThisPredicates.equals(setThatPredicates);
   }
 
   @Override
   public int hashCode() {
     // don't care about array order
-    int result = predicates != null ? new HashSet<BasePredicate>(Arrays.asList(predicates)).hashCode() : 0;
+    int result = predicates != null ? new HashSet<Predicate>(Arrays.asList(predicates)).hashCode() : 0;
     result = 31 * result + (propertyIds != null ? propertyIds.hashCode() : 0);
     return result;
   }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/NotPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/NotPredicate.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/NotPredicate.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/NotPredicate.java Tue May 14 15:55:56 2013
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller.predicate;
 
+import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Resource;
 
 /**
@@ -24,7 +25,7 @@ import org.apache.ambari.server.controll
  */
 public class NotPredicate extends UnaryPredicate {
 
-  public NotPredicate(BasePredicate predicate) {
+  public NotPredicate(Predicate predicate) {
     super(predicate);
   }
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/OrPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/OrPredicate.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/OrPredicate.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/OrPredicate.java Tue May 14 15:55:56 2013
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller.predicate;
 
+import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Resource;
 
 import java.util.Arrays;
@@ -29,20 +30,20 @@ import java.util.List;
  */
 public class OrPredicate extends ArrayPredicate {
 
-  public OrPredicate(BasePredicate... predicates) {
+  public OrPredicate(Predicate... predicates) {
     super(predicates);
   }
 
   @Override
-  public BasePredicate create(BasePredicate... predicates) {
+  public Predicate create(Predicate... predicates) {
     return instance(predicates);
   }
 
-  public static BasePredicate instance(BasePredicate... predicates) {
-    List<BasePredicate> predicateList = new LinkedList<BasePredicate>();
+  public static Predicate instance(Predicate... predicates) {
+    List<Predicate> predicateList = new LinkedList<Predicate>();
 
     // Simplify the predicate array
-    for (BasePredicate predicate : predicates) {
+    for (Predicate predicate : predicates) {
       if (predicate instanceof AlwaysPredicate) {
         return predicate;
       }
@@ -55,13 +56,13 @@ public class OrPredicate extends ArrayPr
     }
     return predicateList.size() == 1 ?
         predicateList.get(0) :
-        new OrPredicate(predicateList.toArray(new BasePredicate[predicateList.size()]));
+        new OrPredicate(predicateList.toArray(new Predicate[predicateList.size()]));
   }
 
   @Override
   public boolean evaluate(Resource resource) {
-    BasePredicate[] predicates = getPredicates();
-    for (BasePredicate predicate : predicates) {
+    Predicate[] predicates = getPredicates();
+    for (Predicate predicate : predicates) {
       if (predicate.evaluate(resource)) {
         return true;
       }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/UnaryPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/UnaryPredicate.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/UnaryPredicate.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/UnaryPredicate.java Tue May 14 15:55:56 2013
@@ -17,26 +17,29 @@
  */
 package org.apache.ambari.server.controller.predicate;
 
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
+
 import java.util.Set;
 
 /**
  * Predicate that operates on one other predicate.
  */
 public abstract class UnaryPredicate implements BasePredicate {
-  private final BasePredicate predicate;
+  private final Predicate predicate;
 
-  public UnaryPredicate(BasePredicate predicate) {
+  public UnaryPredicate(Predicate predicate) {
     assert(predicate != null);
     this.predicate = predicate;
   }
 
-  public BasePredicate getPredicate() {
+  public Predicate getPredicate() {
     return predicate;
   }
 
   @Override
   public Set<String> getPropertyIds() {
-    return predicate.getPropertyIds();
+    return PredicateHelper.getPropertyIds(predicate);
   }
 
   @Override

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PredicateBuilder.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PredicateBuilder.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PredicateBuilder.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PredicateBuilder.java Tue May 14 15:55:56 2013
@@ -18,7 +18,6 @@
 package org.apache.ambari.server.controller.utilities;
 
 import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.EqualsPredicate;
 import org.apache.ambari.server.controller.predicate.GreaterEqualsPredicate;
 import org.apache.ambari.server.controller.predicate.GreaterPredicate;
@@ -26,6 +25,7 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.predicate.LessPredicate;
 import org.apache.ambari.server.controller.predicate.NotPredicate;
 import org.apache.ambari.server.controller.predicate.OrPredicate;
+import org.apache.ambari.server.controller.spi.Predicate;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -36,7 +36,7 @@ import java.util.List;
 public class PredicateBuilder {
 
   private String propertyId;
-  private List<BasePredicate> predicates = new LinkedList<BasePredicate>();
+  private List<Predicate> predicates = new LinkedList<Predicate>();
   private Operator operator = null;
   private final PredicateBuilder outer;
   private boolean done = false;
@@ -71,7 +71,7 @@ public class PredicateBuilder {
     return new PredicateBuilder(this);
   }
 
-  public BasePredicate toPredicate() {
+  public Predicate toPredicate() {
     return getPredicate();
   }
 
@@ -85,7 +85,7 @@ public class PredicateBuilder {
     return new PredicateBuilderWithPredicate();
   }
 
-  private void addPredicate(BasePredicate predicate) {
+  private void addPredicate(Predicate predicate) {
     predicates.add(predicate);
   }
 
@@ -97,14 +97,14 @@ public class PredicateBuilder {
     if (predicates.size() == 0) {
       throw new IllegalStateException("No left operand.");
     }
-    BasePredicate predicate;
+    Predicate predicate;
 
     switch (operator) {
       case And:
-        predicate = new AndPredicate(predicates.toArray(new BasePredicate[predicates.size()]));
+        predicate = new AndPredicate(predicates.toArray(new Predicate[predicates.size()]));
         break;
       case Or:
-        predicate = new OrPredicate(predicates.toArray(new BasePredicate[predicates.size()]));
+        predicate = new OrPredicate(predicates.toArray(new Predicate[predicates.size()]));
         break;
       default:
         throw new IllegalStateException("Unknown operator " + this.operator);
@@ -113,11 +113,11 @@ public class PredicateBuilder {
     addPredicate(predicate);
   }
 
-  private BasePredicate getPredicate() {
+  private Predicate getPredicate() {
     handleComparator();
 
     if (predicates.size() == 1) {
-      BasePredicate predicate = predicates.get(0);
+      Predicate predicate = predicates.get(0);
       if (not) {
         predicate = new NotPredicate(predicate);
         not = false;
@@ -199,7 +199,7 @@ public class PredicateBuilder {
       return PredicateBuilder.this;
     }
 
-    public BasePredicate toPredicate() {
+    public Predicate toPredicate() {
       if (outer != null) {
         throw new IllegalStateException("Unbalanced block - missing end.");
       }

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java Tue May 14 15:55:56 2013
@@ -22,7 +22,6 @@ import org.apache.ambari.server.api.reso
 import org.apache.ambari.server.api.util.TreeNode;
 import org.apache.ambari.server.api.util.TreeNodeImpl;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.spi.*;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.api.resources.ResourceInstance;
@@ -317,7 +316,7 @@ public class QueryImplTest {
     Predicate userPredicate = pb.property("foo").equals("bar").toPredicate();
     // combine internal predicate and user predicate
     //todo: for now, need to cast to BasePredicate
-    Predicate predicate = new AndPredicate((BasePredicate) internalPredicate, (BasePredicate) userPredicate);
+    Predicate predicate = new AndPredicate(internalPredicate, userPredicate);
 
     // expectations
     expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitorTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitorTest.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitorTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitorTest.java Tue May 14 15:55:56 2013
@@ -19,10 +19,11 @@ package org.apache.ambari.server.control
 
 import junit.framework.Assert;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.CategoryIsEmptyPredicate;
 import org.apache.ambari.server.controller.predicate.OrPredicate;
+import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.junit.Test;
 
@@ -36,36 +37,36 @@ public class PropertyPredicateVisitorTes
   private static final String PROPERTY_A = PropertyHelper.getPropertyId("category", "A");
   private static final String PROPERTY_B = PropertyHelper.getPropertyId("category", "B");
 
-  private static final BasePredicate PREDICATE_1 = new PredicateBuilder().property(PROPERTY_A).equals("Monkey").toPredicate();
-  private static final BasePredicate PREDICATE_2 = new PredicateBuilder().property(PROPERTY_B).equals("Runner").toPredicate();
-  private static final BasePredicate PREDICATE_3 = new AndPredicate(PREDICATE_1, PREDICATE_2);
-  private static final BasePredicate PREDICATE_4 = new OrPredicate(PREDICATE_1, PREDICATE_2);
-  private static final BasePredicate PREDICATE_5 = new CategoryIsEmptyPredicate("cat1");
+  private static final Predicate PREDICATE_1 = new PredicateBuilder().property(PROPERTY_A).equals("Monkey").toPredicate();
+  private static final Predicate PREDICATE_2 = new PredicateBuilder().property(PROPERTY_B).equals("Runner").toPredicate();
+  private static final Predicate PREDICATE_3 = new AndPredicate(PREDICATE_1, PREDICATE_2);
+  private static final Predicate PREDICATE_4 = new OrPredicate(PREDICATE_1, PREDICATE_2);
+  private static final Predicate PREDICATE_5 = new CategoryIsEmptyPredicate("cat1");
 
   @Test
   public void testVisit() {
     PropertyPredicateVisitor visitor = new PropertyPredicateVisitor();
-    PREDICATE_1.accept(visitor);
+    PredicateHelper.visit(PREDICATE_1, visitor);
     Map<String, Object> properties = visitor.getProperties();
     Assert.assertEquals(1, properties.size());
     Assert.assertEquals("Monkey", properties.get(PROPERTY_A));
 
     visitor = new PropertyPredicateVisitor();
-    PREDICATE_3.accept(visitor);
+    PredicateHelper.visit(PREDICATE_3, visitor);
     properties = visitor.getProperties();
     Assert.assertEquals(2, properties.size());
     Assert.assertEquals("Monkey", properties.get(PROPERTY_A));
     Assert.assertEquals("Runner", properties.get(PROPERTY_B));
 
     visitor = new PropertyPredicateVisitor();
-    PREDICATE_4.accept(visitor);
+    PredicateHelper.visit(PREDICATE_4, visitor);
     properties = visitor.getProperties();
     Assert.assertEquals(2, properties.size());
     Assert.assertEquals("Monkey", properties.get(PROPERTY_A));
     Assert.assertEquals("Runner", properties.get(PROPERTY_B));
 
     visitor = new PropertyPredicateVisitor();
-    PREDICATE_5.accept(visitor);
+    PredicateHelper.visit(PREDICATE_5, visitor);
     properties = visitor.getProperties();
     Assert.assertTrue(properties.isEmpty());
   }

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitorTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitorTest.java?rev=1482411&r1=1482410&r2=1482411&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitorTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SimplifyingPredicateVisitorTest.java Tue May 14 15:55:56 2013
@@ -19,11 +19,12 @@ package org.apache.ambari.server.control
 
 import junit.framework.Assert;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.CategoryIsEmptyPredicate;
 import org.apache.ambari.server.controller.predicate.OrPredicate;
+import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.easymock.Capture;
 import org.junit.Test;
@@ -50,22 +51,22 @@ public class SimplifyingPredicateVisitor
   private static final String PROPERTY_C = PropertyHelper.getPropertyId("category", "C");
   private static final String PROPERTY_D = PropertyHelper.getPropertyId("category", "D");
 
-  private static final BasePredicate PREDICATE_1 = new PredicateBuilder().property(PROPERTY_A).equals("Monkey").toPredicate();
-  private static final BasePredicate PREDICATE_2 = new PredicateBuilder().property(PROPERTY_B).equals("Runner").toPredicate();
-  private static final BasePredicate PREDICATE_3 = new AndPredicate(PREDICATE_1, PREDICATE_2);
-  private static final BasePredicate PREDICATE_4 = new OrPredicate(PREDICATE_1, PREDICATE_2);
-  private static final BasePredicate PREDICATE_5 = new PredicateBuilder().property(PROPERTY_C).equals("Racer").toPredicate();
-  private static final BasePredicate PREDICATE_6 = new OrPredicate(PREDICATE_5, PREDICATE_4);
-  private static final BasePredicate PREDICATE_7 = new PredicateBuilder().property(PROPERTY_C).equals("Power").toPredicate();
-  private static final BasePredicate PREDICATE_8 = new OrPredicate(PREDICATE_6, PREDICATE_7);
-  private static final BasePredicate PREDICATE_9 = new AndPredicate(PREDICATE_1, PREDICATE_8);
-  private static final BasePredicate PREDICATE_10 = new OrPredicate(PREDICATE_3, PREDICATE_5);
-  private static final BasePredicate PREDICATE_11 = new AndPredicate(PREDICATE_4, PREDICATE_10);
-  private static final BasePredicate PREDICATE_12 = new PredicateBuilder().property(PROPERTY_D).equals("Installer").toPredicate();
-  private static final BasePredicate PREDICATE_13 = new AndPredicate(PREDICATE_1, PREDICATE_12);
-  private static final BasePredicate PREDICATE_14 = new PredicateBuilder().property(PROPERTY_D).greaterThan(12).toPredicate();
-  private static final BasePredicate PREDICATE_15 = new AndPredicate(PREDICATE_1, PREDICATE_14);
-  private static final BasePredicate PREDICATE_16 = new CategoryIsEmptyPredicate("cat1");
+  private static final Predicate PREDICATE_1 = new PredicateBuilder().property(PROPERTY_A).equals("Monkey").toPredicate();
+  private static final Predicate PREDICATE_2 = new PredicateBuilder().property(PROPERTY_B).equals("Runner").toPredicate();
+  private static final Predicate PREDICATE_3 = new AndPredicate(PREDICATE_1, PREDICATE_2);
+  private static final Predicate PREDICATE_4 = new OrPredicate(PREDICATE_1, PREDICATE_2);
+  private static final Predicate PREDICATE_5 = new PredicateBuilder().property(PROPERTY_C).equals("Racer").toPredicate();
+  private static final Predicate PREDICATE_6 = new OrPredicate(PREDICATE_5, PREDICATE_4);
+  private static final Predicate PREDICATE_7 = new PredicateBuilder().property(PROPERTY_C).equals("Power").toPredicate();
+  private static final Predicate PREDICATE_8 = new OrPredicate(PREDICATE_6, PREDICATE_7);
+  private static final Predicate PREDICATE_9 = new AndPredicate(PREDICATE_1, PREDICATE_8);
+  private static final Predicate PREDICATE_10 = new OrPredicate(PREDICATE_3, PREDICATE_5);
+  private static final Predicate PREDICATE_11 = new AndPredicate(PREDICATE_4, PREDICATE_10);
+  private static final Predicate PREDICATE_12 = new PredicateBuilder().property(PROPERTY_D).equals("Installer").toPredicate();
+  private static final Predicate PREDICATE_13 = new AndPredicate(PREDICATE_1, PREDICATE_12);
+  private static final Predicate PREDICATE_14 = new PredicateBuilder().property(PROPERTY_D).greaterThan(12).toPredicate();
+  private static final Predicate PREDICATE_15 = new AndPredicate(PREDICATE_1, PREDICATE_14);
+  private static final Predicate PREDICATE_16 = new CategoryIsEmptyPredicate("cat1");
 
   @Test
   public void testVisit() {
@@ -81,9 +82,9 @@ public class SimplifyingPredicateVisitor
 
     replay(provider);
 
-    PREDICATE_1.accept(visitor);
+    PredicateHelper.visit(PREDICATE_1, visitor);
 
-    List<BasePredicate> simplifiedPredicates = visitor.getSimplifiedPredicates();
+    List<Predicate> simplifiedPredicates = visitor.getSimplifiedPredicates();
 
     Assert.assertEquals(1, simplifiedPredicates.size());
     Assert.assertEquals(PREDICATE_1, simplifiedPredicates.get(0));
@@ -91,7 +92,7 @@ public class SimplifyingPredicateVisitor
     assertEquals(1, setProps.size());
     assertEquals(PROPERTY_A, setProps.iterator().next());
     // ---
-    PREDICATE_3.accept(visitor);
+    PredicateHelper.visit(PREDICATE_3, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -99,7 +100,7 @@ public class SimplifyingPredicateVisitor
     Assert.assertEquals(PREDICATE_3, simplifiedPredicates.get(0));
 
     // ---
-    PREDICATE_4.accept(visitor);
+    PredicateHelper.visit(PREDICATE_4, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -108,7 +109,7 @@ public class SimplifyingPredicateVisitor
     Assert.assertEquals(PREDICATE_2, simplifiedPredicates.get(1));
 
     // ---
-    PREDICATE_6.accept(visitor);
+    PredicateHelper.visit(PREDICATE_6, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -118,7 +119,7 @@ public class SimplifyingPredicateVisitor
     Assert.assertEquals(PREDICATE_2, simplifiedPredicates.get(2));
 
     // ---
-    PREDICATE_8.accept(visitor);
+    PredicateHelper.visit(PREDICATE_8, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -129,7 +130,7 @@ public class SimplifyingPredicateVisitor
     Assert.assertEquals(PREDICATE_7, simplifiedPredicates.get(3));
 
     // ---
-    PREDICATE_9.accept(visitor);
+    PredicateHelper.visit(PREDICATE_9, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -137,7 +138,7 @@ public class SimplifyingPredicateVisitor
 //    Assert.assertEquals(???, simplifiedPredicates.get(0));
 
     // ---
-    PREDICATE_11.accept(visitor);
+    PredicateHelper.visit(PREDICATE_11, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -145,7 +146,7 @@ public class SimplifyingPredicateVisitor
 //    Assert.assertEquals(???, simplifiedPredicates.get(0));
 
     // ---
-    PREDICATE_16.accept(visitor);
+    PredicateHelper.visit(PREDICATE_16, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -160,7 +161,7 @@ public class SimplifyingPredicateVisitor
     replay(provider);
 
     // ---
-    PREDICATE_13.accept(visitor);
+    PredicateHelper.visit(PREDICATE_13, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 
@@ -173,7 +174,7 @@ public class SimplifyingPredicateVisitor
     replay(provider);
 
     // ---
-    PREDICATE_15.accept(visitor);
+    PredicateHelper.visit(PREDICATE_15, visitor);
 
     simplifiedPredicates = visitor.getSimplifiedPredicates();
 



Mime
View raw message