cascading.operation.filter

## Class Sample

- java.lang.Object
- - cascading.operation.BaseOperation<java.util.Random>
  - - cascading.operation.filter.Sample

- All Implemented Interfaces:
    DeclaresResults, Filter<java.util.Random>, Operation<java.util.Random>, Traceable, java.io.Serializable

      public class Sample
      extends BaseOperation<java.util.Random>
      implements Filter<java.util.Random>

  Class Sample is a `Filter` that only allows the given fraction of `Tuple` instances to pass.

  Where fraction is between 1 and zero, inclusive. Thus to sample `50%` of the tuples in a stream, use the fraction `0.5`.

  By default, the seed is created at random on the constructor. This implies every branch using the Sample filter will return the same random stream based on that seed. So if this Sample instance is distributed into multiple systems against the same data, the result will be the same tuple stream. The alternative would be to make this Operation "not safe". See `Operation.isSafe()`.

  Conversely, if the same stream of random data is require across application executions, set the seed manually.

  The seed is generated from the following code:

  `System.identityHashCode(this) * 2654435761L ^ System.currentTimeMillis()`

  Override `makeSeed()` to customize.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class cascading.operation.BaseOperation

      `fieldDeclaration, numArgs, trace`

    - ### Fields inherited from interface cascading.operation.Operation

      `ANY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Sample(double fraction)` Creates a new Sample that permits percent Tuples to pass.
    `Sample(long seed, double fraction)` Creates a new Sample that permits percent Tuples to pass.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(java.lang.Object object)`
    `double` | `getFraction()`
    `long` | `getSeed()`
    `int` | `hashCode()`
    `boolean` | `isRemove(FlowProcess flowProcess, FilterCall<java.util.Random> filterCall)` Method isRemove returns true if input should be removed from the tuple stream.
    `protected long` | `makeSeed()`
    `void` | `prepare(FlowProcess flowProcess, OperationCall<java.util.Random> operationCall)` Method prepare does nothing, and may safely be overridden.

    - ### Methods inherited from class cascading.operation.BaseOperation

      `cleanup, flush, getFieldDeclaration, getNumArgs, getTrace, isSafe, printOperationInternal, toString, toStringInternal`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface cascading.operation.Operation

      `cleanup, flush, getFieldDeclaration, getNumArgs, isSafe`

- - ### Constructor Detail

    - #### Sample

          @ConstructorProperties(value="fraction")
          public Sample(double fraction)

      Creates a new Sample that permits percent Tuples to pass.
      Parameters:
        `fraction` - of type double

    - #### Sample

          @ConstructorProperties(value={"seed","fraction"})
          public Sample(long seed,
                                      double fraction)

      Creates a new Sample that permits percent Tuples to pass. The given seed value seeds the random number generator.
      Parameters:
        `seed` - of type long
        `fraction` - of type double

  - ### Method Detail

    - #### getSeed

          public long getSeed()

    - #### getFraction

          public double getFraction()

    - #### makeSeed

          protected long makeSeed()

    - #### prepare

          public void prepare(FlowProcess flowProcess,
                     OperationCall<java.util.Random> operationCall)

      Description copied from class: `BaseOperation`
      Method prepare does nothing, and may safely be overridden.
      Specified by:
        `prepare` in interface `Operation<java.util.Random>`
      Overrides:
        `prepare` in class `BaseOperation<java.util.Random>`

    - #### isRemove

          public boolean isRemove(FlowProcess flowProcess,
                         FilterCall<java.util.Random> filterCall)

      Description copied from interface: `Filter`
      Method isRemove returns true if input should be removed from the tuple stream.
      Specified by:
        `isRemove` in interface `Filter<java.util.Random>`
      Parameters:
        `flowProcess` - of type FlowProcess
        `filterCall` - of type FilterCall
      Returns:
        boolean

    - #### equals

          public boolean equals(java.lang.Object object)

      Overrides:
        `equals` in class `BaseOperation<java.util.Random>`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `BaseOperation<java.util.Random>`

Copyright © 2007-2015 Xplenty, Inc. All Rights Reserved.