@@ -0,0 +1,1447 @@
+/*%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;%0A%0A/**%0A *%0A * @author kenneth.lau%0A * @param %3CK%3E%0A */%0Apublic final class CountedLock%3CK%3E implements ICountable, ILockable%3CK%3E %7B%0A%0A    private final int mMaxKeyMismatchCount;%0A    private final ILockable%3CK%3E mLock;%0A%0A    private int mKeyMismatchCount = 0;%0A%0A    public CountedLock(final int maxKeyMismatchCount, final ILockable%3CK%3E lock) %7B%0A        mMaxKeyMismatchCount = maxKeyMismatchCount;%0A        mLock = lock;%0A    %7D%0A%0A    @Override%0A    public final boolean isLocked() %7B%0A        return mLock.isLocked();%0A    %7D%0A%0A    @Override%0A    public final void lock() %7B%0A        mLock.lock();%0A    %7D%0A%0A    @Override%0A    public final void tryUnlock(final K key) %7B%0A        if (isMaxKeyMismatchCountReached()) return;%0A        mLock.tryUnlock(key);%0A        if (isLocked()) addKeyMismatchCount();%0A    %7D%0A%0A    @Override%0A    public final void tryResetCount() %7B%0A        if (!isLocked()) resetKeyMismatchCount();%0A    %7D%0A%0A    @Override%0A    public final int count() %7B%0A        return mKeyMismatchCount;%0A    %7D%0A%0A    private boolean isMaxKeyMismatchCountReached() %7B%0A        return count() %3E= mMaxKeyMismatchCount;%0A    %7D%0A%0A    private void addKeyMismatchCount() %7B%0A        mKeyMismatchCount++;%0A    %7D%0A%0A    private void resetKeyMismatchCount() %7B%0A        mKeyMismatchCount = 0;%0A    %7D%0A%0A%7D%0A

Create CountedLock.java