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

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

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

import net.zerobuilder.compiler.generate.DtoModule.Module;
import net.zerobuilder.compiler.generate.DtoProjectedDescription.ProjectedDescription;
import net.zerobuilder.compiler.generate.DtoProjectedModule.ProjectedModule;
import net.zerobuilder.compiler.generate.DtoSimpleDescription.SimpleDescription;

import java.util.function.BiFunction;
import java.util.function.Function;

public final class DtoDescriptionInput {

  interface DescriptionInputCases {
    R simple(SimpleDescriptionInput simple);
    R projected(ProjectedDescriptionInput projected);
  }

  public interface DescriptionInput {
     R accept(DescriptionInputCases cases);
  }

  static  Function asFunction(DescriptionInputCases cases) {
    return descriptionInput -> descriptionInput.accept(cases);
  }

  static  Function descriptionInputCases(
      BiFunction simpleFunction,
      BiFunction projectedFunction) {
    return asFunction(new DescriptionInputCases() {
      @Override
      public R simple(SimpleDescriptionInput simple) {
        return simpleFunction.apply(simple.module, simple.description);
      }
      @Override
      public R projected(ProjectedDescriptionInput projected) {
        return projectedFunction.apply(projected.module, projected.description);
      }
    });
  }

  public static final class SimpleDescriptionInput implements DescriptionInput {
    final Module module;
    final SimpleDescription description;
    public SimpleDescriptionInput(Module module, SimpleDescription description) {
      this.module = module;
      this.description = description;
    }

    @Override
    public  R accept(DescriptionInputCases cases) {
      return cases.simple(this);
    }
  }

  public static final class ProjectedDescriptionInput implements DescriptionInput {
    final ProjectedModule module;
    final ProjectedDescription description;
    public ProjectedDescriptionInput(ProjectedModule module, ProjectedDescription description) {
      this.module = module;
      this.description = description;
    }

    @Override
    public  R accept(DescriptionInputCases cases) {
      return cases.projected(this);
    }
  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy