<commit_before>package net.lxwrz.simplees.infrastructure;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class AggregateRoot {
    private UUID id;
    private List<Event> uncommitedChanges = new ArrayList<Event>();
    private long version;

    public AggregateRoot() {
        this(UUID.randomUUID());
    }

    public AggregateRoot(UUID aggregateId) {
        id = aggregateId;
    }

    public void applyChange(Event event) {
        applyChange(event, true);
    }

    // TODO refactor!
    private void applyChange(Event event, boolean isNew) {
        UnimportantCrap.invokeHandlerMethod(this, event);
        if (isNew) {
            uncommitedChanges.add(event);
        } else {
            version++;
        }
    }

    public List<Event> getUncommitedChanges() {
        return uncommitedChanges;
    }

    public void markChangesAsCommited() {
        uncommitedChanges.clear();
    }

    public void loadFromHistory(List<Event> history) {
        for (Event event : history) {
            applyChange(event, false);
        }
    }

    public UUID getId() {
        return id;
    }<commit_msg>Refactor: get rid of the ugly else<commit_after>package net.lxwrz.simplees.infrastructure;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class AggregateRoot {
    private UUID id;
    private List<Event> uncommitedChanges = new ArrayList<Event>();
    private long version;

    public AggregateRoot() {
        this(UUID.randomUUID());
    }

    public AggregateRoot(UUID aggregateId) {
        id = aggregateId;
    }

    public void applyChange(Event event) {
        UnimportantCrap.invokeHandlerMethod(this, event);
        uncommitedChanges.add(event);
    }

    private void applyChangeFromHistory(Event event) {
        UnimportantCrap.invokeHandlerMethod(this, event);
        version++;
    }

    public List<Event> getUncommitedChanges() {
        return uncommitedChanges;
    }

    public void markChangesAsCommited() {
        uncommitedChanges.clear();
    }

    public void loadFromHistory(List<Event> history) {
        for (Event event : history) {
            applyChangeFromHistory(event);
        }
    }

    public UUID getId() {
        return id;
    }
{'fraction_non_alphanumeric': 0.09458864936207655, 'fraction_numerical': 0.0, 'mean_word_length': 2.5924170616113744, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2276657', 'n_tokens_mistral': 664, 'n_tokens_neox': 652, 'n_words': 148}