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

us.abstracta.jmeter.javadsl.codegeneration.params.EncodingParam Maven / Gradle / Ivy

Go to download

Simple API to run JMeter performance tests in an VCS and programmers friendly way.

There is a newer version: 028
Show newest version
package us.abstracta.jmeter.javadsl.codegeneration.params;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import us.abstracta.jmeter.javadsl.codegeneration.MethodCall;

/**
 * Is a parameter with an encoding (Charset) value.
 *
 * @since 0.62
 */
public class EncodingParam extends FixedParam {

  private static final Map STANDARD_CHARSETS_NAMES =
      findConstantNamesMap(StandardCharsets.class, Charset.class, s -> true);

  public EncodingParam(String expression, Charset defaultValue) {
    super(Charset.class, expression, Charset::forName, defaultValue);
  }

  @Override
  public Set getImports() {
    return Collections.singleton((STANDARD_CHARSETS_NAMES.get(value) != null
        ? StandardCharsets.class
        : Charset.class).getName());
  }

  public String buildCode(String indent) {
    String standardCharsetName = STANDARD_CHARSETS_NAMES.get(value);
    return standardCharsetName != null
        ? StandardCharsets.class.getSimpleName() + "." + standardCharsetName
        : MethodCall.forStaticMethod(Charset.class, "forName", new StringParam(getValue().name()))
            .buildCode();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy