For example,
greater or equal to 50 and smaller than 100 (>=50 && < 100)
smaller than 10 or greater than 40 (<10 || >40)
I have been thinking about how to represent mathematical range in a file and database, the range may be input by non programmer and I need to keep the input simple, but at another side, it also need to keep the input easy to convert to data and easy to check error input e.g.: <10 || >100
seems the most simple but it is harder for me to parse the string to get the data, also need to consider input format error
I have been considering some input methods, using >=50 && < 100 as example, which is in key value form:
Using one string to represent whole range:
<rangeInString>=50 && < 100</rangeInString>
Separate two strings, one represent lower bound and another one represent upper bound, then parse each string in program:
<lowerBound> >=50 </lowerBound> <upperBound> <100 </upperBound>
Separate lower and upper bound, also separate the sign from number:
<lowerBound> <sign> >= </sign> <data>50</data> </lowerBound> <upperBound> <sign> < </sign> <data>100</data> </upperBound>
Separate lower bound and upper bound,also separate sign, and also separate the case that if includes the equal condition:
<lowerBound> <sign> > </sign> <isIncludeEqual>true</isIncludeEqual> <data>50</data> </lowerBound> <upperBound> <sign> < </sign> <isIncludeEqual>false</isIncludeEqual> <data>100</data> </upperBound>
auto detect using
&&
or||
, e.g. :>= A with < B,if A < B, must be&&
e.g. (>= 50 && <100
), otherwise it is||
e.g. (>= 100 || <50
):<A> <sign> > </sign> <isIncludeEqual>true</isIncludeEqual> <data>50</data> </A> <B> <sign> < </sign> <isIncludeEqual>false</isIncludeEqual> <data>100</data> </B>
Use a field "isAnd" to separate >=50 && < 100 (true) and <=50 || > 100 (false) instead of using field sign "<" and ">" :
<lowerBound> <isIncludeEqual>true</isIncludeEqual> <data>50</data> </lowerBound> <upperBound> <isIncludeEqual>false</isIncludeEqual> <data>100</data> </upperBound> <isAnd>true</isAnd>
other data model...
I need to consider somethings:
easy for non programmer to input
easy to convert or parse to data into program
easy to check error, for example,parse string increase the complexity of converting data and checking incorrect format, also there may have other incorrect format,e.g.:
<=50 && >100
should not be valid, I may allow auto detect using&&
or||
by the sign of input, but it may increase the complexity of the code