WIP: Importer
This commit is contained in:
parent
97c326ab53
commit
484bd3a2c9
|
@ -0,0 +1,88 @@
|
|||
package Presenter.Import;
|
||||
|
||||
import Model.Arrangement;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||
*
|
||||
* @Author: Armin Wolf
|
||||
* @Email: a_wolf28@uni-muenster.de
|
||||
* @Date: 21.06.2017.
|
||||
*/
|
||||
public class DataImporter {
|
||||
|
||||
private String path;
|
||||
private InputStream inputStream;
|
||||
private Arrangement model;
|
||||
final String separator = " ";
|
||||
|
||||
public DataImporter(String path, Arrangement model) {
|
||||
this.path = path;
|
||||
this.model = model;
|
||||
try {
|
||||
inputStream = new FileInputStream(path);
|
||||
} catch (FileNotFoundException e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
// process the line.
|
||||
}
|
||||
br.close();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void parseLine(String line) {
|
||||
if (line.substring(0, 1) == "#") {
|
||||
return;
|
||||
} else if (isNumeric(line.substring(line.lastIndexOf(separator), line.length() - 1))) {
|
||||
String id = line.substring(0, line.indexOf(separator));
|
||||
Double x = Double.parseDouble(line.substring(line.indexOf(separator), line.lastIndexOf(separator)));
|
||||
Double y = Double.parseDouble(line.substring(line.lastIndexOf(separator), line.length()-1));
|
||||
System.out.println("ID: "+id+" x: "+x+"\t y: "+y);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str) {
|
||||
try {
|
||||
double d = Double.parseDouble(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
path = path;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public void setInputStream(InputStream inputStream) {
|
||||
this.inputStream = inputStream;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package Presenter.Import;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||
*
|
||||
* @Author: Armin Wolf
|
||||
* @Email: a_wolf28@uni-muenster.de
|
||||
* @Date: 21.06.2017.
|
||||
*/
|
||||
public class DataImporterTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DataImporter importer = new DataImporter("", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue