Commit 0ff4f179 authored by Georg Graßnick's avatar Georg Graßnick 🤔
Browse files

Merge branch 'refactor/georg' into 'master'

Refactor/georg

See merge request !46
parents b0a4057f dfbcd0c8
......@@ -149,14 +149,15 @@ public final class App {
});
try {
// Logging example
mLogger.info("Application started");
// Parse command line parameters
CommandLineParser cliParser = new CommandLineParser();
if (CommandLineParser.checkForHelp(args)) {
cliParser.printHelp(); // If requested, print help and exit
return EXIT_SUCCESS;
}
mLogger.info("Application started");
SettingsWriter settings = cliParser.parse(args);
SettingsReader settingsReader = settings;
......
......@@ -53,8 +53,17 @@ public class CsvDotParser extends CsvParseAlgorithm<PointListContainer<PointList
Number yValue;
try {
xValue = Constants.NUMBER_FORMAT.parse(xRowIterator.next());
} catch (ParseException pe) {
// TODO: actually throw exceptions
// Currently this does not work because some of the csv data examples from SVGPlott include empty cells,
// and their correct layout is not documented.
mLogger.warn("Line: " + (row - 1) + ": Could not parse value", pe);
continue;
}
try {
yValue = Constants.NUMBER_FORMAT.parse(yRowIterator.next());
} catch (ParseException e) {
} catch (ParseException pe) {
mLogger.warn("Line: " + row + ": Could not parse value", pe);
continue;
}
Point2DDouble newPoint = new Point2DDouble(xValue.doubleValue(), yValue.doubleValue());
......@@ -82,73 +91,6 @@ public class CsvDotParser extends CsvParseAlgorithm<PointListContainer<PointList
public PointListContainer<PointList> parseAsVerticalDataSets(final List<? extends List<String>> csvData) {
Objects.requireNonNull(csvData);
if (true) {
throw new UnsupportedOperationException("Vertical parsing is currently not supported");
}
int row = 0;
PointListContainer<PointList> container = new SimplePointListContainerImpl();
if (csvData.isEmpty()) {
return container;
}
// Iterate over the first row in order to get the headers
int col = 0;
for (String header : csvData.get(0)) {
if (col % 2 == 0) {
PointList pointList = new SimplePointListImpl();
pointList.setName(header);
container.pushBack(pointList);
}
col++;
}
row++;
// Continue as long as there is at least one further rows left
while (csvData.size() >= row + 1) {
List<String> fields = csvData.get(row);
Iterator<String> fieldIterator = fields.iterator();
col = -1;
while (fieldIterator.hasNext()) {
String xRaw = fieldIterator.next();
String yRaw;
col++;
if (!fieldIterator.hasNext()) {
break;
}
yRaw = fieldIterator.next();
Number xValue;
Number yValue;
try {
xValue = Constants.NUMBER_FORMAT.parse(xRaw);
yValue = Constants.NUMBER_FORMAT.parse(yRaw);
} catch (ParseException e) {
col++;
continue;
}
Point2DDouble point = new Point2DDouble(xValue.doubleValue(), yValue.doubleValue());
addPointToPointListList(container, col / 2, point);
col++;
}
row++;
}
// TODO First add points to PointList, then add PointList to PointListContainer, so that there is no need for a calculateExtrema call
container.calculateExtrema();
return container;
}
}
......@@ -2,15 +2,11 @@ package de.tudresden.inf.mci.brailleplot.csvparser;
import de.tudresden.inf.mci.brailleplot.datacontainers.PointList;
import de.tudresden.inf.mci.brailleplot.datacontainers.PointListContainer;
import de.tudresden.inf.mci.brailleplot.datacontainers.SimplePointListImpl;
import de.tudresden.inf.mci.brailleplot.point.Point2DDouble;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
/**
* An algorithm for parsing CSV data. Contains implementations for two
......@@ -39,42 +35,6 @@ public abstract class CsvParseAlgorithm<T extends PointListContainer<PointList>>
*/
public abstract T parseAsVerticalDataSets(List<? extends List<String>> csvData);
/**
* Adds a {@link Point2DDouble} to a {@link PointList} in a {@link PointListContainer}{@literal <}{@link PointList}{@literal >},
* specified by {@code listIndex}. Adds more {@link PointList PointLists} if
* needed.
* @param container The {@link PointListContainer}{@literal <}{@link PointList}{@literal >} to which the point shall be added
* @param index The index of the list to which the point shall be added
* @param point The {@link Point2DDouble} which shall be added
*/
protected void addPointToPointListList(final PointListContainer<PointList> container, final int index, final Point2DDouble point) {
Objects.requireNonNull(container);
Objects.requireNonNull(point);
// TODO: Check if this actually works --> does not work (ConcurrentModificationException)
if (true) {
throw new UnsupportedOperationException();
}
int currentIdx = 0;
int listsToAddCount = index - container.getSize();
Iterator<PointList> it = container.iterator();
// Add extra intermediate lists if required
if (listsToAddCount > 0) {
for (int i = 0; i < listsToAddCount; i++) {
container.pushBack(new SimplePointListImpl());
}
}
// Add the element itself
for (; currentIdx < index; currentIdx++) {
it.next();
}
it.next().pushBack(point);
}
/**
* Transpose CSV data (List of Lists) as if it were a matrix.
* @param csvData CSV as List of Lists&lt;T&gt;
......
......@@ -18,83 +18,6 @@ import java.util.Objects;
*/
public class CsvXAlignedCategoriesParser extends CsvParseAlgorithm<CategoricalPointListContainer<PointList>> {
/*
@Override
public CategoricalPointListContainer<PointList> parseAsHorizontalDataSets(final List<? extends List<String>> csvData) {
Objects.requireNonNull(csvData);
if (true) {
throw new UnsupportedOperationException("Horizontal parsing is currently not supported");
}
CategoricalPointListContainer<PointList> container = new SimpleCategoricalPointListContainerImpl();
Iterator<? extends List<String>> rowIterator = csvData.iterator();
if (!rowIterator.hasNext()) {
return container;
}
Iterator<String> lineIterator = rowIterator.next().iterator();
// Move the iterator to the first category name
if (!lineIterator.hasNext()) {
return container;
}
lineIterator.next();
if (!lineIterator.hasNext()) {
return container;
}
// Store all categories
List<String> categories = new LinkedList<>();
while (lineIterator.hasNext()) {
categories.add(lineIterator.next());
}
Iterator<String> categoriesIt = categories.iterator();
// Store each row's data set
while (rowIterator.hasNext()) {
lineIterator = rowIterator.next().iterator();
// Create a PointList with the title of the data set
if (!lineIterator.hasNext()) {
continue;
}
String category = categoriesIt.next();
PointList pointList = new SimplePointListImpl(category);
container.pushBack(pointList);
// Add all the points
int colPosition = 0;
while (lineIterator.hasNext()) {
if (colPosition >= container.getSize()) {
break;
}
// Find out the mY value
Number yValue;
try {
yValue = Constants.NUMBER_FORMAT.parse(lineIterator.next());
} catch (ParseException e) {
colPosition++;
continue;
}
// Add the new point
Point2DDouble newPoint = new Point2DDouble(colPosition, yValue.doubleValue());
pointList.pushBack(newPoint);
colPosition++;
}
}
// TODO First add points to PointList, then add PointList to PointListContainer, so that there is no need for a calculateExtrema call
container.calculateExtrema();
return container;
}
*/
@Override
public CategoricalPointListContainer<PointList> parseAsHorizontalDataSets(final List<? extends List<String>> csvData) {
Objects.requireNonNull(csvData);
......@@ -154,5 +77,4 @@ public class CsvXAlignedCategoriesParser extends CsvParseAlgorithm<CategoricalPo
}
return container;
}
}
......@@ -18,92 +18,6 @@ import java.util.Objects;
*/
public class CsvXAlignedParser extends CsvParseAlgorithm<PointListContainer<PointList>> {
/*
@Override
public PointListContainer<PointList> parseAsHorizontalDataSets(final List<? extends List<String>> csvData) {
Objects.requireNonNull(csvData);
if (true) {
throw new UnsupportedOperationException("Horizontal parsing is currently not supported");
}
PointListContainer<PointList> container = new SimplePointListContainerImpl();
List<Number> xValues = new ArrayList<>();
Iterator<? extends List<String>> rowIterator = csvData.iterator();
if (!rowIterator.hasNext()) {
return container;
}
Iterator<String> lineIterator = rowIterator.next().iterator();
// Move the iterator to the mX value
if (!lineIterator.hasNext()) {
return container;
}
lineIterator.next();
if (!lineIterator.hasNext()) {
return container;
}
// Store all mX values, if one is not specified store NaN
while (lineIterator.hasNext()) {
Number xValue;
try {
xValue = Constants.NUMBER_FORMAT.parse(lineIterator.next());
} catch (ParseException e) {
xValue = Double.NaN;
}
xValues.add(xValue);
}
// Store each row's data set
while (rowIterator.hasNext()) {
lineIterator = rowIterator.next().iterator();
// Create a PointList with the title of the data set
if (!lineIterator.hasNext()) {
continue;
}
PointList pointList = new SimplePointListImpl();
pointList.setName(lineIterator.next());
container.pushBack(pointList);
// Add all the points
int colPosition = 0;
while (lineIterator.hasNext()) {
if (colPosition >= xValues.size()) {
break;
}
Number xValue = xValues.get(colPosition);
if (xValue.equals(Double.NaN)) {
lineIterator.next();
colPosition++;
continue;
}
// Find out the mY value
Number yValue;
try {
yValue = Constants.NUMBER_FORMAT.parse(lineIterator.next());
} catch (ParseException e) {
colPosition++;
continue;
}
// Add the new point
Point2DDouble newPoint = new Point2DDouble(xValue.doubleValue(), yValue.doubleValue());
pointList.pushBack(newPoint);
colPosition++;
}
}
// TODO First add points to PointList, then add PointList to PointListContainer, so that there is no need for a calculateExtrema call
container.calculateExtrema();
return container;
}
*/
@Override
public PointListContainer<PointList> parseAsHorizontalDataSets(final List<? extends List<String>> csvData) {
Objects.requireNonNull(csvData);
......@@ -114,9 +28,7 @@ public class CsvXAlignedParser extends CsvParseAlgorithm<PointListContainer<Poin
}
@Override
/**
* This method has been implemented from scratch, as there is no documentation about the structure of the CSV files whatsoever.
*/
// This method has been implemented from scratch, as there is no documentation about the structure of the CSV files whatsoever.
public PointListContainer<PointList> parseAsVerticalDataSets(final List<? extends List<String>> csvData) {
Objects.requireNonNull(csvData);
......@@ -153,5 +65,4 @@ public class CsvXAlignedParser extends CsvParseAlgorithm<PointListContainer<Poin
}
return container;
}
}
/**
* Package for parsing algorithms for CSV files.
* TODO refactor parser ({@link de.tudresden.inf.mci.brailleplot.csvparser.CsvXAlignedParser}, {@link de.tudresden.inf.mci.brailleplot.csvparser.CsvXAlignedCategoriesParser}, {@link de.tudresden.inf.mci.brailleplot.csvparser.CsvDotParser}) classes. Lots of blocks are copied with small modifications.
*/
package de.tudresden.inf.mci.brailleplot.csvparser;
......@@ -102,7 +102,6 @@ public class SimpleMatrixDataImpl<T> extends AbstractPrintableData implements Ma
return sb.toString();
}
// TODO: Remove, once svgexporter is implemented
public final String toBoolString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < getRowCount(); i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment