net.zerobuilder.compiler.generate.DtoRegularGoalContext Maven / Gradle / Ivy
package net.zerobuilder.compiler.generate;
import com.squareup.javapoet.TypeName;
import net.zerobuilder.compiler.generate.DtoGoalContext.AbstractGoalContext;
import net.zerobuilder.compiler.generate.DtoProjectedRegularGoalContext.ProjectedRegularGoalContext;
import net.zerobuilder.compiler.generate.DtoRegularGoal.SimpleRegularGoalContext;
import java.util.List;
import java.util.function.Function;
final class DtoRegularGoalContext {
public static abstract class RegularGoalContext extends AbstractGoalContext {
public final List thrownTypes;
RegularGoalContext(List thrownTypes) {
this.thrownTypes = thrownTypes;
}
abstract R acceptRegular(RegularGoalContextCases cases);
@Override
final R accept(DtoGoalContext.GoalCases cases) {
return cases.regularGoal(this);
}
}
interface RegularGoalContextCases {
R simple(SimpleRegularGoalContext simple);
R projected(ProjectedRegularGoalContext projected);
}
static Function asFunction(RegularGoalContextCases cases) {
return goal -> goal.acceptRegular(cases);
}
static Function regularGoalContextCases(
Function super SimpleRegularGoalContext, ? extends R> simpleFunction,
Function super ProjectedRegularGoalContext, ? extends R> projectedFunction) {
return asFunction(new RegularGoalContextCases() {
@Override
public R simple(SimpleRegularGoalContext simple) {
return simpleFunction.apply(simple);
}
@Override
public R projected(ProjectedRegularGoalContext projected) {
return projectedFunction.apply(projected);
}
});
}
private DtoRegularGoalContext() {
throw new UnsupportedOperationException("no instances");
}
}