Skip to content

Commit

Permalink
Add fine logging to single column data source
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielsherry committed Aug 21, 2024
1 parent 82db5ef commit 5679e21
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.peakaboo.app.PeakabooLog;
import org.peakaboo.dataset.io.DataInputAdapter;
import org.peakaboo.dataset.source.model.DataSourceReadException;
import org.peakaboo.dataset.source.model.components.datasize.DataSize;
Expand Down Expand Up @@ -71,16 +72,18 @@ public List<String> getFileExtensions() {
}

@Override
public FileFormatCompatibility compatibility(List<DataInputAdapter> filenames) {
public FileFormatCompatibility compatibility(List<DataInputAdapter> files) {
try {
//exactly 1 file
if (filenames.size() != 1) {
if (files.size() != 1) {
PeakabooLog.get().fine("Expected exactly one file");
return FileFormatCompatibility.NO;
}
DataInputAdapter filename = filenames.get(0);
DataInputAdapter filename = files.get(0);

//no larger than 1MB
if (filename.size().orElse(0l) > 1048576l) {
PeakabooLog.get().fine("Expected a file less than 1MB");
return FileFormatCompatibility.NO;
}

Expand All @@ -90,10 +93,12 @@ public FileFormatCompatibility compatibility(List<DataInputAdapter> filenames) {
if (test(lines)) {
return FileFormatCompatibility.MAYBE_BY_CONTENTS;
} else {
PeakabooLog.get().fine("File did not meet expected structure");
return FileFormatCompatibility.NO;
}

} catch (IOException e) {
PeakabooLog.get().fine("An error occurred while reading this file: " + e.getMessage());
return FileFormatCompatibility.NO;
}
}
Expand Down Expand Up @@ -184,9 +189,12 @@ private static boolean test(List<String> lines) {
if (parts.length == 2) {
for (String line : lines) {
parts = line.split(splitPattern);
if (parts.length != 2) return false;
if (!isNumeric(parts[0])) return false;
if (!isNumeric(parts[1])) return false;
if (parts.length != 2) {
return false;
}
if (!isNumeric(parts[0]) || !isNumeric(parts[1])) {
return false;
}
}
} else if (parts.length == 1) {
for (String line : lines) {
Expand Down

0 comments on commit 5679e21

Please sign in to comment.