如何在Java中读取属性文件中的范围值

时间:2023-02-05 14:01:38

I want to read values from Properties file as a range of values. My Task is, calculating result based on points gained. for example,points are,

我想从属性文件中读取值作为一系列值。我的任务是,根据获得的积分计算结果。例如,点是,

<100 : some result.
101 - 110 : Some result.
111 - 120 : Some result.
121 - 130 : some result.
.....
.....
991 - 1000 : some result.
>1000 : some result.

Is any way of storing and getting result from Properties file instead of placing [key,value] pair from 1 to 1000, because i may get float values also? should i have to write if else statements for all possible conditions?

有没有办法从Properties文件中存储和获取结果,而不是将[key,value]对从1放到1000,因为我也可以获得浮点值?我是否应该为所有可能的条件写if else语句?

1 个解决方案

#1


0  

I would use an Array

我会使用一个数组

String[] results = "<100,<100,<100,<100,<100,<100,<100,<100,<100,<100,result101-110,result111-120, etc".split(",");

String result = results[(value-1)/10];

Or you can use a NavigableMap if the ranges vary

或者,如果范围不同,您可以使用NavigableMap

NavigableMap<Double, String> map = ...
String result = map.higherEntry(value).getValue();

In which case the format could be upper-limit result

在这种情况下,格式可以是上限结果

100 some result.
110 Some result.
120 Some result.
130 some result.
.....
.....
1000 Some result.
Infinity some result.

#1


0  

I would use an Array

我会使用一个数组

String[] results = "<100,<100,<100,<100,<100,<100,<100,<100,<100,<100,result101-110,result111-120, etc".split(",");

String result = results[(value-1)/10];

Or you can use a NavigableMap if the ranges vary

或者,如果范围不同,您可以使用NavigableMap

NavigableMap<Double, String> map = ...
String result = map.higherEntry(value).getValue();

In which case the format could be upper-limit result

在这种情况下,格式可以是上限结果

100 some result.
110 Some result.
120 Some result.
130 some result.
.....
.....
1000 Some result.
Infinity some result.