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

69
LINES

< > BotCompany Repo | #1031165 // SynchronizedNavigableSet

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

Libraryless. Click here for Pure Java version (3023L/17K).

persistable static class SynchronizedNavigableSet<E>
    extends SynchronizedSortedSet<E>
    implements NavigableSet<E>
{
    @java.io.Serial
    private static final long serialVersionUID = -5505529816273629798L;

    @SuppressWarnings("serial") // Conditionally serializable
    /*private final*/ NavigableSet<E> ns;

    SynchronizedNavigableSet(NavigableSet<E> s) {
        super(s);
        ns = s;
    }

    SynchronizedNavigableSet(NavigableSet<E> s, Object mutex) {
        super(s, mutex);
        ns = s;
    }
    public E lower(E e)      { synchronized (mutex) {return ns.lower(e);} }
    public E floor(E e)      { synchronized (mutex) {return ns.floor(e);} }
    public E ceiling(E e)  { synchronized (mutex) {return ns.ceiling(e);} }
    public E higher(E e)    { synchronized (mutex) {return ns.higher(e);} }
    public E pollFirst()  { synchronized (mutex) {return ns.pollFirst();} }
    public E pollLast()    { synchronized (mutex) {return ns.pollLast();} }

    public NavigableSet<E> descendingSet() {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.descendingSet(), mutex);
        }
    }

    public Iterator<E> descendingIterator()
             { synchronized (mutex) { return descendingSet().iterator(); } }

    public NavigableSet<E> subSet(E fromElement, E toElement) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.subSet(fromElement, true, toElement, false), mutex);
        }
    }
    public NavigableSet<E> headSet(E toElement) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.headSet(toElement, false), mutex);
        }
    }
    public NavigableSet<E> tailSet(E fromElement) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.tailSet(fromElement, true), mutex);
        }
    }

    public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex);
        }
    }

    public NavigableSet<E> headSet(E toElement, boolean inclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.headSet(toElement, inclusive), mutex);
        }
    }

    public NavigableSet<E> tailSet(E fromElement, boolean inclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.tailSet(fromElement, inclusive), mutex);
        }
    }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031165
Snippet name: SynchronizedNavigableSet
Eternal ID of this version: #1031165/2
Text MD5: a6c017f908f5de58466e9d645533d71e
Transpilation MD5: e792316baf5ced9b04520eeecd9b0163
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-16 17:49:17
Source code size: 2633 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 127 / 438
Version history: 1 change(s)
Referenced in: [show references]