Given a tabular data structure, for example. arraylist arraylists (2D array or some other repeating data structure), what would be the cleanest way to validate elements against specific rules?
For example, we give the following data:
[true, false, false, true]
[false, false, false, false]
[true, false, false, false]
How can I ensure that any of the three conditions is met:
- all elements in all rows
true - all elements in all rows
false - If the string contains mixed values, then only the first element can be
true, otherwise the check should fail.
For example, the above data should not be verified due to the value truein position [0, 3].
UPDATE:
-, Java 8 myBoolArrayList.stream().allMatch(Boolean::booleanValue); myBoolArrayList.stream().noneMatch(Boolean::booleanValue); - , , .