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

44
LINES

< > BotCompany Repo | #1034595 // SynchronizedSortedMap (backup with extra field)

JavaX fragment (include)

persistable sclass SynchronizedSortedMap<K,V>
    extends SynchronizedMap<K,V>
    implements SortedMap<K,V>
{
    // not final because persistence
    private /*final*/ SortedMap<K,V> sm;

    SynchronizedSortedMap(SortedMap<K,V> m) {
        super(m);
        sm = m;
    }
    SynchronizedSortedMap(SortedMap<K,V> m, Object mutex) {
        super(m, mutex);
        sm = m;
    }

    public Comparator<? super K> comparator() {
        synchronized (mutex) {return sm.comparator();}
    }

    public SortedMap<K,V> subMap(K fromKey, K toKey) {
        synchronized (mutex) {
            return new SynchronizedSortedMap<>(
                sm.subMap(fromKey, toKey), mutex);
        }
    }
    public SortedMap<K,V> headMap(K toKey) {
        synchronized (mutex) {
            return new SynchronizedSortedMap<>(sm.headMap(toKey), mutex);
        }
    }
    public SortedMap<K,V> tailMap(K fromKey) {
        synchronized (mutex) {
           return new SynchronizedSortedMap<>(sm.tailMap(fromKey),mutex);
        }
    }

    public K firstKey() {
        synchronized (mutex) {return sm.firstKey();}
    }
    public K lastKey() {
        synchronized (mutex) {return sm.lastKey();}
    }
}

Author comment

Began life as a copy of #1031164

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1034595
Snippet name: SynchronizedSortedMap (backup with extra field)
Eternal ID of this version: #1034595/1
Text MD5: 01cf7a47b7af5570f8e1d52c6e306046
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:19:59
Source code size: 1244 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 147 / 147
Referenced in: