/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package doublex.lib.locks;

import java.util.AbstractMap;
import java.util.LinkedHashMap;

/**
 *
 * @author DoubleX
 * @param <K>
 */
public final class Locks<K> {

    private final ILockable<K> NULL_LOCK = new NullLock<>();

    private final AbstractMap<String, ILockable<K>> mLocks = 
            new LinkedHashMap<>();

    public final ILockable<K> lock(final String key) {
        return mLocks.containsKey(key) ? mLocks.get(key) : NULL_LOCK;
    }

    public final boolean isLocked() {
        return mLocks.values().stream().anyMatch((lock) -> (lock.isLocked()));
    }

    public final void tryPutLock(final String key, final ILockable<K> lock) {
        if (canPutLock(key, lock)) putLock(key, lock);
    }

    public final ILockable<K> triedTakenLock(final String key) {
        return (canTakeLock(key)) ? takenLock(key) : NULL_LOCK;
    }

    private boolean canPutLock(final String key, final ILockable<K> lock) {
        return !mLocks.containsKey(key) && !lock.isLocked();
    }

    private void putLock(final String key, final ILockable<K> lock) {
        mLocks.put(key, lock);
    }

    private boolean canTakeLock(final String key) {
        return mLocks.containsKey(key) && !mLocks.get(key).isLocked();
    }

    private ILockable<K> takenLock(final String key) {
        final ILockable<K> lock = mLocks.get(key);
        mLocks.remove(key);
        return lock;
    }

}

@@ -340,19 +340,40 @@
 Locks%3CK%3E
+ implements ILocks%3CK%3E
  %7B%0A
-
 %0A    pri
@@ -521,24 +521,38 @@
 shMap%3C%3E();%0A%0A
+    @Override%0A
     public f
@@ -663,32 +663,46 @@
 LL_LOCK;%0A    %7D%0A%0A
+    @Override%0A
     public final
@@ -801,32 +801,46 @@
 ked()));%0A    %7D%0A%0A
+    @Override%0A
     public final
@@ -959,24 +959,38 @@
 ck);%0A    %7D%0A%0A
+    @Override%0A
     public f
@@ -1584,26 +1584,20 @@
  lock = 
-mL
+l
 ock
-s.get
 (key);%0A 

Update Locks.java