package org.apache.jmeter.protocol.java.sampler;
import java.util.Iterator;
import java.util.Map;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.test.JavaTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JavaSamplerContext {
private static final Logger log = LoggerFactory.getLogger(JavaTest.class);
private final Map<String, String> params;
public JavaSamplerContext(Arguments args) {
this.params = args.getArgumentsAsMap();
}
public boolean containsParameter(String name) {
return this.params.containsKey(name);
}
public Iterator<String> getParameterNamesIterator() {
return this.params.keySet().iterator();
}
public String getParameter(String name) {
return this.getParameter(name, (String)null);
}
public String getParameter(String name, String defaultValue) {
return this.params != null && this.params.containsKey(name) ? (String)this.params.get(name) : defaultValue;
}
public int getIntParameter(String name) throws NumberFormatException {
if (this.params != null && this.params.containsKey(name)) {
return Integer.decode((String)this.params.get(name));
} else {
throw new NumberFormatException("No value for parameter named '" + name + "'.");
}
}
public int getIntParameter(String name, int defaultValue) {
if (this.params != null && this.params.containsKey(name)) {
try {
return Integer.decode((String)this.params.get(name));
} catch (NumberFormatException var4) {
log.warn("Value for parameter '" + name + "' not an integer: '" + (String)this.params.get(name) + "'. Using default: '" + defaultValue + "'.", var4);
return defaultValue;
}
} else {
return defaultValue;
}
}
public long getLongParameter(String name) throws NumberFormatException {
if (this.params != null && this.params.containsKey(name)) {
return Long.decode((String)this.params.get(name));
} else {
throw new NumberFormatException("No value for parameter named '" + name + "'.");
}
}
public long getLongParameter(String name, long defaultValue) {
if (this.params != null && this.params.containsKey(name)) {
try {
return Long.decode((String)this.params.get(name));
} catch (NumberFormatException var5) {
log.warn("Value for parameter '" + name + "' not a long: '" + (String)this.params.get(name) + "'. Using default: '" + defaultValue + "'.", var5);
return defaultValue;
}
} else {
return defaultValue;
}
}
}
网友评论