Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1008728 // Test IP to country [old database]

JavaX source code [tags: archive use-pretranspiled] - run with: x30.jar

Uses 51K of libraries. Click here for Pure Java version (3971L/27K/87K).

1  
!7
2  
3  
sclass Item {
4  
  long end;
5  
  S country;
6  
}
7  
8  
static new TreeMap<Long, Item> data;
9  
10  
p {
11  
  for (S s : lines(readerToString(utf8bufferedReader(lzmaInputStream(#1004343))))) {
12  
    L<S> l = tok_splitAtComma_unquote(s);
13  
    if (l(l) < 3) continue;
14  
    long start = parseLong(first(l));
15  
    long end = parseLong(second(l));
16  
    S country = intern(l.get(4));
17  
    data.put(start, nuWithValues(Item, +end, +country));
18  
  }
19  
  print(l(data) + " " + first(keys(data)));
20  
  botSleep();
21  
}
22  
23  
answer {
24  
  long ip = ipToInt(trim(s));
25  
  print("s=" + s + ", ip=" + ip);
26  
  Long key = data.floorKey(ip);
27  
  if (key != null) {
28  
    Item i = data.get(key);
29  
    if (i != null) ret i.country;
30  
  }
31  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): cfunsshuasjs, mqqgnosmbjvj, nbgitpuheiab, tvejysmllsmz

No comments. add comment

Snippet ID: #1008728
Snippet name: Test IP to country [old database]
Eternal ID of this version: #1008728/14
Text MD5: c2274bdf7da1194ed8469bb86176ab0e
Transpilation MD5: b69a00e738276245bfaf787b714a16df
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2017-05-31 17:32:08
Source code size: 697 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 450 / 566
Version history: 13 change(s)
Referenced in: [show references]