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

com.datatorrent.lib.math.ExceptMap 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 java.util.HashMap;
import java.util.Map;

import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.annotation.Stateless;
import com.datatorrent.lib.algo.MatchMap;
import com.datatorrent.lib.util.UnifierHashMap;

/**
 * This operator does comparison on tuple sub-classed from Number based on the property "key", "value", and "cmp", and not matched tuples are emitted.
 * 

* The comparison is done by getting double value from the Number. Both output ports * are optional, but at least one has to be connected *

* This module is a pass through
*
*
* StateFull : No, output is emitted in current window.
* Partitions : Yes, No state dependency among input tuples.
*
* Ports:
* data: expects Map<K,V extends Number>
* except: emits HashMap<K,V>
*
* Properties:
* key: The key on which compare is done
* value: The value to compare with
* cmp: The compare function. Supported values are "lte", "lt", "eq", * "neq", "gt", "gte". Default is "eq"
*
* Compile time checks:
* Key must be non empty
* Value must be able to convert to a "double"
* Compare string, if specified, must be one of "lte", "lt", "eq", "neq", "gt", * "gte"
*
* Run time checks:
* Does the incoming HashMap have the key, Is the value of the key a number
*
* @displayName Except Map * @category Math * @tags comparison, Number * @since 0.3.3 */ @Stateless public class ExceptMap extends MatchMap { /** * Output port that emits non matching number tuples. */ public final transient DefaultOutputPort> except = new DefaultOutputPort>() { @Override public Unifier> getUnifier() { return new UnifierHashMap(); } }; /** * Does nothing. Overrides base as call super.tupleMatched() would emit the * tuple * * @param tuple */ @Override public void tupleMatched(Map tuple) { } /** * Emits the tuple. Calls cloneTuple to get a copy, allowing users to override * in case objects are mutable * * @param tuple */ @Override public void tupleNotMatched(Map tuple) { except.emit(cloneTuple(tuple)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy