<commit_before>package net.zerobuilder.compiler.generate;

import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.TypeName;
import net.zerobuilder.compiler.generate.DtoContext.BuildersContext;
import net.zerobuilder.compiler.generate.DtoGoal.AbstractGoalDetails;
import net.zerobuilder.compiler.generate.DtoRegularParameter.AbstractRegularParameter;
import net.zerobuilder.compiler.generate.DtoRegularParameter.ProjectedParameter;
import net.zerobuilder.compiler.generate.DtoRegularParameter.SimpleParameter;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import static java.util.Collections.emptyList;
import static javax.lang.model.element.Modifier.PRIVATE;
import static net.zerobuilder.compiler.generate.Utilities.fieldSpec;
import static net.zerobuilder.compiler.generate.Utilities.memoize;

public final class DtoRegularStep {

  static abstract class AbstractRegularStep extends DtoStep.AbstractStep {

    protected AbstractRegularStep(String thisType,
                                  Optional<AbstractRegularStep> nextType,
                                  AbstractGoalDetails goalDetails,
                                  BuildersContext context) {
      super(thisType, nextType, goalDetails, context);
    }

    abstract Optional<DtoStep.CollectionInfo> collectionInfo();
    abstract FieldSpec field();
    abstract AbstractRegularParameter regularParameter();
    abstract List<TypeName> declaredExceptions();

    @Override
    final <R> R accept(DtoStep.StepCases<R> cases) {
      return cases.regularStep(this);
    }
  }

  static final class ProjectedRegularStep extends AbstractRegularStep {
    final ProjectedParameter parameter;
    final List<TypeName> declaredExceptions;

    private final Supplier<FieldSpec> field;
    private final Supplier<Optional<DtoStep.CollectionInfo>> collectionInfo;

    private ProjectedRegularStep(String thisType,
                                 Optional<AbstractRegularStep> nextType,
                                 AbstractGoalDetails goalDetails,
                                 BuildersContext context,
                                 ProjectedParameter parameter,
                                 List<TypeName> declaredExceptions) {
      super(thisType, nextType, goalDetails, context);
      this.declaredExceptions = declaredExceptions;
      this.parameter = parameter;
      this.field = memoizeField(parameter);
      this.collectionInfo = memoizeCollectionInfo(parameter);
    }

    private static Supplier<Optional<DtoStep.CollectionInfo>> memoizeCollectionInfo(
        AbstractRegularParameter parameter) {
      return memoize(() ->
          DtoStep.CollectionInfo.create(parameter.type, parameter.name));
    }

    private static Supplier<FieldSpec> memoizeField(AbstractRegularParameter parameter) {
      return memoize(() ->
          fieldSpec(parameter.type, parameter.name, PRIVATE));
    }

    static ProjectedRegularStep create(String thisType,
                                       Optional<AbstractRegularStep> nextType,
                                       AbstractGoalDetails goalDetails,
                                       BuildersContext context,
                                       ProjectedParameter parameter,
                                       List<TypeName> declaredExceptions) {
      return new ProjectedRegularStep(thisType, nextType, goalDetails, context, parameter, declaredExceptions);
    }

    @Override
    Optional<DtoStep.CollectionInfo> collectionInfo() {
      return collectionInfo.get();
    }

    @Override
    FieldSpec field() {
      return field.get();
    }

    @Override
    AbstractRegularParameter regularParameter() {
      return parameter;
    }

    @Override
    List<TypeName> declaredExceptions() {
      return declaredExceptions;
    }
  }

  static final class SimpleRegularStep extends AbstractRegularStep {
    final SimpleParameter parameter;

    private final Supplier<FieldSpec> field;
    private final Supplier<Optional<DtoStep.CollectionInfo>> collectionInfo;

    private SimpleRegularStep(String thisType,
                              Optional<AbstractRegularStep> nextType,
                              AbstractGoalDetails goalDetails,
                              BuildersContext context,
                              SimpleParameter parameter) {
      super(thisType, nextType, goalDetails, context);
      this.parameter = parameter;
      this.field = memoizeField(parameter);
      this.collectionInfo = memoizeCollectionInfo(parameter);
    }

    private static Supplier<Optional<DtoStep.CollectionInfo>> memoizeCollectionInfo(
        AbstractRegularParameter parameter) {
      return memoize(() ->
          DtoStep.CollectionInfo.create(parameter.type, parameter.name));
    }

    private static Supplier<FieldSpec> memoizeField(AbstractRegularParameter parameter) {
      return memoize(() ->
          fieldSpec(parameter.type, parameter.name, PRIVATE));
    }

    static SimpleRegularStep create(String thisType,
                                    Optional<AbstractRegularStep> nextType,
                                    AbstractGoalDetails goalDetails,
                                    BuildersContext context,
                                    SimpleParameter parameter) {
      return new SimpleRegularStep(thisType, nextType, goalDetails, context, parameter);
    }

    @Override
    Optional<DtoStep.CollectionInfo> collectionInfo() {
      return collectionInfo.get();
    }

    @Override
    FieldSpec field() {
      return field.get();
    }

    @Override
    AbstractRegularParameter regularParameter() {
      return parameter;
    }

    @Override
    List<TypeName> declaredExceptions() {
      return emptyList();
    }
  }


  private DtoRegularStep() {
    throw new UnsupportedOperationException("no instances");
  }
}<commit_msg>refactoring<commit_after>package net.zerobuilder.compiler.generate;

import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.TypeName;
import net.zerobuilder.compiler.generate.DtoContext.BuildersContext;
import net.zerobuilder.compiler.generate.DtoGoal.AbstractGoalDetails;
import net.zerobuilder.compiler.generate.DtoRegularParameter.AbstractRegularParameter;
import net.zerobuilder.compiler.generate.DtoRegularParameter.ProjectedParameter;
import net.zerobuilder.compiler.generate.DtoRegularParameter.SimpleParameter;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import static java.util.Collections.emptyList;
import static javax.lang.model.element.Modifier.PRIVATE;
import static net.zerobuilder.compiler.generate.Utilities.fieldSpec;
import static net.zerobuilder.compiler.generate.Utilities.memoize;

public final class DtoRegularStep {

  static abstract class AbstractRegularStep extends DtoStep.AbstractStep {

    protected AbstractRegularStep(String thisType,
                                  Optional<AbstractRegularStep> nextType,
                                  AbstractGoalDetails goalDetails,
                                  BuildersContext context) {
      super(thisType, nextType, goalDetails, context);
    }

    abstract Optional<DtoStep.CollectionInfo> collectionInfo();
    abstract FieldSpec field();
    abstract AbstractRegularParameter regularParameter();
    abstract List<TypeName> declaredExceptions();

    @Override
    final <R> R accept(DtoStep.StepCases<R> cases) {
      return cases.regularStep(this);
    }
  }

  static final class ProjectedRegularStep extends AbstractRegularStep {
    final ProjectedParameter parameter;
    final List<TypeName> declaredExceptions;

    private final Supplier<FieldSpec> field;
    private final Supplier<Optional<DtoStep.CollectionInfo>> collectionInfo;

    private ProjectedRegularStep(String thisType,
                                 Optional<AbstractRegularStep> nextType,
                                 AbstractGoalDetails goalDetails,
                                 BuildersContext context,
                                 ProjectedParameter parameter,
                                 List<TypeName> declaredExceptions,
                                 Supplier<FieldSpec> field,
                                 Supplier<Optional<DtoStep.CollectionInfo>> collectionInfo) {
      super(thisType, nextType, goalDetails, context);
      this.declaredExceptions = declaredExceptions;
      this.parameter = parameter;
      this.field = field;
      this.collectionInfo = collectionInfo;
    }

    static ProjectedRegularStep create(String thisType,
                                       Optional<AbstractRegularStep> nextType,
                                       AbstractGoalDetails goalDetails,
                                       BuildersContext context,
                                       ProjectedParameter parameter,
                                       List<TypeName> declaredExceptions) {
      return new ProjectedRegularStep(thisType, nextType, goalDetails, context, parameter, declaredExceptions,
          memoizeField(parameter), memoizeCollectionInfo(parameter));
    }

    @Override
    Optional<DtoStep.CollectionInfo> collectionInfo() {
      return collectionInfo.get();
    }

    @Override
    FieldSpec field() {
      return field.get();
    }

    @Override
    AbstractRegularParameter regularParameter() {
      return parameter;
    }

    @Override
    List<TypeName> declaredExceptions() {
      return declaredExceptions;
    }
  }

  static final class SimpleRegularStep extends AbstractRegularStep {
    final SimpleParameter parameter;

    private final Supplier<FieldSpec> field;
    private final Supplier<Optional<DtoStep.CollectionInfo>> collectionInfo;

    private SimpleRegularStep(String thisType,
                              Optional<AbstractRegularStep> nextType,
                              AbstractGoalDetails goalDetails,
                              BuildersContext context,
                              SimpleParameter parameter,
                              Supplier<FieldSpec> field,
                              Supplier<Optional<DtoStep.CollectionInfo>> collectionInfo) {
      super(thisType, nextType, goalDetails, context);
      this.parameter = parameter;
      this.field = field;
      this.collectionInfo = collectionInfo;
    }

    static SimpleRegularStep create(String thisType,
                                    Optional<AbstractRegularStep> nextType,
                                    AbstractGoalDetails goalDetails,
                                    BuildersContext context,
                                    SimpleParameter parameter) {
      return new SimpleRegularStep(thisType, nextType, goalDetails, context, parameter,
          memoizeField(parameter), memoizeCollectionInfo(parameter));
    }

    @Override
    Optional<DtoStep.CollectionInfo> collectionInfo() {
      return collectionInfo.get();
    }

    @Override
    FieldSpec field() {
      return field.get();
    }

    @Override
    AbstractRegularParameter regularParameter() {
      return parameter;
    }

    @Override
    List<TypeName> declaredExceptions() {
      return emptyList();
    }
  }

  private static Supplier<Optional<DtoStep.CollectionInfo>> memoizeCollectionInfo(
      AbstractRegularParameter parameter) {
    return memoize(() ->
        DtoStep.CollectionInfo.create(parameter.type, parameter.name));
  }

  private static Supplier<FieldSpec> memoizeField(AbstractRegularParameter parameter) {
    return memoize(() ->
        fieldSpec(parameter.type, parameter.name, PRIVATE));
  }

  private DtoRegularStep() {
    throw new UnsupportedOperationException("no instances");
  }
}
{'fraction_non_alphanumeric': 0.07025321851820275, 'fraction_numerical': 0.0, 'mean_word_length': 2.5130278526504943, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1374468', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2721, 'n_words': 566}