BinaryComparisonOperator.java

  1. package de.turnertech.ows.filter;

  2. import de.turnertech.ows.gml.IFeature;

  3. public class BinaryComparisonOperator implements ComparisonOperator {

  4.     private final Expression leftExpression;

  5.     private final BinaryComparisonName operatorType;

  6.     private final Expression rightExpression;

  7.     private boolean matchCase;

  8.     private MatchAction matchAction;

  9.     public BinaryComparisonOperator(final Expression leftExpression, BinaryComparisonName operatorType, final Expression rightExpression) {
  10.         this.leftExpression = leftExpression;
  11.         this.operatorType = operatorType;
  12.         this.rightExpression = rightExpression;
  13.         this.matchCase = true;
  14.         this.matchAction = MatchAction.ANY;
  15.     }
  16.    
  17.     public Expression getLeftExpression() {
  18.         return leftExpression;
  19.     }

  20.     public BinaryComparisonName getOperatorType() {
  21.         return operatorType;
  22.     }

  23.     public Expression getRightExpression() {
  24.         return rightExpression;
  25.     }

  26.     public boolean isMatchCase() {
  27.         return matchCase;
  28.     }

  29.     public BinaryComparisonOperator setMatchCase(boolean matchCase) {
  30.         this.matchCase = matchCase;
  31.         return this;
  32.     }

  33.     public MatchAction getMatchAction() {
  34.         return matchAction;
  35.     }

  36.     public BinaryComparisonOperator setMatchAction(MatchAction matchAction) {
  37.         this.matchAction = matchAction;
  38.         return this;
  39.     }

  40.     @Override
  41.     public boolean test(IFeature feature) {
  42.         // Special case handling for null.
  43.         if(leftExpression == null && rightExpression == null && operatorType.equals(BinaryComparisonName.PROPERTY_IS_EQUAL_TO)) {
  44.             return true;
  45.         }
  46.         if(leftExpression == null || rightExpression == null) {
  47.             return false;
  48.         }

  49.         final Object left = leftExpression.apply(feature);
  50.         final Object right = rightExpression.apply(feature);

  51.         return operatorType.test(left, right, matchCase);
  52.     }
  53.    
  54. }