package com.wrox.algorithms.ssearch;

public class CallCountingCharSequence implements CharSequence {
    /** odnośna sekwencja znaków */
    private final CharSequence _charSequence;

    /** licznik zliczający wywołania metody charAt() */
    private int _callCount;

    public CallCountingCharSequence(CharSequence charSequence) {
        assert charSequence != null : "nie określono sekwencji";
        _charSequence = charSequence;
    }

    public int getCallCount() {
        return _callCount;
    }

    public int length() {
        return _charSequence.length();
    }

    public char charAt(int index) {
        ++_callCount;
        return _charSequence.charAt(index);
    }

    public CharSequence subSequence(int start, int end) {
        return _charSequence.subSequence(start, end);
    }
}
