remove obsolete class

This commit is contained in:
2019-02-09 15:25:39 +01:00
parent 27b83234cc
commit 93dea402a5

View File

@@ -1,80 +0,0 @@
package org.lucares.pdbui;
import java.io.IOException;
import java.util.Optional;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.api.TagsBuilder;
import org.lucares.pdbui.date.FastISODateParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO remove?
public class CsvToEntryTransformer implements LineToEntryTransformer {
private static final Logger LOGGER = LoggerFactory.getLogger(CsvToEntryTransformer.class);
private final String[] headers;
private final Pattern splitPattern = Pattern.compile(",");
private final FastISODateParser fastISODateParser = new FastISODateParser();
public CsvToEntryTransformer(final String[] headers) {
this.headers = headers;
}
@Override
public Optional<Entry> toEntry(final String line) throws IOException {
Optional<Entry> result;
try {
// For future reference:
// Pattern.split is actually faster than StringUtils.splitPreserveAll when the
// test runs longer.
// It seems that the JIT is compiling StringUtils.splitPreserveAll earlier, but
// Pattern.split is ending up getting the faster code in the long run.
final String[] columns = splitPattern.split(line);
if (columns.length == headers.length && columns[0].length() > 0 && columns[0].charAt(0) != '@') {
result = createEntry(columns);
} else {
result = Optional.empty();
}
} catch (final Exception e) {
LOGGER.error("Failed to create entry from line: {}", line, e);
result = Optional.empty();
}
return result;
}
private Optional<Entry> createEntry(final String[] columns) {
long epochMilli = 0;
long duration = Long.MIN_VALUE;
final TagsBuilder tagsBuilder = TagsBuilder.create();
for (int i = 0; i < columns.length; i++) {
switch (headers[i]) {
case "@timestamp":
epochMilli = fastISODateParser.parseAsEpochMilli(columns[i]);
break;
case "duration":
duration = Long.parseLong(columns[i]);
break;
default:
if (!StringUtils.isBlank(columns[i])) {
final int key = Tags.STRING_COMPRESSOR.put(headers[i]);
final int value = Tags.STRING_COMPRESSOR.put(columns[i]);
tagsBuilder.add(key, value);
}
break;
}
}
final Tags tags = tagsBuilder.build();
final Entry entry = new Entry(epochMilli, duration, tags);
return Optional.of(entry);
}
}