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

30
LINES

< > BotCompany Repo | #1010611 // objectID - assign a unique long value to each queried object

JavaX fragment (include)

1  
static long objectID(O o) {
2  
  if (o == null) ret 0;
3  
  Map generalMap = vm_generalMap();
4  
  if (generalMap == null) fail("Please upgrade JavaX");
5  
  synchronized(generalMap) {
6  
    Map map = cast generalMap.get("objectIDs");
7  
    if (map == null) {
8  
      pcall-short {
9  
        map = (Map) nuForeignObject(javax(), className(javax()) + '$WeakIdentityHashMap);
10  
      }
11  
      if (map == null) map = new WeakIdentityHashMap; // older JavaX
12  
      generalMap.put("objectIDs", map);
13  
    }
14  
    Long l = cast map.get(o);
15  
    if (l == null) {
16  
      l = toLong(generalMap.get("lastObjectID"))+1;
17  
      generalMap.put("lastObjectID", l);
18  
      map.put(o, l);
19  
    }
20  
    ret l;
21  
  }
22  
}
23  
24  
static Collection<Long> objectID_liveIDs() {
25  
  Map generalMap = cast getOpt(javax(), 'generalMap);
26  
  if (generalMap == null) ret new L;
27  
  synchronized(generalMap) {
28  
    ret cloneList(values((Map<O, Long>) generalMap.get("objectIDs")));
29  
  }
30  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1010611
Snippet name: objectID - assign a unique long value to each queried object
Eternal ID of this version: #1010611/13
Text MD5: 64f68f431764fd8ac9bc11cd26860dd8
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-23 05:20:10
Source code size: 936 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 501 / 554
Version history: 12 change(s)
Referenced in: [show references]