<commit_before>package com.scalien.scaliendb;

public class Index
{
    private Client client;
    private long databaseID;
    private long tableID;
    private String stringKey;
    private byte[] byteKey;

    private long count = 1000;
    private long index = 0;
    private long num = 0;

    public Index(Client client, long databaseID, long tableID, String key) {
        this.client = client;
        this.databaseID = databaseID;
        this.tableID = tableID;
        this.stringKey = key;
    }

    public Index(Client client, long databaseID, long tableID, byte[] key) {
        this.client = client;
        this.databaseID = databaseID;
        this.tableID = tableID;
        this.byteKey = key;
    }

    public long Get()  throws SDBPException {
        if (num == 0)
            AllocateIndexRange();
        
        num--;
        return index++;
    }

    private void AllocateIndexRange() throws SDBPException {
        long oldDatabaseID = client.getDatabaseID();
        long oldTableID = client.getTableID();

        if (oldDatabaseID != databaseID)
            client.useDatabase(databaseID);
        if (oldTableID != tableID)
            client.useTable(tableID);

        if (stringKey != null)
            index = client.add(stringKey, count) - count;
        else
            index = client.add(byteKey, count) - count;
        num = count;

        if (oldDatabaseID != databaseID)
            client.useDatabase(oldDatabaseID);<commit_msg>Added setGranularity to Java Index class. Added reset() to Java Index class. Added docstrings to Java Index class.<commit_after>package com.scalien.scaliendb;

public class Index
{
    private Client client;
    private long databaseID;
    private long tableID;
    private String stringKey;
    private byte[] byteKey;

    private long count = 1000;
    private long index = 0;
    private long num = 0;

    public Index(Client client, long databaseID, long tableID, String key) {
        this.client = client;
        this.databaseID = databaseID;
        this.tableID = tableID;
        this.stringKey = key;
    }

    public Index(Client client, long databaseID, long tableID, byte[] key) {
        this.client = client;
        this.databaseID = databaseID;
        this.tableID = tableID;
        this.byteKey = key;
    }
    
    /**
     * Sets the granularity for this index proxy.
     *
     * @param   ps          granularity, default 1000
     */
    public void setGranularity(long count)
    {
        this.count = count;
    }

    /**
     * Retrieves the next unique index value.
     *
     * @return              the next unique index value
     */
    public long get()  throws SDBPException {
        if (num == 0)
            AllocateIndexRange();
        
        num--;
        return index++;
    }

    /**
     * Resets the index to 0 (on the server).
     * WARNING: use with care, the index will no longer be unique!
     *
     */
    public void reset()  throws SDBPException {
        long oldDatabaseID = client.getDatabaseID();
        long oldTableID = client.getTableID();

        if (oldDatabaseID != databaseID)
            client.useDatabase(databaseID);
        if (oldTableID != tableID)
            client.useTable(tableID);

        if (stringKey != null)
            client.set(stringKey, "0");
        else
            client.set(byteKey, "0".getBytes());
        num = 0;

        if (oldDatabaseID != databaseID)
            client.useDatabase(oldDatabaseID);
        if (oldTableID != tableID)
            client.useTable(oldTableID);
    }

    private void AllocateIndexRange() throws SDBPException {
        long oldDatabaseID = client.getDatabaseID();
        long oldTableID = client.getTableID();

        if (oldDatabaseID != databaseID)
            client.useDatabase(databaseID);
        if (oldTableID != tableID)
            client.useTable(tableID);

        if (stringKey != null)
            index = client.add(stringKey, count) - count;
        else
            index = client.add(byteKey, count) - count;
        num = count;

        if (oldDatabaseID != databaseID)
            client.useDatabase(oldDatabaseID);
{'fraction_non_alphanumeric': 0.09224117223156378, 'fraction_numerical': 0.005284650492433342, 'mean_word_length': 2.0394160583941607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3854599', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1136, 'n_words': 332}