Are there any libraries for parsing "number expressions" like 1,2-9,33- in Java

Posted by mihi on Stack Overflow See other posts from Stack Overflow or by mihi
Published on 2010-05-25T17:53:55Z Indexed on 2010/05/25 18:01 UTC
Read the original article Hit count: 232

Filed under:
|
|
|
|

Hi,

I don't think it is hard, just tedious to write: Some small free (as in beer) library where I can put in a String like 1,2-9,33- and it can tell me whether a given number matches that expression. Just like most programs have in their print range dialogs. Special functions for matching odd or even numbers only, or matching every number that is 2 mod 5 (or something like that) would be nice, but not needed.

The only operation I have to perform on this list is whether the range contains a given (nonnegative) integer value; more operations like max/min value (if they exist) or an iterator would be nice, of course.

What would be needed that it does not occupy lots of RAM if anyone enters 1-10000000 but the only number I will ever query is 12345 :-)

(To implement it, I would parse a list into several (min/max/value/mod) pairs, like 1,10,0,1 for 1-10 or 11,33,1,2 for 1-33odd, or 12,62,2,10 for 12-62/10 (i. e. 12, 22, 32, ..., 62) and then check each number for all the intervals. Open intervals by using Integer.MaxValue etc. If there are no libs, any ideas to do it better/more efficient?)

© Stack Overflow or respective owner

Related posts about java

Related posts about parse