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

18
LINES

< > BotCompany Repo | #1012178 // concurrentlyIterateList - wants a RandomAccessList

JavaX fragment (include)

1  
// iterate safely (& quickly) in the face of concurrent modifications
2  
static <A> IterableIterator<A> concurrentlyIterateList(final L<A> l) {
3  
  ret iteratorFromFunction_withEndMarker_f0(new F0<A>() {
4  
    int i;
5  
6  
    A get() {
7  
      int _i = i++;
8  
      synchronized(l) {
9  
        if (_i < l(l)) {
10  
          A a = l.get(_i);
11  
          if (a == iteratorFromFunction_endMarker) fail("no"); // ugly comparison fail-fast redemption
12  
          ret a;
13  
        }
14  
        ret (A) iteratorFromFunction_endMarker; // ugly cast
15  
      }
16  
    }
17  
  });
18  
}

Author comment

Began life as a copy of #1012173

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012178
Snippet name: concurrentlyIterateList - wants a RandomAccessList
Eternal ID of this version: #1012178/8
Text MD5: e895be85f5c85485dfd280f84badf55b
Author: stefan
Category: javax / collections
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-11 13:20:21
Source code size: 550 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 387 / 434
Version history: 7 change(s)
Referenced in: [show references]