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

com.datatorrent.lib.math.LogicalCompare 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.math;

import com.datatorrent.api.DefaultInputPort;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.annotation.Stateless;
import com.datatorrent.common.util.BaseOperator;
import com.datatorrent.common.util.Pair;

/**
 * This operator compares the two values in a given pair <T,T> object which are of the comparable property, and emits the pair on appropriate port denoting the result of the comparison.
 * 

* If the first value is equal to second value, then the pair is emitted on equalTo, greaterThanEqualTo, and lessThanEqualTo ports. * If the first value is less than second value, then the pair is emitted on notEqualTo, lessThan and lessThanEqualTo ports. * If the first value is greater than second value, then the pair is emitted on notEqualTo, greaterThan and greaterThanEqualTo ports. * This is a pass through operator. *
* StateFull : No, output is computed during current window.
* Partitions : Yes, no dependency among input tuples.
*
* Ports:
* input: expects Pair<T,T>
* equalTo: emits Pair<T,T>
* notEqualTo: emits Pair<T,T>
* greaterThanEqualTo: emits Pair<T,T>
* greaterThan: emits Pair<T,T>
* lessThanEqualTo: emits Pair<T,T>
* lessThan: emits Pair<T,T>
*
* @displayName Logical Compare * @category Math * @tags comparison, logical, key value * @since 0.3.3 */ @Stateless public abstract class LogicalCompare> extends BaseOperator { /** * Input port that takes a key, value pair for comparison. */ public final transient DefaultInputPort> input = new DefaultInputPort>() { @Override public void process(Pair tuple) { int i = tuple.first.compareTo(tuple.second); if (i > 0) { greaterThan.emit(tuple); greaterThanOrEqualTo.emit(tuple); notEqualTo.emit(tuple); } else if (i < 0) { lessThan.emit(tuple); lessThanOrEqualTo.emit(tuple); notEqualTo.emit(tuple); } else { equalTo.emit(tuple); lessThanOrEqualTo.emit(tuple); greaterThanOrEqualTo.emit(tuple); } } }; /** * Equal output port. */ public final transient DefaultOutputPort> equalTo = new DefaultOutputPort>(); /** * Not Equal output port. */ public final transient DefaultOutputPort> notEqualTo = new DefaultOutputPort>(); /** * Less than output port. */ public final transient DefaultOutputPort> lessThan = new DefaultOutputPort>(); /** * Greater than output port. */ public final transient DefaultOutputPort> greaterThan = new DefaultOutputPort>(); /** * Less than equal to output port. */ public final transient DefaultOutputPort> lessThanOrEqualTo = new DefaultOutputPort>(); /** * Greater than equal to output port. */ public final transient DefaultOutputPort> greaterThanOrEqualTo = new DefaultOutputPort>(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy