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)

persistable sclass SynchronizedNavigableMap<K,V> extends SynchronizedSortedMap<K,V> implements NavigableMap<K,V>
{
    // not final because persistence
    private /*final*/ NavigableMap<K,V> nm;

    SynchronizedNavigableMap(NavigableMap<K,V> m) {
        super(m);
        nm = m;
    }
    SynchronizedNavigableMap(NavigableMap<K,V> m, Object mutex) {
        super(m, mutex);
        nm = m;
    }

    public Entry<K, V> lowerEntry(K key)
                    { synchronized (mutex) { return nm.lowerEntry(key); } }
    public K lowerKey(K key)
                      { synchronized (mutex) { return nm.lowerKey(key); } }
    public Entry<K, V> floorEntry(K key)
                    { synchronized (mutex) { return nm.floorEntry(key); } }
    public K floorKey(K key)
                      { synchronized (mutex) { return nm.floorKey(key); } }
    public Entry<K, V> ceilingEntry(K key)
                  { synchronized (mutex) { return nm.ceilingEntry(key); } }
    public K ceilingKey(K key)
                    { synchronized (mutex) { return nm.ceilingKey(key); } }
    public Entry<K, V> higherEntry(K key)
                   { synchronized (mutex) { return nm.higherEntry(key); } }
    public K higherKey(K key)
                     { synchronized (mutex) { return nm.higherKey(key); } }
    public Entry<K, V> firstEntry()
                       { synchronized (mutex) { return nm.firstEntry(); } }
    public Entry<K, V> lastEntry()
                        { synchronized (mutex) { return nm.lastEntry(); } }
    public Entry<K, V> pollFirstEntry()
                   { synchronized (mutex) { return nm.pollFirstEntry(); } }
    public Entry<K, V> pollLastEntry()
                    { synchronized (mutex) { return nm.pollLastEntry(); } }

    public NavigableMap<K, V> descendingMap() {
        synchronized (mutex) {
            return
                new SynchronizedNavigableMap<>(nm.descendingMap(), mutex);
        }
    }

    public NavigableSet<K> keySet() {
        return navigableKeySet();
    }

    public NavigableSet<K> navigableKeySet() {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex);
        }
    }

    public NavigableSet<K> descendingKeySet() {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex);
        }
    }


    public SortedMap<K,V> subMap(K fromKey, K toKey) {
        synchronized (mutex) {
            return new SynchronizedNavigableMap<>(
                nm.subMap(fromKey, true, toKey, false), mutex);
        }
    }
    public SortedMap<K,V> headMap(K toKey) {
        synchronized (mutex) {
            return new SynchronizedNavigableMap<>(nm.headMap(toKey, false), mutex);
        }
    }
    public SortedMap<K,V> tailMap(K fromKey) {
        synchronized (mutex) {
    return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex);
        }
    }

    public NavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableMap<>(
                nm.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex);
        }
    }

    public NavigableMap<K, V> headMap(K toKey, boolean inclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableMap<>(
                    nm.headMap(toKey, inclusive), mutex);
        }
    }

    public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableMap<>(
                nm.tailMap(fromKey, inclusive), mutex);
        }
    }
}

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: 62 / 82
Referenced in: [show references]