public class FieldBasedTupleMatcher extends java.lang.Object implements TupleMatcher, ValueMatcher, IgnoreNullTransform, IgnoreFieldTransform
FieldBasedTupleMatcher
matches tuples by comparing their fields against
ValueMatcher
s. It can be used as a ValueMatcher
for sub-tuples
as well. More complicated behavior can be achieved by calling configuration
methods. For example:
FieldBasedTupleMatcher m = FieldBasedTupleMatcher.of(t) .ignoreNulls() .require("name", "Steven") .requireNonNull("value");Warning:
FieldBasedTupleMatcher
instances are always immutable;
a configuration method such as code>ignoreNulls has no effect on the
instance it is invoked on.Modifier and Type | Method and Description |
---|---|
com.google.gson.JsonElement |
describe(com.google.gson.Gson gson)
get a description of the matcher suitable
for use in error messages.
|
static FieldBasedTupleMatcher |
empty()
get a
FieldBasedTupleMatcher which will match anything. |
FieldBasedTupleMatcher |
ignore(java.lang.String field)
get an identical
FieldBasedTupleMatcher to this, except
that it will ignore the field identified by field
TODO: it is possible to "ignore" fields that actually do not exist in the Schema |
ValueMatcher |
ignoreField(java.lang.String field)
|
FieldBasedTupleMatcher |
ignoreNulls()
get an identical
FieldBasedTupleMatcher to this, except
that it will ignore any null values that it is currently
configured to enforce. |
boolean |
matches(java.lang.Object field)
determine whether or not a value matches
|
boolean |
matches(com.streambase.sb.Tuple t)
determine whether t matches.
|
static FieldBasedTupleMatcher |
of(java.util.LinkedHashMap<java.lang.String,ValueMatcher> matchers)
get a
FieldBasedTupleMatcher with all the provided matchers. |
FieldBasedTupleMatcher |
require(java.lang.String field,
java.lang.Object val)
get an identical
FieldBasedTupleMatcher to this, except
that it will require the field identified by field to match
the literal val . |
FieldBasedTupleMatcher |
require(java.lang.String field,
ValueMatcher m)
get an identical
FieldBasedTupleMatcher to this, except
that it will require the field identified by field to match
m |
FieldBasedTupleMatcher |
requireNonNull(java.lang.String field)
get an identical
FieldBasedTupleMatcher to this, except
that it will require the field identified by field to be
non-null. |
FieldBasedTupleMatcher |
requireNull(java.lang.String field)
get an identical
FieldBasedTupleMatcher to this, except
that it will require the field identified by field to be
null. |
public static FieldBasedTupleMatcher empty()
FieldBasedTupleMatcher
which will match anything.
This is usually used as a base for more complicated matchers.public static FieldBasedTupleMatcher of(java.util.LinkedHashMap<java.lang.String,ValueMatcher> matchers)
FieldBasedTupleMatcher
with all the provided matchers.matchers
- A map of field names to matchers.public FieldBasedTupleMatcher ignoreNulls()
FieldBasedTupleMatcher
to this, except
that it will ignore any null values that it is currently
configured to enforce.ignoreNulls
in interface IgnoreNullTransform
public FieldBasedTupleMatcher ignore(java.lang.String field)
FieldBasedTupleMatcher
to this, except
that it will ignore the field identified by field
TODO: it is possible to "ignore" fields that actually do not exist in the Schemapublic ValueMatcher ignoreField(java.lang.String field)
IgnoreFieldTransform
ValueMatcher
like this
but that will
ignore sub-fields with the name field
. If the result
would be a trivial ValueMatcher
, return null
instead.ignoreField
in interface IgnoreFieldTransform
field
- The field to ignorepublic FieldBasedTupleMatcher require(java.lang.String field, ValueMatcher m)
FieldBasedTupleMatcher
to this, except
that it will require the field identified by field
to match
m
public FieldBasedTupleMatcher require(java.lang.String field, java.lang.Object val)
FieldBasedTupleMatcher
to this, except
that it will require the field identified by field
to match
the literal val
.
Equivalent to require(field, Matchers.literal(val))
.public FieldBasedTupleMatcher requireNull(java.lang.String field)
FieldBasedTupleMatcher
to this, except
that it will require the field identified by field
to be
null.
Equivalent to require(field, Matchers.isNull())
.public FieldBasedTupleMatcher requireNonNull(java.lang.String field)
FieldBasedTupleMatcher
to this, except
that it will require the field identified by field
to be
non-null.
Equivalent to require(field, Matchers.isNonNull())
.public boolean matches(java.lang.Object field) throws com.streambase.sb.TupleException
ValueMatcher
matches
in interface ValueMatcher
com.streambase.sb.TupleException
public boolean matches(com.streambase.sb.Tuple t) throws com.streambase.sb.TupleException
TupleMatcher
matches
in interface TupleMatcher
com.streambase.sb.TupleException
public com.google.gson.JsonElement describe(com.google.gson.Gson gson)
TupleMatcher
describe
in interface TupleMatcher
describe
in interface ValueMatcher