com.softicar.platform.common.core.interfaces.NullaryVoidFunctionList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.interfaces;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
/**
* Aggregates multiple {@link INullaryVoidFunction} objects into a list, that
* itself implements {@link INullaryVoidFunction}.
*
* @author Oliver Richers
*/
public class NullaryVoidFunctionList implements INullaryVoidFunction {
private final Collection functions;
public NullaryVoidFunctionList() {
this.functions = new ArrayList<>();
}
/**
* Calls all contained {@link INullaryVoidFunction} objects in the order
* that they were added.
*/
@Override
public void apply() {
for (var function: functions) {
function.apply();
}
}
public NullaryVoidFunctionList add(INullaryVoidFunction function) {
functions.add(Objects.requireNonNull(function));
return this;
}
public NullaryVoidFunctionList addAll(NullaryVoidFunctionList other) {
functions.addAll(other.functions);
return this;
}
}