use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class CSVSaveService method getSampleSaveConfiguration.
/**
* Parse a CSV header line
*
* @param headerLine
* from CSV file
* @param filename
* name of file (for log message only)
* @return config corresponding to the header items found or null if not a
* header line
*/
public static SampleSaveConfiguration getSampleSaveConfiguration(String headerLine, String filename) {
// Try
String[] parts = splitHeader(headerLine, _saveConfig.getDelimiter());
// default
// delimiter
String delim = null;
if (parts == null) {
Perl5Matcher matcher = JMeterUtils.getMatcher();
PatternMatcherInput input = new PatternMatcherInput(headerLine);
Pattern pattern = JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
"\\w+((\\W)\\w+)?(\\2\\w+)*(\\2\"\\w+\")*", // last entries may be quoted strings
Perl5Compiler.READ_ONLY_MASK);
if (matcher.matches(input, pattern)) {
delim = matcher.getMatch().group(2);
// now validate the
parts = splitHeader(headerLine, delim);
// result
}
}
if (parts == null) {
// failed to recognise the header
return null;
}
// We know the column names all exist, so create the config
SampleSaveConfiguration saveConfig = new SampleSaveConfiguration(false);
int varCount = 0;
for (String label : parts) {
if (isVariableName(label)) {
varCount++;
} else {
Functor set = headerLabelMethods.get(label);
set.invoke(saveConfig, new Boolean[] { Boolean.TRUE });
}
}
if (delim != null) {
if (log.isWarnEnabled()) {
log.warn("Default delimiter '{}' did not work; using alternate '{}' for reading {}", _saveConfig.getDelimiter(), delim, filename);
}
saveConfig.setDelimiter(delim);
}
saveConfig.setVarCount(varCount);
return saveConfig;
}
use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class ObjectTableSorterTest method createModelAndSorter.
@BeforeEach
public void createModelAndSorter() {
String[] headers = { "key", "value", "object" };
Functor[] readFunctors = { new Functor("getKey"), new Functor("getValue"), new Functor("getValue") };
Functor[] writeFunctors = { null, null, null };
Class<?>[] editorClasses = { String.class, Integer.class, Object.class };
ObjectTableModel model = new ObjectTableModel(headers, readFunctors, writeFunctors, editorClasses);
sorter = new ObjectTableSorter(model);
List<Map.Entry<String, Integer>> data = asList(b2(), a3(), d4(), c1());
data.forEach(model::addRow);
}
use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class ObjectTableModel method setValueAt.
/**
* {@inheritDoc}
*/
@Override
public void setValueAt(Object cellValue, int row, int col) {
if (row < objects.size()) {
Object value = objects.get(row);
if (col < writeFunctors.size()) {
Functor setMethod = writeFunctors.get(col);
if (setMethod != null) {
setMethod.invoke(value, new Object[] { cellValue });
super.fireTableDataChanged();
}
} else if (headers.size() == 1) {
objects.set(row, cellValue);
}
}
}
use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class ObjectTableModel method checkFunctors.
/**
* Check all registered functors.
* <p>
* <b>** only for use in unit test code **</b>
* </p>
*
* @param _value - an instance of the table model row data item
* (if null, use the class passed to the constructor).
*
* @param caller - class of caller.
*
* @return false if at least one Functor cannot be found.
*/
@SuppressWarnings("deprecation")
public boolean checkFunctors(Object _value, Class<?> caller) {
Object value;
if (_value == null && objectClass != null) {
try {
value = objectClass.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
log.error("Cannot create instance of class {}", objectClass.getName(), e);
return false;
}
} else {
value = _value;
}
boolean status = true;
for (int i = 0; i < getColumnCount(); i++) {
Functor setMethod = writeFunctors.get(i);
if (setMethod != null && !setMethod.checkMethod(value, getColumnClass(i))) {
status = false;
log.warn("{} is attempting to use nonexistent {}", caller.getName(), setMethod);
}
Functor getMethod = readFunctors.get(i);
if (getMethod != null && !getMethod.checkMethod(value)) {
status = false;
log.warn("{} is attempting to use nonexistent {}", caller.getName(), getMethod);
}
}
return status;
}
use of org.apache.jorphan.reflect.Functor in project jmeter by apache.
the class ObjectTableModel method getValueAt.
/**
* {@inheritDoc}
*/
@Override
public Object getValueAt(int row, int col) {
log.debug("Getting row value");
Object value = objects.get(row);
if (headers.size() == 1 && col >= readFunctors.size()) {
return value;
}
Functor getMethod = readFunctors.get(col);
if (getMethod != null && value != null) {
return getMethod.invoke(value);
}
return null;
}
Aggregations