<commit_before>
package com.zygon.htm.memory.core;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Sets;
import com.zygon.htm.core.Identifier;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author zygon
 */
public class ActivationTable {

    private static LoadingCache<Identifier, Identifier> createIdentifierCache (long timeout, TimeUnit units) {

        LoadingCache<Identifier, Identifier> cache =
            CacheBuilder.newBuilder()
                .expireAfterWrite(timeout, units)
                .build(
                    new CacheLoader<Identifier, Identifier>() {
                        @Override
                        public Identifier load(Identifier key) throws Exception {
                            return key;
                        }
                    }
                );

        return cache;
    }

    private final LoadingCache<Identifier,Identifier> cache = createIdentifierCache(1, TimeUnit.SECONDS);

    public final void add (ActivationMessage msg) throws ExecutionException {
        this.cache.put(msg.getDestination(), msg.getDestination());
    }

    public final long getCount() {
        return this.cache.size();
    }

    public final Set<Identifier> getAllIdentifiers() {

        Set<Identifier> sources = Sets.newHashSet();

        // light copy - hopefully this won't cause issues
        for (Identifier id : this.cache.asMap().values()) {
            sources.add(id);
        }

        return sources;
    }

    public final boolean contains(Identifier id) {
        return this.cache.getIfPresent(id) != null;
    }

    public final boolean isEmpty() {
        return this.cache.size() == 0;
    }
}<commit_msg>Some refactoring<commit_after>package com.zygon.htm.memory.core;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Sets;
import com.zygon.htm.core.Identifier;

import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author zygon
 */
public class ActivationTable {

    private final LoadingCache<Identifier, Identifier> cache
            = createCache(1, TimeUnit.SECONDS);

    public final void add(ActivationMessage msg) throws ExecutionException {
        this.cache.put(msg.getDestination(), msg.getDestination());
    }

    public final long getCount() {
        return this.cache.size();
    }

    public final Set<Identifier> getAllIdentifiers() {

        Set<Identifier> sources = Sets.newHashSet();
        // light copy - hopefully this won't cause issues
        sources.addAll(this.cache.asMap().values());

        return sources;
    }

    public final boolean contains(Identifier id) {
        return this.cache.getIfPresent(id) != null;
    }

    public final boolean isEmpty() {
        return this.cache.size() == 0;
    }

    // Expire after write
    private static <T> LoadingCache<T, T> createCache(long timeout, TimeUnit units) {
        return CacheBuilder.newBuilder()
                .expireAfterWrite(timeout, units)
                .build(new CacheLoader<T, T>() {
                    @Override
                    public T load(T key) throws Exception {
                        return key;
                    }
                });
    }
}
{'fraction_non_alphanumeric': 0.10105024127164348, 'fraction_numerical': 0.0011353959693443088, 'mean_word_length': 2.359389895138227, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4940435', 'n_tokens_mistral': 959, 'n_tokens_neox': 910, 'n_words': 218}