@@ -0,0 +1,2313 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage doublex.lib.locks.lock;%0A%0Aimport doublex.lib.locks.exceptions.KeyMismatchException;%0Aimport doublex.lib.locks.exceptions.MaxKeyMismatchCountReachedException;%0Aimport doublex.lib.locks.exceptions.ResetCountFailException;%0A%0A/**%0A *%0A * @author DoubleX%0A * @param %3CK%3E%0A */%0Apublic final class KissLock%3CK%3E %7B%0A%0A    private boolean mIsLocked = false;%0A    private int mKeyMismatchCount = 0, mMaxKeyMismatchCount;%0A    private K mKey;%0A%0A    public KissLock(final int maxKeyMismatchCount, final K key) %7B%0A        mMaxKeyMismatchCount = maxKeyMismatchCount;%0A        mKey = key;%0A    %7D%0A%0A    public int count() %7B%0A        return mKeyMismatchCount;%0A    %7D%0A%0A    public boolean isLocked() %7B%0A        return mIsLocked;%0A    %7D%0A%0A    public void lock() %7B%0A        mIsLocked = true;%0A    %7D%0A%0A    public synchronized void tryChangeKey(final K oldKey, final K newKey) %0A            throws KeyMismatchException %7B%0A        if (!isLocked()) %7B%0A            if (!mKey.equals(oldKey)) %7B%0A                throw new KeyMismatchException();%0A            %7D%0A            mKey = newKey;%0A        %7D%0A    %7D%0A%0A    public void tryChangeMaxCount(final int maxCount) %0A            throws ResetCountFailException %7B%0A        if (!isLocked()) %7B%0A            if (maxCount %3E count()) %7B%0A                throw new ResetCountFailException(%0A                        new MaxKeyMismatchCountReachedException());%0A            %7D%0A            mMaxKeyMismatchCount = maxCount;%0A        %7D%0A    %7D%0A%0A    public void tryResetCount() %7B%0A        if (!isLocked())  %7B%0A            mKeyMismatchCount = 0;%0A        %7D%0A    %7D%0A%0A    public synchronized void tryUnlock(final K key) throws KeyMismatchException %7B%0A        if (count() %3E= mMaxKeyMismatchCount) %7B%0A            throw new KeyMismatchException(%0A                    new MaxKeyMismatchCountReachedException());%0A        %7D else if (mKey.equals(key)) %7B%0A            mIsLocked = false;%0A        %7D else %7B%0A            mKeyMismatchCount++;%0A            if (count() %3E= mMaxKeyMismatchCount) %7B%0A                throw new KeyMismatchException(%0A                        new MaxKeyMismatchCountReachedException());%0A            %7D%0A            throw new KeyMismatchException();%0A        %7D%0A    %7D%0A%0A%7D%0A

Create KissLock.java