Reputation: 353
I have Long value to be looked upon in Lookup values and return the corresponds value. For the sake of not getting any value related errors I have set up all values to Long type.
Here is my code
package RestClient;
public class Range {
public static Long upper;
public static Long value;
public Range(Long i, Long j) {
Range.upper = i;
Range.value = j;
}
}
package RestClient;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class Rangelookup {
public static String Lookup(Long key) {
NavigableMap<Long, Range> map = new TreeMap<Long, Range>();
map.put(5045076263000000000L, new Range(5045076263249899999L, 507866L));
map.put(5045076263249900000L, new Range(5045076263249999999L, 507866L));
map.put(5045076263250000000L, new Range(5045076263499899999L, 507868L));
map.put(5045076263499900000L, new Range(5045076263499999999L, 507868L));
map.put(5045076263500000000L, new Range(5045076263749899999L, 507867L));
map.put(5045076263749900000L, new Range(5045076263749999999L, 507867L));
map.put(5045076263750000000L, new Range(5045076263999899999L, 507869L));
map.put(5045076263999900000L, new Range(5045076263999999999L, 507869L));
map.put(5045075892250000000L, new Range(5045075892499899999L, 507867L));
map.put(5045075892499900000L, new Range(5045075892499999999L, 507867L));
map.put(5045075892000000000L, new Range(5045075892249899999L, 507869L));
map.put(5045075892249900000L, new Range(5045075892249999999L, 507869L));
String output = "";
Map.Entry<Long, Range> entry = map.floorEntry(key);
if (entry == null) {
output = "No Entry Found";
} else if (key <= entry.getValue().upper) {
output = entry.getValue().value.toString();
} else {
output = "No Entry Found";
}
System.out.println(output);
return output;
}
public static void main(String[] args) {
Lookup(5045076263249899985L);
}
}
May I know please why its not returning any value ? Why its going to "no Entry found" case ?
May I Know please what am doing wrong ?
Upvotes: 0
Views: 23
Reputation: 43689
The entry that is found is this one:
map.put(5045076263000000000L, new Range(5045076263249899999L, 507866L));
But the upper value 5045075892249999999
is less than the lookup key 5045076263249899985
:
5045075892249999999
<
5045076263249899985
Therefore you get "No Entry Found"
.
Upvotes: 1