I want to create a large range map that will map the keys accoriding their numbers to buckets , for instance :
NavigableMap<String, String> map = new TreeMap<>();
map.put("var2#" + 0L, "out0"); // "var2#0..100 => out0
map.put("var2#" + 100L, "out1"); // "var2#100..200" => out1
map.put("var2#" + 200L, "out2"); // "var2#200..300" => out2
map.put("var2#" + 300L, "out3"); // "var2#300..+" => out3
That means if a new key will arrive with value res should be "var2#150" ==> "out1"
What I tried to do , is to use sorted map , everything is working with range of the numbers inside the map
something like :
String out1 = map.floorEntry("var2#" + 150L).getValue(); //out1 , works!
, but if send var2#2000 , instead to get res "out3" , I got "out2" , and so on...
String res = map.floorEntry("var2#" + 2000L).getValue();
Syso(res) ==> out2 , BUT I expected result => "out3"
// because it is bigger that the range.
P.S:
It is very large map with prefix of some "string" and comes after typed
long number . Eg. "var1#100, var1#200 , ...bla1#1000 , bla5#2000....
Another issue - when I have same long value on different keys I expect to do 1st match on the string and then on the number ...
map.put("var1#" + 200L, "out0");
map.put("var2#" + 200L, "out1");
map.put("var3#" + 200L, "out2");
map.put("var4#" + 200L, "out3");
String out1 = map.floorEntry("var2#" + 150L).getValue();
System.out.println("====> " + out1); //expected out1 , because only match of "var2
String out3 = map.floorEntry("var2#" + 250L).getValue(); //expected out1 , because only match of "var2
System.out.println("====> " + out3);" ....
Any suggestions please , maybe some algorithm ?