blob: ffa9a681f933bf6a3b32c51aa0ec1e65bb48178a [file] [log] [blame]
/*
* Copyright (c) 2013 DataTorrent, Inc. ALL Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datatorrent.lib.streamquery.condition;
import java.util.Map;
import javax.validation.constraints.NotNull;
/**
* A derivation of Condition that validates row by checking if the given column name value lies between given left,right range. <br>
* <p>
* <b>Properties : </b> <br>
* <b> column : </b> Name of column. <br>
* <b> leftValue : </b> left range of column value. <br>
* <b> rightValue : </b> right range od column value. <br>
* <br>
* @displayName Between Condition
* @category Streamquery/Condition
* @tags sql condition
* @since 0.3.4
*/
public class BetweenCondition extends Condition
{
/**
* Column name to be checked.
*/
@NotNull
private String column;
/**
* Left range value.
*/
@NotNull
private Object leftValue;
/**
* Right range value.
*/
@NotNull
private Object rightValue;
/**
* @param column Name of column, must be non null. <br>
* @param leftValue Left range for value, mut be non null. <br>
* @param rightValue right range for value, mut be non null. <br>
*/
public BetweenCondition(@NotNull String column, @NotNull Object leftValue, @NotNull Object rightValue)
{
this.column = column;
this.leftValue = leftValue;
this.rightValue = rightValue;
}
/**
* Validate given row.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public boolean isValidRow(@NotNull Map<String, Object> row)
{
if (!row.containsKey(column)) return false;
Object value = row.get(column);
if (value == null) return false;
if (((Comparable)value).compareTo((Comparable)leftValue) < 0) return false;
if (((Comparable)value).compareTo((Comparable)rightValue) > 0) return false;
return true;
}
/**
* Must not be called.
*/
@Override
public boolean isValidJoin(@NotNull Map<String, Object> row1, Map<String, Object> row2)
{
assert(false);
return false;
}
}