com.streambase.sb

## Class TupleCopier

- java.lang.Object
- - com.streambase.sb.DataTypeCopier
  - - com.streambase.sb.TupleCopier

-     public class TupleCopier
      extends DataTypeCopier

  A utility class which copies the fields from one tuple to another. TupleCopier uses the given schemas to determine which fields to copy from one Tuple to another. The strict flag on the ctor determines if an Exception is thrown if the fields in the destination schema do not match the fields in the source schema. Fields are matched by name and type. With the strict flag set to false the TupleCopier will only copy the fields between the source and destination that match field name and type. TupleCopier is more efficient than using Tuple's getField(), setField() methods to copy portions of a tuple. TupleCopier's constructor sets up the TupleCopier so that repeated calls to copyTuple() are more efficent. If a full copy is desired Tuple.clone() is probably a more efficient option. An example usage:

  >          ...
  >          TupleCopier input2OutputCopier = new TupleCopier(inputSchema, outputSchema, true);

  >          while (true) {
  >             outputTuple.clear();
  >             input2OutputCopier.copyTuple(getInputTuple(), outputTuple);
  >             sendOutput(port, outputTuple);
  >          }

  Since:
    6.4.5
  See Also:
    `Tuple.clone()`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TupleCopier.Options` Options for this TupleCopier

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TupleCopier(Schema sourceSchema, Schema destSchema, boolean strict)` Create the TupleCopier.
    `TupleCopier(Schema sourceSchema, Schema destSchema, EnumSet<TupleCopier.Options> options)` Create the TupleCopier.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) List<?>` | `copyList(List<?> sourceList)` Copy the given list
    `void` | `copyTuple(Tuple sourceTuple, Tuple destTuple)` Copy the fields from the sourceTuple to the destTuple.

    - ### Methods inherited from class com.streambase.sb.DataTypeCopier

      `copyField, copyList, createCopier`

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TupleCopier

          public TupleCopier(Schema sourceSchema,
                             Schema destSchema,
                             boolean strict)
                      throws TupleException

      Create the TupleCopier. Do some up front error checking and setting up Schema maps. This constructor will create a TupleCopier with #CopyByName semantics.
      Parameters:
        `sourceSchema` - The schema of the source Tuple
        `destSchema` - The schema of the destination tuple
        `strict` - set to true will throw exceptions if schema fields do not match by name and type. Set to false and the TupleCopier will copy only fields that match by name and type.
      Throws:
        `TupleException` - with strict on if the fields do not match by name and type

    - #### TupleCopier

          public TupleCopier(Schema sourceSchema,
                             Schema destSchema,
                             EnumSet<TupleCopier.Options> options)
                      throws TupleException

      Create the TupleCopier. Do some up front error checking and setting up Schema maps.
      Parameters:
        `sourceSchema` - The schema of the source Tuple
        `destSchema` - The schema of the destination tuple
        `options` - options from `TupleCopier.Options`
      Throws:
        `TupleException` - with strict on if the fields do not match by name and type
      Since:
        7.0

  - ### Method Detail

    - #### copyTuple

          public void copyTuple(Tuple sourceTuple,
                                Tuple destTuple)
                         throws TupleException

      Copy the fields from the sourceTuple to the destTuple. It is assumed that the destination Tuple is either new or has been cleared.
      Parameters:
        `sourceTuple` - the source tuple
        `destTuple` - the cleared destination tuple
      Throws:
        `TupleException` - on field copy errors

    - #### copyList

          List<?> copyList(List<?> sourceList)
                    throws TupleException

      Description copied from class: `DataTypeCopier`
      Copy the given list
      Specified by:
        `copyList` in class `DataTypeCopier`
      Parameters:
        `sourceList` - the list to copy
      Returns:
        a new list
      Throws:
        `TupleException` - on error

Copyright © 2015–2018 Cloud Software Group, Inc.. All rights reserved.