I have a UI where the user can build a query to then apply those conditions to search in a text file.
Let's assume the string is as follows: A and (B or C)
I also have access to each value (A, B, C)
, logical operators (and, or)
and grouping brackets.
So what I need to have is: line.contains(A) && (line.contains(B) || line.contains(C))
boolean found = false;
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while ((line = reader.readLine()) != null && !contains) {
if (line.contains(A) && (line.contains(B) || line.contains(C))) {
found = true;
}
}
return found;
The above specific conditions might also not work since I'm searching for that in each line and the conditions might be in different lines. But this is another issue I have to deal with :)
Any idea on how to do this?