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

77
LINES

< > BotCompany Repo | #1011343 // NotifyingCollection - also synchronizes

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (9228L) is out of date.

1  
persistable sclass NotifyingCollection<E> extends AbstractCollection<E> implements Collection<E> {
2  
  Collection<E> c;  // Backing Collection
3  
4  
  *() {} // for persistence
5  
  *(Collection<E> *c) {}
6  
7  
  public int size() {
8  
      synchronized (this) {return c.size();}
9  
  }
10  
  public boolean isEmpty() {
11  
      synchronized (this) {return c.isEmpty();}
12  
  }
13  
  public boolean contains(Object o) {
14  
      synchronized (this) {return c.contains(o);}
15  
  }
16  
  public Object[] toArray() {
17  
      synchronized (this) {return c.toArray();}
18  
  }
19  
  public <T> T[] toArray(T[] a) {
20  
      synchronized (this) {return c.toArray(a);}
21  
  }
22  
23  
  public Iterator<E> iterator() {
24  
      return c.iterator(); // caller should not use Iterator.remove()
25  
  }
26  
27  
  public boolean add(E e) {
28  
      synchronized (this) { beforeChange(); if (!c.add(e)) false; } change(); true;
29  
  }
30  
  public boolean remove(Object o) {
31  
      synchronized (this) { beforeChange(); if (!c.remove(o)) false;} change(); true;
32  
  }
33  
34  
  public boolean containsAll(Collection<?> coll) {
35  
      synchronized (this) {return c.containsAll(coll);}
36  
  }
37  
  public boolean addAll(Collection<? extends E> coll) {
38  
      synchronized (this) { beforeChange(); if (!c.addAll(coll)) false;} change(); true;
39  
  }
40  
  public boolean removeAll(Collection<?> coll) {
41  
      synchronized (this) { beforeChange(); if (!c.removeAll(coll)) false;} change(); true;
42  
  }
43  
  public boolean retainAll(Collection<?> coll) {
44  
      synchronized (this) { beforeChange(); if (!c.retainAll(coll)) false;} change(); true;
45  
  }
46  
  public void clear() {
47  
      synchronized (this) { beforeChange(); c.clear();} change();
48  
  }
49  
  public String toString() {
50  
      synchronized (this) {return c.toString();}
51  
  }
52  
  
53  
  /*public void forEach(Consumer<? super E> consumer) {
54  
      synchronized (this) {c.forEach(consumer);}
55  
  }*/
56  
 
57  
  /*public boolean removeIf(Predicate<? super E> filter) {
58  
      synchronized (this) {return c.removeIf(filter);}
59  
  }*/
60  
  @Override
61  
  public Spliterator<E> spliterator() {
62  
      return c.spliterator(); // Must be manually synched by user!
63  
  }
64  
  
65  
  /*public Stream<E> stream() {
66  
      return c.stream(); // Must be manually synched by user!
67  
  }*/
68  
  
69  
  /*public Stream<E> parallelStream() {
70  
      return c.parallelStream(); // Must be manually synched by user!
71  
  }*/
72  
  
73  
  void beforeChange() {}
74  
  void change() {}
75  
  
76  
  Collection<E> unwrap() { ret c; }
77  
}

Author comment

Began life as a copy of #1009405

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1011343
Snippet name: NotifyingCollection - also synchronizes
Eternal ID of this version: #1011343/7
Text MD5: 249cb9bdb7591414caaf150409f86f2c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-10-07 18:15:41
Source code size: 2432 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 520 / 2007
Version history: 6 change(s)
Referenced in: [show references]