<commit_before>/*
 * 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 final class CountedLock<K> implements ICountable, ILockable<K> {

    private final int mMaxKeyMismatchCount;
    private final ILockable<K> mLock;

    private int mKeyMismatchCount = 0;

    public CountedLock(final int maxKeyMismatchCount, final ILockable<K> lock) {
        mMaxKeyMismatchCount = maxKeyMismatchCount;
        mLock = lock;
    }

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

    @Override
    public final void lock() {
        mLock.lock();
    }

    @Override
    public final void tryUnlock(final K key) {
        if (isMaxKeyMismatchCountReached()) return;
        mLock.tryUnlock(key);
        if (isLocked()) addKeyMismatchCount();
    }

    @Override
    public final void tryResetCount() {
        if (!isLocked()) resetKeyMismatchCount();
    }

    @Override
    public final int count() {
        return mKeyMismatchCount;
    }

    private boolean isMaxKeyMismatchCountReached() {
        return count() >= mMaxKeyMismatchCount;
    }

    private void addKeyMismatchCount() {
        mKeyMismatchCount++;
    }

    private void resetKeyMismatchCount() {
        mKeyMismatchCount = 0;
    }

}
<commit_msg>Update CountedLock.java<commit_after>/*
 * 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 final class CountedLock<K> implements ICountable, ILockable<K> {

    private final ILockable<K> mLock;

    private int mKeyMismatchCount;
    private int mMaxKeyMismatchCount;

    public CountedLock(final int maxKeyMismatchCount, final ILockable<K> lock) {
        resetKeyMismatchCount();
        mMaxKeyMismatchCount = maxKeyMismatchCount;
        mLock = lock;
    }

    @Override
    public boolean isLocked() {
        return mLock.isLocked();
    }

    @Override
    public void lock() {
        mLock.lock();
    }

    @Override
    public void tryUnlock(final K key) {
        if (isReachMaxKeyMismatchCount()) {
            return;
        }
        mLock.tryUnlock(key);
        if (isLocked()) {
            addKeyMismatchCount();
        }
    }

    @Override
    public int count() {
        return mKeyMismatchCount;
    }

    @Override
    public void tryChangeMaxCount(final int maxCount) {
        if (canChangeMaxCount(maxCount)) {
            changeMaxKeyMismatchCount(maxCount);
        }
    }

    @Override
    public void tryResetCount() {
        if (!isLocked()) {
            resetKeyMismatchCount();
        }
    }

    private boolean isReachMaxKeyMismatchCount() {
        return count() >= mMaxKeyMismatchCount;
    }

    private void addKeyMismatchCount() {
        mKeyMismatchCount++;
    }

    private boolean canChangeMaxCount(final int maxCount) {
        return !isLocked() && isExceedCurKeyMismatchCount(maxCount);
    }

    private boolean isExceedCurKeyMismatchCount(final int maxCount) {
        return maxCount > count();
    }

    private void changeMaxKeyMismatchCount(final int maxCount) {
        mMaxKeyMismatchCount = maxCount;
    }

    private void resetKeyMismatchCount() {
        mKeyMismatchCount = 0;
    }

}

{'fraction_non_alphanumeric': 0.0892706279921149, 'fraction_numerical': 0.0008448324415657561, 'mean_word_length': 2.620795107033639, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6785824', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1072, 'n_words': 267}