/[projects]/dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/util/NearestShortTreeMap.java
ViewVC logotype

Annotation of /dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/util/NearestShortTreeMap.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2785 - (hide annotations) (download)
Thu Nov 26 14:25:41 2015 UTC (8 years, 6 months ago) by torben
File size: 607 byte(s)
Implementér anvend-nærmeste-husnr
1 torben 2785 package dk.daoas.daoadresseservice.util;
2    
3     import java.util.TreeMap;
4    
5     public class NearestShortTreeMap {
6    
7    
8     public static <T> short getNearestKey(short search, TreeMap<Short,T> map) {
9    
10     Short ceilKey = map.ceilingKey(search);
11     Short lowerKey = map.lowerKey(search);
12    
13     if (ceilKey == null) {
14     return lowerKey;
15     }
16    
17     if (lowerKey == null) {
18     return ceilKey;
19     }
20    
21    
22     int ceilDiff = Math.abs( ceilKey - search );
23     int lowerDiff = Math.abs( lowerKey - search );
24    
25     if (ceilDiff < lowerDiff) {
26     return ceilKey;
27     } else {
28     return lowerKey;
29     }
30    
31     }
32    
33     }

  ViewVC Help
Powered by ViewVC 1.1.20