Package com.streambase.sb.unittest
Class FieldBasedTupleComparator
java.lang.Object
com.streambase.sb.unittest.FieldBasedTupleComparator
- All Implemented Interfaces:
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.
DEFAULT_COMPARATOR
provides a reasonable default comparison of tuples.
DEFAULT_COMPARE_REGISTRY
provides a filled in registry of default FieldBasedTupleComparator.CompareFunctor
s.
- Since:
- 6.6
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A strategy object for handling comparisons of specific field types.static class
Compare double values using a ratio test and a tolerance.static class
Ignore timestamp compare functorstatic class
List compare functorstatic class
Simple object compare functorstatic class
Check if the second argument matches the regex defined for the first argument.static class
Tuple compare functor -
Field Summary
Modifier and TypeFieldDescriptionstatic final FieldBasedTupleComparator
Default comparatorstatic final com.streambase.sb.DataType.Registry<FieldBasedTupleComparator.CompareFunctor>
Default compare functor registrystatic final Map<DataType,
FieldBasedTupleComparator.CompareFunctor> Default functor data type to functor mapstatic final FieldBasedTupleComparator
Ignore timestamp comparatorstatic final FieldBasedTupleComparator
Regular expression comparator -
Constructor Summary
ConstructorDescriptionFieldBasedTupleComparator
(com.streambase.sb.DataType.Registry<FieldBasedTupleComparator.CompareFunctor> comparators, String... fields) ConstructorFieldBasedTupleComparator
(FieldBasedTupleComparator baseComparator, String... fields) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compare two tuples.boolean
compareValues
(CompleteDataType cdt, Object expected, Object actual) Compare two values withCompleteDataType
cdt.Convert the provided Tuple into a string appropriate for error messages.
-
Field Details
-
DEFAULT_FUNCTOR_MAP
Default functor data type to functor map -
DEFAULT_COMPARE_REGISTRY
public static final com.streambase.sb.DataType.Registry<FieldBasedTupleComparator.CompareFunctor> DEFAULT_COMPARE_REGISTRYDefault compare functor registry -
DEFAULT_COMPARATOR
Default comparator -
REGEX_COMPARATOR
Regular expression comparator -
IGNORE_TIMESTAMP_COMPARATOR
Ignore timestamp comparator
-
-
Constructor Details
-
FieldBasedTupleComparator
public FieldBasedTupleComparator(com.streambase.sb.DataType.Registry<FieldBasedTupleComparator.CompareFunctor> comparators, String... fields) throws StreamBaseException Constructor- Parameters:
comparators
- comparatorsfields
- fields to compare- Throws:
StreamBaseException
- initialization error
-
FieldBasedTupleComparator
public FieldBasedTupleComparator(FieldBasedTupleComparator baseComparator, String... fields) throws StreamBaseException Constructor- Parameters:
baseComparator
- base comparatorfields
- fields to compare- Throws:
StreamBaseException
- initialization error
-
-
Method Details
-
compare
Description copied from interface:TupleComparator
Compare two tuples.- Specified by:
compare
in interfaceTupleComparator
- Parameters:
expected
- The expected valueactual
- The actual value- Returns:
- true if the tuples are equal
- Throws:
StreamBaseException
- error comparing tuples
-
compareValues
public boolean compareValues(CompleteDataType cdt, Object expected, Object actual) throws StreamBaseException Description copied from interface:TupleComparator
Compare two values withCompleteDataType
cdt.- Specified by:
compareValues
in interfaceTupleComparator
- Parameters:
cdt
- TheCompleteDataType
for the objects being comparedexpected
- The expected valueactual
- The actual value- Returns:
- true if the values are equal
- Throws:
StreamBaseException
- error comparing tuples
-
formatForErrorMessage
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 interfaceTupleComparator
- Parameters:
t
- The tuple to format- Returns:
- A human readable string.
-