use of io.spine.server.reflect.Field in project core-java by SpineEventEngine.
the class MatchFilter method checkFields.
private static boolean checkFields(Message object, FieldFilter filter) {
final Optional<Field> fieldOptional = Field.forFilter(object.getClass(), filter);
if (!fieldOptional.isPresent()) {
return false;
}
final Field field = fieldOptional.get();
final Optional<Message> value;
try {
value = field.getValue(object);
} catch (IllegalStateException ignored) {
// Wrong Message class -> does not satisfy the criteria.
return false;
}
final Collection<Any> expectedAnys = filter.getValueList();
final Collection<Message> expectedValues = Collections2.transform(expectedAnys, unpackFunc());
if (!value.isPresent()) {
/* If there is no value in the field return `true`
if the list of required values is also empty. */
final boolean nothingIsExpected = expectedValues.isEmpty();
return nothingIsExpected;
}
final boolean result = expectedValues.contains(value.get());
return result;
}