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

80
LINES

< > BotCompany Repo | #1009413 // MapInConcept

JavaX fragment (include)

1  
sclass MapInConcept<K, V> implements Map<K, V> {
2  
  Map<K, V> m;  // Backing Map
3  
  Concept cc;
4  
5  
  *() {} // for persistence
6  
  *(Map<K, V> *m, Concept *cc) {}
7  
8  
  public int size() {
9  
      synchronized (this) {return m.size();}
10  
  }
11  
  public boolean isEmpty() {
12  
      synchronized (this) {return m.isEmpty();}
13  
  }
14  
  public boolean containsKey(Object key) {
15  
      synchronized (this) {return m.containsKey(key);}
16  
  }
17  
  public boolean containsValue(Object value) {
18  
      synchronized (this) {return m.containsValue(value);}
19  
  }
20  
  public V get(Object key) {
21  
      synchronized (this) {return m.get(key);}
22  
  }
23  
24  
  public V put(K key, V value) {
25  
      try { synchronized (this) {return m.put(key, value);} } finally { cc.change(); }
26  
  }
27  
  public V remove(Object key) {
28  
      try { synchronized (this) {return m.remove(key);} } finally { cc.change(); }
29  
  }
30  
  public void putAll(Map<? extends K, ? extends V> map) {
31  
      synchronized (this) {m.putAll(map);} cc.change();
32  
  }
33  
  public void clear() {
34  
      synchronized (this) {m.clear();} cc.change();
35  
  }
36  
37  
  private transient Set<K> keySet;
38  
  private transient Set<Map.Entry<K,V>> entrySet;
39  
  private transient Collection<V> values;
40  
41  
  public Set<K> keySet() {
42  
      synchronized (this) {
43  
          if (keySet==null)
44  
              keySet = new SynchronizedSet(m.keySet(), this);
45  
          return keySet;
46  
      }
47  
  }
48  
49  
  public Set<Map.Entry<K,V>> entrySet() {
50  
      synchronized (this) {
51  
          if (entrySet==null)
52  
              entrySet = new SynchronizedSet(m.entrySet(), this);
53  
          return entrySet;
54  
      }
55  
  }
56  
57  
  public Collection<V> values() {
58  
      synchronized (this) {
59  
          if (values==null)
60  
              values = new SynchronizedCollection(m.values(), this);
61  
          return values;
62  
      }
63  
  }
64  
65  
  public boolean equals(Object o) {
66  
      if (this == o)
67  
          return true;
68  
      synchronized (this) {return m.equals(o);} // TODO: deadlock?
69  
  }
70  
  public int hashCode() {
71  
      synchronized (this) {return m.hashCode();}
72  
  }
73  
  public String toString() {
74  
      synchronized (this) {return m.toString();}
75  
  }
76  
77  
  // 1.8 stuff omitted
78  
  
79  
  Map<K, V> unwrap() { ret m; }
80  
}

Author comment

Began life as a copy of #1009405

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, imzmzdywqqli, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009413
Snippet name: MapInConcept
Eternal ID of this version: #1009413/7
Text MD5: 2081b6d9c2bf7d567e0457bc611b1265
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-07 18:34:04
Source code size: 2210 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 419 / 2444
Version history: 6 change(s)
Referenced in: [show references]