All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.zerobuilder.compiler.generate.DtoProjectedGoal Maven / Gradle / Ivy

There is a newer version: 1.603
Show newest version
package net.zerobuilder.compiler.generate;

import com.squareup.javapoet.TypeName;
import net.zerobuilder.compiler.generate.DtoBeanGoal.BeanGoalContext;
import net.zerobuilder.compiler.generate.DtoGoalContext.AbstractGoalContext;
import net.zerobuilder.compiler.generate.DtoProjectedRegularGoalContext.ProjectedRegularGoalContext;

import java.util.function.Function;

import static java.util.function.Function.identity;

public final class DtoProjectedGoal {

  public interface ProjectedGoal {
     R acceptProjected(ProjectedGoalCases cases);
  }

  interface ProjectedGoalCases {
    R regular(ProjectedRegularGoalContext regular);
    R bean(BeanGoalContext bean);
  }

  public static  Function asFunction(ProjectedGoalCases cases) {
    return goal -> goal.acceptProjected(cases);
  }

  public static  Function projectedGoalCases(
      Function regularFunction,
      Function beanFunction) {
    return asFunction(new ProjectedGoalCases() {
      @Override
      public R regular(ProjectedRegularGoalContext regular) {
        return regularFunction.apply(regular);
      }
      @Override
      public R bean(BeanGoalContext bean) {
        return beanFunction.apply(bean);
      }
    });
  }

  private static  Function restrict(Function function) {
    return projectedGoalCases(
        regular -> function.apply(regular),
        bean -> function.apply(bean)
    );
  }

  static final Function goalContext =
      restrict(identity());

  public static final Function goalType =
      restrict(AbstractGoalContext::goalType);

  static final Function context =
      restrict(AbstractGoalContext::context);

  private DtoProjectedGoal() {
    throw new UnsupportedOperationException("no instances");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy