java.lang.Object
org.apache.storm.trident.operation.builtin.Negate
All Implemented Interfaces:
Serializable, EachOperation, Filter, Operation

public class Negate extends Object implements Filter
A `Filter` implementation that inverts another delegate `Filter`.

The `Negate.isKeep()` method simply returns the opposite of the delegate's `isKeep()` method:

```java public boolean isKeep(TridentTuple tuple) { return !this.delegate.isKeep(tuple); } ```

The `Negate` filter is useful for dividing a Stream in two based on some boolean condition.

Suppose we had a Stream named `userStream` containing information about users, and a custom `Filter` implementation, `RegisteredUserFilter` that filtered out unregistered users. We could divide the `userStream` Stream into two separate Streams -- one for registered users, and one for unregistered users -- by doing the following:

```java Stream userStream = ...

Filter registeredFilter = new ResisteredUserFilter(); Filter unregisteredFilter = new Negate(registeredFilter);

Stream registeredUserStream = userStream.each(userStream.getOutputFields(), registeredFilter); Stream unregisteredUserStream = userStream.each(userStream.getOutputFields(), unregisteredFilter); ```

See Also:
  • Constructor Details

    • Negate

      public Negate(Filter delegate)
  • Method Details

    • isKeep

      public boolean isKeep(TridentTuple tuple)
      Description copied from interface: Filter
      Determines if a tuple should be filtered out of a stream.
      Specified by:
      isKeep in interface Filter
      Parameters:
      tuple - the tuple being evaluated
      Returns:
      `false` to drop the tuple, `true` to keep the tuple
    • prepare

      public void prepare(Map<String,Object> conf, TridentOperationContext context)
      Description copied from interface: Operation
      Called when the `Operation` is first initialized.
      Specified by:
      prepare in interface Operation
      Parameters:
      conf - the Storm configuration map
      context - the operation context which provides information such as the number of partitions in the stream, and the current partition index. It also provides methods for registering operation-specific metrics.
      See Also:
    • cleanup

      public void cleanup()
      Description copied from interface: Operation
      When running in local mode, called when the local cluster is being shut down.
      Specified by:
      cleanup in interface Operation