/*
 * 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;

/**
 *
 * @author DoubleX
 * @param <K>
 */
public abstract class AbstractLock<K> implements ILockable<K> {

    private boolean mIsLocked = false;

    @Override
    public final boolean isLocked() {
        return mIsLocked;
    }

    @Override
    public final void lock() {
        mIsLocked = true;
    }

    @Override
    public final void tryUnlock(final K key) {
        if (isCorrectKey(key)) {
            unlock();
        }
    }

    abstract boolean isCorrectKey(final K key);

    private void unlock() {
        mIsLocked = false;
    }

};

@@ -203,16 +203,116 @@
 ib.locks
+.lock;%0A%0Aimport doublex.lib.locks.ILockable;%0Aimport doublex.lib.locks.exceptions.KeyMismatchException
 ;%0A%0A/**%0A 
@@ -676,16 +676,44 @@
 l K key)
+ throws KeyMismatchException
  %7B%0A     
@@ -762,16 +762,79 @@
 lock();%0A
+        %7D else %7B%0A            throw new KeyMismatchException();%0A
         

Update AbstractLock.java