简体   繁体   中英

Map range (min-max) to a single value and if a value is in a range return the value mapped in java

I need to map different interval to different single value.
The interval is type long and formed by min and max. The value is a short. The intervals are not overlapped, but can be consecutive. I would like to look up if a value is contained in one interval and in positive case returning the value mapped to this interval. Otherwise return null.

For example:

Range => Value  
100-200 => 5  
500-800 => 50  
201-300 => 50

If I lookup for 150, I need to have 5 as result, for 554 50 and instead for 305 null.

如果第三方库是公平的游戏,那么这完全是Guava的TreeRangeMap所做的100%。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM