I am using this method:
public boolean checkRowsFilterNameBy(String filter){
waitForElmContainsText(searchButton, "Search");
List<AuditRow> listRows = auditTable.getTable();
for(AuditRow row : listRows){
if(!row.nameStr.equals(filter)||!row.nameStr.contains(filter))
return false;
}
return true;
}
and I want to be able to change it using Stream , I've tried the following, but I am missing something:
listRows.stream().forEach(auditRow -> {
if(auditRow.actionStr.equals(filter))return true;} else return false;);
but I am getting an error.
match() Various matching operations can be used to check whether a given predicate matches the stream elements. All of these matching operations are terminal and return a boolean result.
Java Boolean equals() method The equals() method of Java Boolean class returns a Boolean value. It returns true if the argument is not null and is a Boolean object that represents the same Boolean value as this object, else it returns false.
valueOf() method is used to return a boolean value either “true” or “false” depending upon the value of the specified boolean object.
The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true" . Example: Boolean. parseBoolean("True") returns true . Example: Boolean.
You may do it like so,
listRows.stream().allMatch(row -> row.nameStr.equals(filter) && row.nameStr.contains(filter));
Update
As per Holgers suggestion, this can be further simplified as this.
listRows.stream().allMatch(row -> row.nameStr.contains(filter));
The use of equals
or contains
may vary depending on your context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With