All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datatorrent.lib.streamquery.condition.BetweenCondition Maven / Gradle / Ivy

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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. 
*

* Properties :
* column : Name of column.
* leftValue : left range of column value.
* rightValue : right range od column value.
*
* @displayName Between Condition * @category Stream Manipulators * @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.
* @param leftValue Left range for value, mut be non null.
* @param rightValue right range for value, mut be non null.
*/ 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 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 row1, Map row2) { assert (false); return false; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy