Skip to content
Snippets Groups Projects
Commit fcc30f3d authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

add Datastore module which will be the central storage for record

objects, edits to FileProcessor to store the processed records in the
DataStore object.
parent 74c9160f
No related branches found
No related tags found
No related merge requests found
package biotree;
import java.util.ArrayList;
import sort.GeneralCompare;
import sort.GeneralRange;
import sort.KDT;
/**
* Module for storing Record objects in a central place.
* @author Christopher W. Schankula
*
*/
public class DataStore {
public static KDT<Record> records;
public static void init(Record[] recs) {
GeneralCompare<Record> ax0 = (r0,r1) -> {
Record rec0 = (Record) r0;
Record rec1 = (Record) r1;
if (rec0.getYear() != rec1.getYear())
return rec0.getYear() - rec1.getYear();
else if (rec0.getMonth() != rec1.getMonth())
return rec0.getMonth() - rec1.getMonth();
else if (rec0.getDay() != rec1.getDay())
return rec0.getDay() - rec1.getDay();
else
return 0;
};
GeneralCompare<Record> ax1 = (r0,r1) -> ((Record) r0).getTaxonId() - ((Record) r1).getTaxonId();
GeneralCompare<Record> ax2 = (r0,r1) -> Float.compare(((Record) r0).getLatitude(), ((Record) r1).getLatitude());
GeneralCompare<Record> ax3 = (r0,r1) -> Float.compare(((Record) r0).getLongitude(), ((Record) r1).getLongitude());
ArrayList<GeneralCompare<Record>> axes = new ArrayList<GeneralCompare<Record>>(4);
axes.add(ax0);axes.add(ax1);axes.add(ax2);axes.add(ax3);
records = new KDT<Record>(axes, recs);
System.out.println("K:" + records.getK());
System.out.println("H:" + records.height());
System.out.println("S:" + records.size());
}
}
......@@ -3,6 +3,7 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner; // Testing ONLY
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -18,6 +19,7 @@ import java.util.regex.Pattern;
*/
public class FileProcessor {
private static String path = "src/occurrence.csv";
private static ArrayList<Record> al = new ArrayList<Record>(1000);
/**
* Gets the path string
......@@ -53,7 +55,7 @@ public class FileProcessor {
br.readLine(); // Reads Past Field Names
int i = 0;
while ((currentLine = br.readLine()) != null) {
while ((currentLine = br.readLine()) != null && i < 100) {
//System.out.println(currentLine); //Testing ONLY for checking one line at a time
i++;
System.out.println("Processed line " + i);
......@@ -61,6 +63,9 @@ public class FileProcessor {
//s.nextLine(); //Testing ONLY for checking one line at a time
}
//initialize the storage of records
DataStore.init(al.toArray(new Record[al.size()]));
s.close();//Testing ONLY
br.close();
fr.close();
......@@ -136,7 +141,7 @@ public class FileProcessor {
int errorCount=0; // TESTING ONLY
if (!matchEventId.group(10).equals("NA")) {
try{
rec = createRecord(Integer.parseInt(matchEventId.group(3)), matchEventId.group(1), BioTree.processRecord(matchEventId.group(10)), Integer.parseInt(matchEventId.group(2)), Float.parseFloat(matchEventId.group(7)), Float.parseFloat(matchEventId.group(8)), Integer.parseInt(matchEventId.group(4)), Integer.parseInt(matchEventId.group(5)), Integer.parseInt(matchEventId.group(6)));
al.add(createRecord(Integer.parseInt(matchEventId.group(3)), matchEventId.group(1), BioTree.processRecord(matchEventId.group(10)), Integer.parseInt(matchEventId.group(2)), Float.parseFloat(matchEventId.group(7)), Float.parseFloat(matchEventId.group(8)), Integer.parseInt(matchEventId.group(4)), Integer.parseInt(matchEventId.group(5)), Integer.parseInt(matchEventId.group(6))));
} catch(IOException e) {
System.out.println("Input Error:" + e);
} catch(NullPointerException e) {
......
package biotree;
public class Record {
public class Record implements Comparable<Record> {
private final int eventId;
private final String occurId;
private final int taxonId;
......@@ -109,4 +109,10 @@ public class Record {
return day;
}
@Override
public int compareTo(Record o) {
// TODO Auto-generated method stub
return 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment