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

autofixture.publicinterface.inline.strings.IdentifierStringGenerator Maven / Gradle / Ivy

package autofixture.publicinterface.inline.strings;

import autofixture.interfaces.FixtureContract;
import autofixture.interfaces.InlineInstanceGenerator;

public class IdentifierStringGenerator implements
    InlineInstanceGenerator {

  private final InlineInstanceGenerator alphaCharGenerator;
  private final InlineInstanceGenerator digitCharGenerator;
  private final int length;

  public IdentifierStringGenerator(
      final InlineInstanceGenerator alphaCharGenerator,
      final InlineInstanceGenerator digitCharGenerator, final int length) {
    this.alphaCharGenerator = alphaCharGenerator;
    this.digitCharGenerator = digitCharGenerator;
    this.length = length;
  }

  @Override
  public String next(final FixtureContract fixture) {
    final StringBuilder result = new StringBuilder();
    for (int i = 0; i < length / 2; ++i) {
      result.append(alphaCharGenerator.next(fixture));
      result.append(digitCharGenerator.next(fixture));
    }

    if (result.length() < length) {
      result.append(alphaCharGenerator.next(fixture));
    }

    return result.toString();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy