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

21
LINES

< > BotCompany Repo | #1018030 // class DerivedSet - base set + additions

JavaX fragment (include)

1  
static class DerivedSet<A> extends AbstractSet<A> {
2  
  Set<A> base;
3  
  Set<A> additions = new HashSet;
4  
  
5  
  *() {}
6  
  *(Set<A> *base) {}
7  
  *(Set<A> *base, Set<A> *additions) {}
8  
  
9  
  public int size() { ret base.size()+additions.size(); }
10  
  public Iterator<A> iterator() { fail(); }
11  
  public bool contains(O o) { ret base.contains(o) || additions.contains(o); }
12  
  
13  
  public bool add(A a) {
14  
    ret !base.contains(a) && additions.add(a);
15  
  }
16  
  
17  
  // does not remove from base set, only from additions
18  
  public bool remove(O o) { ret additions.remove(o); }
19  
  
20  
  O mutex() { ret collectionMutex(additions); }
21  
}

Author comment

Began life as a copy of #1017455

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018030
Snippet name: class DerivedSet - base set + additions
Eternal ID of this version: #1018030/1
Text MD5: ffc89bfbc9eff27dd14960a78340e907
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-26 17:20:19
Source code size: 625 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 369 / 907
Referenced in: [show references]