<commit_before>package org.granchi.hollywood;

/**
 * Model for a Hollywood application.
 * <p>
 * <ul>
 * <li>Should not block, nor start any thread</li>
 * <li>Should be immutable, so there are no lateral effects from it being passed from actor to
 * actor</li>
 * <li>Is called from a single thread, so it will never receive two actions concurrently</li>
 * <li>Is ok to return itself from an action, if no change is needed</li>
 * </ul>
 *
 * @author serandel
 */
public interface Model {
    /**
     * Generates a new model, from itself and the data contained in an action.
     * <p>
     * It is allowed to return itself if the action didn't cause any state change.
     *
     * @param action action, can't be null
     * @return new model
     */
    Model actUpon(Action action);
}<commit_msg>Change Model to an abstract class so getSubmodelOfType is defined here (and I remain unconvinced about the API...)<commit_after>package org.granchi.hollywood;

import java.util.Collection;
import java.util.Collections;

/**
 * Model for a Hollywood application.
 * <p>
 * <ul>
 * <li>Should not block, nor start any thread</li>
 * <li>Should be immutable, so there are no lateral effects from it being passed from actor to
 * actor</li>
 * <li>Is called from a single thread, so it will never receive two actions concurrently</li>
 * <li>Is ok to return itself from an action, if no change is needed</li>
 * </ul>
 *
 * @author serandel
 */
public abstract class Model {
    /**
     * Generates a new model, from itself and the data contained in an action.
     * <p>
     * It is allowed to return itself if the action didn't cause any state change.
     *
     * @param action action, can't be null
     * @return new model
     */
    abstract Model actUpon(Action action);

    /**
     * Returns itself if it's of a specific class or a subclass of it, or, for composite models, the
     * submodels that are compliant with the same condition.
     *
     * @param type desired class
     * @param <T>  type of the desired class
     * @return model of submodel of that class
     */
    @SuppressWarnings("unchecked")
    public <T extends Model> Collection<T> getSubmodelOfType(Class<T> type) {
        if (type.isAssignableFrom(this.getClass())) {
            return Collections.singletonList((T) this);
        } else {
            return Collections.emptyList();
        }
    }
}
{'fraction_non_alphanumeric': 0.09649122807017543, 'fraction_numerical': 0.0, 'mean_word_length': 2.9262295081967213, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '4037642', 'n_tokens_mistral': 693, 'n_tokens_neox': 673, 'n_words': 295}