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

101
LINES

< > BotCompany Repo | #1034596 // SynchronizedNavigableMap (backup with extra field)

JavaX fragment (include)

1  
persistable sclass SynchronizedNavigableMap<K,V> extends SynchronizedSortedMap<K,V> implements NavigableMap<K,V>
2  
{
3  
    // not final because persistence
4  
    private /*final*/ NavigableMap<K,V> nm;
5  
6  
    SynchronizedNavigableMap(NavigableMap<K,V> m) {
7  
        super(m);
8  
        nm = m;
9  
    }
10  
    SynchronizedNavigableMap(NavigableMap<K,V> m, Object mutex) {
11  
        super(m, mutex);
12  
        nm = m;
13  
    }
14  
15  
    public Entry<K, V> lowerEntry(K key)
16  
                    { synchronized (mutex) { return nm.lowerEntry(key); } }
17  
    public K lowerKey(K key)
18  
                      { synchronized (mutex) { return nm.lowerKey(key); } }
19  
    public Entry<K, V> floorEntry(K key)
20  
                    { synchronized (mutex) { return nm.floorEntry(key); } }
21  
    public K floorKey(K key)
22  
                      { synchronized (mutex) { return nm.floorKey(key); } }
23  
    public Entry<K, V> ceilingEntry(K key)
24  
                  { synchronized (mutex) { return nm.ceilingEntry(key); } }
25  
    public K ceilingKey(K key)
26  
                    { synchronized (mutex) { return nm.ceilingKey(key); } }
27  
    public Entry<K, V> higherEntry(K key)
28  
                   { synchronized (mutex) { return nm.higherEntry(key); } }
29  
    public K higherKey(K key)
30  
                     { synchronized (mutex) { return nm.higherKey(key); } }
31  
    public Entry<K, V> firstEntry()
32  
                       { synchronized (mutex) { return nm.firstEntry(); } }
33  
    public Entry<K, V> lastEntry()
34  
                        { synchronized (mutex) { return nm.lastEntry(); } }
35  
    public Entry<K, V> pollFirstEntry()
36  
                   { synchronized (mutex) { return nm.pollFirstEntry(); } }
37  
    public Entry<K, V> pollLastEntry()
38  
                    { synchronized (mutex) { return nm.pollLastEntry(); } }
39  
40  
    public NavigableMap<K, V> descendingMap() {
41  
        synchronized (mutex) {
42  
            return
43  
                new SynchronizedNavigableMap<>(nm.descendingMap(), mutex);
44  
        }
45  
    }
46  
47  
    public NavigableSet<K> keySet() {
48  
        return navigableKeySet();
49  
    }
50  
51  
    public NavigableSet<K> navigableKeySet() {
52  
        synchronized (mutex) {
53  
            return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex);
54  
        }
55  
    }
56  
57  
    public NavigableSet<K> descendingKeySet() {
58  
        synchronized (mutex) {
59  
            return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex);
60  
        }
61  
    }
62  
63  
64  
    public SortedMap<K,V> subMap(K fromKey, K toKey) {
65  
        synchronized (mutex) {
66  
            return new SynchronizedNavigableMap<>(
67  
                nm.subMap(fromKey, true, toKey, false), mutex);
68  
        }
69  
    }
70  
    public SortedMap<K,V> headMap(K toKey) {
71  
        synchronized (mutex) {
72  
            return new SynchronizedNavigableMap<>(nm.headMap(toKey, false), mutex);
73  
        }
74  
    }
75  
    public SortedMap<K,V> tailMap(K fromKey) {
76  
        synchronized (mutex) {
77  
    return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex);
78  
        }
79  
    }
80  
81  
    public NavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) {
82  
        synchronized (mutex) {
83  
            return new SynchronizedNavigableMap<>(
84  
                nm.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex);
85  
        }
86  
    }
87  
88  
    public NavigableMap<K, V> headMap(K toKey, boolean inclusive) {
89  
        synchronized (mutex) {
90  
            return new SynchronizedNavigableMap<>(
91  
                    nm.headMap(toKey, inclusive), mutex);
92  
        }
93  
    }
94  
95  
    public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
96  
        synchronized (mutex) {
97  
            return new SynchronizedNavigableMap<>(
98  
                nm.tailMap(fromKey, inclusive), mutex);
99  
        }
100  
    }
101  
}

Author comment

Began life as a copy of #1031163

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034596
Snippet name: SynchronizedNavigableMap (backup with extra field)
Eternal ID of this version: #1034596/1
Text MD5: 9f4c02a3ddb22c65d01046daec77148a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-19 08:21:39
Source code size: 3771 bytes / 101 lines
Pitched / IR pitched: No / No
Views / Downloads: 70 / 91
Referenced in: [show references]