<commit_before>package model.entity;

import model.component.base.Component;
import serialization.SerializableReader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;


/**
 * Created by rhondusmithwick on 3/30/16.
 *
 * @author <NAME>
 */
public class EntitySystem {
    private final Map<Integer, Entity> entities = new HashMap<>();

    private int maxID = 0;

    public Entity createEntity() {
        int ID = getNextAvailableID();
        Entity entity = new Entity(ID);
        maxID++;
        return entity;
    }

    public Entity createEntityFromLoad(String fileName) {
        Entity entity = new SerializableReader<Entity>(fileName).readSingle();
        addEntity(entity);
        return entity;
    }

    public Entity createEntityFromDefault(String defaultFileName) {
        Entity entity = createEntity();
        List<Component> components = new SerializableReader<Component>(defaultFileName).read();
        entity.addComponentList(components);
        return entity;
    }

    public void addEntity(Entity entity) {
        entities.put(entity.getID(), entity);
    }


    public <T extends Component> List<T> getAllComponentsOfType(Class<T> componentType) {
        return entities.values().stream().map(e -> e.getCompoWnentList(componentType))
                .flatMap(List::stream).filter(Objects::nonNull).collect(Collectors.toList());
    }

    public <T extends Component> Set<Entity> getEntitiesWithComponentType(Class<T> componentType) {
        Predicate<Entity> hasComponent = (e) -> e.hasComponent(componentType);<commit_msg>Fixed small error.<commit_after>package model.entity;

import model.component.base.Component;
import serialization.SerializableReader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;


/**
 * Created by rhondusmithwick on 3/30/16.
 *
 * @author <NAME>
 */
public class EntitySystem {
    private final Map<Integer, Entity> entities = new HashMap<>();

    private int maxID = 0;

    public Entity createEntity() {
        int ID = getNextAvailableID();
        Entity entity = new Entity(ID);
        maxID++;
        return entity;
    }

    public Entity createEntityFromLoad(String fileName) {
        Entity entity = new SerializableReader<Entity>(fileName).readSingle();
        addEntity(entity);
        return entity;
    }

    public Entity createEntityFromDefault(String defaultFileName) {
        Entity entity = createEntity();
        List<Component> components = new SerializableReader<Component>(defaultFileName).read();
        entity.addComponentList(components);
        return entity;
    }

    public void addEntity(Entity entity) {
        entities.put(entity.getID(), entity);
    }


    public <T extends Component> List<T> getAllComponentsOfType(Class<T> componentType) {
        return entities.values().stream().map(e -> e.getComponentList(componentType))
                .flatMap(List::stream).filter(Objects::nonNull).collect(Collectors.toList());
    }

    public <T extends Component> Set<Entity> getEntitiesWithComponentType(Class<T> componentType) {
        Predicate<Entity> hasComponent = (e) -> e.hasComponent(componentType);
{'fraction_non_alphanumeric': 0.11146869514335869, 'fraction_numerical': 0.003510825043885313, 'mean_word_length': 3.5831099195710454, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, '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': '4421398', 'n_tokens_mistral': 942, 'n_tokens_neox': 922, 'n_words': 215}