This is a question about best practices / design patterns than regular expressions.
In short, I have 3 values: from, to and the value I want to change. From must match one of several patterns:
XX.X >XX.X >=XX.X <XX.X <=XX.X XX.X-XX.X
While To should be a decimal number. Depending on what value is set in From, I have to check if the value I want to change satisfies the From condition. For example, user inputs "From:> 100.00 To: 150.00" means that every value greater than 100.00 must be changed.
Regular expression itself is not a problem. The fact is that if I match the From integer with one regular expression and it passes, I still need to check which parameter was entered - this will lead to generating at least 5 IF in my code, and every time I want to add another option, I will need to add another IF - not cool. Same thing if I created 5 patterns.
Now I have a HashMap that contains a template as a key and ValueMatcher as a value. When a user enters a From value, I loop it against each key on this map, and if it matches, then I use the corresponding ValueMatcher to check if the value I want to change really matches the From value.
This approach, on the other hand, requires that I have a HashMap with all the features, a ValueMatcher interface and 5 implementations, each of which has only 1 short βmatchβ method. I think this is better than IF, but still looks like an exaggerated solution.
Is there any other way to do this? Or is it how I really should do it? I really regret that we cannot store methods in HashMap / pass them as arguments, because then I will only have 1 class with all the appropriate methods and save them in HashMap.