I need a solution for decision making chain. There are number of criteria that may return true, false or be inconclusive. A non-functional code (Java) would look like this:
Boolean res = nullValuesCheck(fieldValue, node);
if (res != null) {
return res;
}
res = typeCheck(node);
if (res != null) {
return res;
}
res = dictCheck(dict, fieldValue);
if (res != null) {
return res;
}
return finalCheck(fieldName, fieldValue); //also returns a Boolean
I'm considering creating an extended predicate that would return a nullable Boolean
instead of boolean
, so that an inconclusive result could be returned.
I tried googling, but found no apparent solution (got lot of mishits on some simple java problems instead). I am wondering whether there exists a pattern, a library maybe, that would handle this problem properly. The problem seems generic and simple to solve and someone must've solved it already. I don't want to reinvent the wheel.