net.zerobuilder.compiler.generate.DtoGeneratorInput Maven / Gradle / Ivy
The newest version!
package net.zerobuilder.compiler.generate;
import net.zerobuilder.compiler.generate.DtoBeanGoalDescription.BeanGoalDescription;
import net.zerobuilder.compiler.generate.DtoContext.GoalContext;
import net.zerobuilder.compiler.generate.DtoModule.BeanModule;
import net.zerobuilder.compiler.generate.DtoModule.ProjectedModule;
import net.zerobuilder.compiler.generate.DtoModule.RegularSimpleModule;
import net.zerobuilder.compiler.generate.DtoRegularGoalDescription.ProjectedRegularGoalDescription;
import net.zerobuilder.compiler.generate.DtoRegularGoalDescription.SimpleRegularGoalDescription;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
public final class DtoGeneratorInput {
interface GoalInputCases {
R projected(ProjectedGoalInput projected, P p);
R regularSimple(RegularSimpleGoalInput regularSimple, P p);
R bean(BeanGoalInput bean, P p);
}
public static abstract class AbstractGoalInput {
abstract R accept(GoalInputCases cases, P p);
}
private static BiFunction asFunction(GoalInputCases cases) {
return (input, p) -> input.accept(cases, p);
}
static BiFunction goalInputCases(
BiFunction projectedFunction,
BiFunction regularSimpleFunction,
BiFunction beanFunction) {
return asFunction(new GoalInputCases() {
@Override
public R projected(ProjectedGoalInput projected, P p) {
return projectedFunction.apply(projected, p);
}
@Override
public R regularSimple(RegularSimpleGoalInput regularSimple, P p) {
return regularSimpleFunction.apply(regularSimple, p);
}
@Override
public R bean(BeanGoalInput bean, P p) {
return beanFunction.apply(bean, p);
}
});
}
static Function goalInputCases(
Function projectedFunction,
Function regularSimpleFunction,
Function beanFunction) {
BiFunction biFunction = asFunction(new GoalInputCases() {
@Override
public R projected(ProjectedGoalInput projected, Void _null) {
return projectedFunction.apply(projected);
}
@Override
public R regularSimple(RegularSimpleGoalInput regularSimple, Void _null) {
return regularSimpleFunction.apply(regularSimple);
}
@Override
public R bean(BeanGoalInput bean, Void _null) {
return beanFunction.apply(bean);
}
});
return input -> biFunction.apply(input, null);
}
public static final class RegularSimpleGoalInput extends AbstractGoalInput {
final RegularSimpleModule module;
final SimpleRegularGoalDescription description;
public RegularSimpleGoalInput(RegularSimpleModule module, SimpleRegularGoalDescription description) {
this.module = module;
this.description = description;
}
@Override
R accept(GoalInputCases cases, P p) {
return cases.regularSimple(this, p);
}
}
public static final class BeanGoalInput extends AbstractGoalInput {
final BeanModule module;
final BeanGoalDescription description;
public BeanGoalInput(BeanModule module, BeanGoalDescription description) {
this.module = module;
this.description = description;
}
@Override
R accept(GoalInputCases cases, P p) {
return cases.bean(this, p);
}
}
public static final class ProjectedGoalInput extends AbstractGoalInput {
final ProjectedModule module;
final ProjectedRegularGoalDescription description;
public ProjectedGoalInput(ProjectedModule module, ProjectedRegularGoalDescription description) {
this.module = module;
this.description = description;
}
@Override
R accept(GoalInputCases cases, P p) {
return cases.projected(this, p);
}
}
public static final class GeneratorInput {
public final List goals;
public final GoalContext context;
private GeneratorInput(DtoContext.GoalContext context, List goals) {
this.goals = goals;
this.context = context;
}
public static GeneratorInput create(GoalContext context, List goals) {
return new GeneratorInput(context, goals);
}
}
private DtoGeneratorInput() {
throw new UnsupportedOperationException("no instances");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy