src/main/java/visitor/Group.java
<gh_stars>0package visitor;

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

public class Group<T> extends Task<T> {
    public String groupUuid;
    private List<Task<T>> tasks;

    public Group<T> addTask(Task<T> task) {
        if (tasks == null) {
            tasks = new ArrayList<>();
        }
        tasks.add(task);
        return this;
    }

    @Override
    public void freeze() {
        super.freeze();
        for (Task<T> task: tasks) {
            task.freeze();
        }
    }

    @Override
    public void stamp(Visitor<T> visitor) {

    }

    @Override
    public void apply(T arg) {
        this.freeze();
        groupUuid = UUID.randomUUID().toString();
        tasks = Collections.unmodifiableList(tasks);
        for (Task<T> task: tasks) {
            task.apply(arg);
        }
    }
}
