com.streambase.sb.unittest

## Class FieldBasedTupleComparator

- java.lang.Object
- - com.streambase.sb.unittest.FieldBasedTupleComparator

- All Implemented Interfaces:
    TupleComparator

      public class FieldBasedTupleComparator
      extends Object
      implements TupleComparator

  A `TupleComparator` that compares tuples in a naive field-by-field manner. Comparison of individual field types can be controlled using `FieldBasedTupleComparator.CompareFunctor`s. A subset of the fields for a tuple can by explicitly specifying the field names.

  `FieldBasedTupleComparator.DEFAULT_COMPARATOR` provides a reasonable default comparison of tuples.

  `FieldBasedTupleComparator.DEFAULT_COMPARE_REGISTRY` provides a filled in registry of default `FieldBasedTupleComparator.CompareFunctor`s.

  Since:
    6.6

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FieldBasedTupleComparator.CompareFunctor` A strategy object for handling comparisons of specific field types.
    `static class` | `FieldBasedTupleComparator.DoubleCompareFunctor` Compare double values using a ratio test and a tolerance.
    `static class` | `FieldBasedTupleComparator.IgnoreTimestampCompareFunctor`
    `static class` | `FieldBasedTupleComparator.ListCompareFunctor`
    `static class` | `FieldBasedTupleComparator.NaiveObjectCompareFunctor`
    `static class` | `FieldBasedTupleComparator.RegexCompareFunctor` Check if the second argument matches the regex defined for the first argument.
    `static class` | `FieldBasedTupleComparator.TupleCompareFunctor`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static FieldBasedTupleComparator` | `DEFAULT_COMPARATOR`
    `static DataType.Registry<FieldBasedTupleComparator.CompareFunctor>` | `DEFAULT_COMPARE_REGISTRY`
    `static Map<DataType,FieldBasedTupleComparator.CompareFunctor>` | `DEFAULT_FUNCTOR_MAP`
    `static FieldBasedTupleComparator` | `IGNORE_TIMESTAMP_COMPARATOR`
    `static FieldBasedTupleComparator` | `REGEX_COMPARATOR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FieldBasedTupleComparator(DataType.Registry<FieldBasedTupleComparator.CompareFunctor> comparators, String... fields)`
    `FieldBasedTupleComparator(FieldBasedTupleComparator baseComparator, String... fields)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `compare(Tuple expected, Tuple actual)` Compare two tuples.
    `boolean` | `compareValues(CompleteDataType cdt, Object expected, Object actual)` Compare two values with `CompleteDataType` cdt.
    `String` | `formatForErrorMessage(Tuple t)` Convert the provided Tuple into a string appropriate for error messages.

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

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

- - ### Field Detail

    - #### DEFAULT_FUNCTOR_MAP

          public static final Map<DataType,FieldBasedTupleComparator.CompareFunctor> DEFAULT_FUNCTOR_MAP

    - #### DEFAULT_COMPARE_REGISTRY

          public static final DataType.Registry<FieldBasedTupleComparator.CompareFunctor> DEFAULT_COMPARE_REGISTRY

    - #### DEFAULT_COMPARATOR

          public static final FieldBasedTupleComparator DEFAULT_COMPARATOR

    - #### REGEX_COMPARATOR

          public static final FieldBasedTupleComparator REGEX_COMPARATOR

    - #### IGNORE_TIMESTAMP_COMPARATOR

          public static final FieldBasedTupleComparator IGNORE_TIMESTAMP_COMPARATOR

  - ### Constructor Detail

    - #### FieldBasedTupleComparator

          public FieldBasedTupleComparator(DataType.Registry<FieldBasedTupleComparator.CompareFunctor> comparators,
                                           String... fields)
                                    throws StreamBaseException

      Throws:
        `StreamBaseException`

    - #### FieldBasedTupleComparator

          public FieldBasedTupleComparator(FieldBasedTupleComparator baseComparator,
                                           String... fields)
                                    throws StreamBaseException

      Throws:
        `StreamBaseException`

  - ### Method Detail

    - #### compare

          public boolean compare(Tuple expected,
                                 Tuple actual)
                          throws StreamBaseException

      Description copied from interface: `TupleComparator`
      Compare two tuples.
      Specified by:
        `compare` in interface `TupleComparator`
      Parameters:
        `expected` - The expected value
        `actual` - The actual value
      Returns:
        true if the tuples are equal
      Throws:
        `StreamBaseException`

    - #### compareValues

          public boolean compareValues(CompleteDataType cdt,
                                       Object expected,
                                       Object actual)
                                throws StreamBaseException

      Description copied from interface: `TupleComparator`
      Compare two values with `CompleteDataType` cdt.
      Specified by:
        `compareValues` in interface `TupleComparator`
      Parameters:
        `cdt` - The `CompleteDataType` for the objects being compared
        `expected` - The expected value
        `actual` - The actual value
      Returns:
        true if the values are equal
      Throws:
        `StreamBaseException`

    - #### formatForErrorMessage

          public String formatForErrorMessage(Tuple t)

      Description copied from interface: `TupleComparator`
      Convert the provided Tuple into a string appropriate for error messages. Some comparators may wish to omit fields that are not salient to the comparison.
      Specified by:
        `formatForErrorMessage` in interface `TupleComparator`
      Parameters:
        `t` - The tuple to format
      Returns:
        A human readable string.

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