<commit_before>package hdm.pk070.jscheme.table;

import hdm.pk070.jscheme.obj.SchemeObject;

/**
 * Created by patrick on 16.05.16.
 */
public abstract class FixedSizeTable<KEY, VALUE extends SchemeObject> extends BaseTable<KEY, VALUE> {

}<commit_msg>Implemented table with fixed size<commit_after>package hdm.pk070.jscheme.table;

import hdm.pk070.jscheme.error.SchemeError;
import hdm.pk070.jscheme.table.environment.entry.EnvironmentEntry;

import java.util.Objects;
import java.util.Optional;

/**
 * Created by patrick on 16.05.16.
 */
public abstract class FixedSizeTable<KEY, VALUE> extends BaseTable<KEY, VALUE> {

    private Object[] entries;

    protected FixedSizeTable(int fixedSize) {
        this.entries = new Object[fixedSize];
    }

    public Optional<VALUE> get(KEY key) {
        Objects.requireNonNull(key);

        // Iteration über alle Slots
        for (Object entry : entries) {
            // extrahiere und vergleiche Key
            if (Objects.nonNull(entry) && keysMatch(key, (VALUE) entry)) {
                return Optional.of((VALUE) entry);
            }
        }
        return Optional.empty();
    }

    public VALUE add(VALUE value) throws SchemeError {
        for (int i = 0; i < entries.length; i++) {
            if (Objects.nonNull(entries[i])) {
                if ((((EnvironmentEntry) value).getKey() == ((EnvironmentEntry)
                        entries[i]).getKey())) {
                    entries[i] = value;
                    return value;
                }
            } else {
                entries[i] = value;
                return value;
            }
        }
        throw new SchemeError("FixedSizeTable overflow!");
    }

}
{'fraction_non_alphanumeric': 0.11314083677077195, 'fraction_numerical': 0.016499705362404242, 'mean_word_length': 2.1977401129943503, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, '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': '3136774', 'n_tokens_mistral': 517, 'n_tokens_neox': 474, 'n_words': 115}