Skip to content

Commit

Permalink
Merge pull request #34 from xposionn/optimizations
Browse files Browse the repository at this point in the history
Optimized code and changed functions to private/package friendly if p…
  • Loading branch information
Liadc authored Dec 4, 2018
2 parents 3b171d7 + 8a494b8 commit c07dbe3
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Algorithms/MultiCSV.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void createProject(String folderName) {
* @param file a specific file in a folder.
* @param project the GIS project we add the layers to.
*/
static void addTree(File file,GIS_project project) {
private static void addTree(File file, GIS_project project) {
File[] children = file.listFiles(); //all files inside directory
if (children != null) {
for (File child : children) {
Expand Down
8 changes: 3 additions & 5 deletions src/Algorithms/TimeChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public static long stringUTCtoLong(String dateInString){
try {
dateInString = dateInString.replaceAll(" ", "T");
dateInString += 'Z';
date = (Date)formatter.parse(dateInString);
date = formatter.parse(dateInString);
} catch (ParseException e) {
e.printStackTrace();
}
long mills = date.getTime();
return mills;
return date.getTime();
}

/**
Expand All @@ -37,8 +36,7 @@ public static long stringUTCtoLong(String dateInString){
*/
public static String longtoUTC(long time){

String out = Instant.ofEpochMilli(time).atOffset(ZoneOffset.UTC).toString(); //from long to String output: dateThourZ
return out;
return Instant.ofEpochMilli(time).atOffset(ZoneOffset.UTC).toString();
}

}
2 changes: 1 addition & 1 deletion src/File_format/Csv2Layer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static GIS_layer csv2Layer(String fileName) { //fileName is the full path
e.printStackTrace();
}
TableLayer layer = new TableLayer();
GIS_layer testlayer = layer.TableLayer(csvTable, csv.getName());
GIS_layer testlayer = layer.tableLayer(csvTable, csv.getName());
return testlayer;
}
}
4 changes: 2 additions & 2 deletions src/File_format/Csv2kml.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Csv2kml {
* This method will transform a CSV file into CsvTable (as in arrayList) to a GIS_layer, and then to KML file to work with Google Earth.
* @param fileName fileName of the CSV file to transform into KML file.
*/
public static void makeKmlFile(String fileName) {
static void makeKmlFile(String fileName) {
String path = System.getProperty("user.dir")+ File.separator;
File csv = new File(path+File.separator+"dataExamples"+File.separator+fileName);
CsvTable csvTable = null;
Expand All @@ -24,7 +24,7 @@ public static void makeKmlFile(String fileName) {
e.printStackTrace();
}
TableLayer layer = new TableLayer();
GIS_layer testlayer = layer.TableLayer(csvTable, csv.getName());
GIS_layer testlayer = layer.tableLayer(csvTable, csv.getName());
testlayer.toKml();
}
}
8 changes: 4 additions & 4 deletions src/File_format/CsvTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class CsvTable {

ArrayList<String[]> csvTable;
private ArrayList<String[]> csvTable;

/**
* This method will return the header of the csv table, in a string[] array.
Expand All @@ -26,7 +26,7 @@ public String[] getHeader() {

/**
* Override toString method.
* @return
* @return String of the csv.
*/
@Override
public String toString() {
Expand All @@ -37,8 +37,8 @@ public String toString() {

/**
* This constructor will get a CSV file and will try to read it and construct a csvTable object from it.
* @param csv
* @throws IOException
* @param csv the csv File
* @throws IOException exception in buffers.
*/
public CsvTable(File csv) throws IOException {
csvTable = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions src/File_format/TableLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TableLayer {
* @param fileName the file name of the Csv table, it will be used to update the GIS layer META DATA with this name.
* @return GIS_layer, completed layer with all relevant variables.
*/
public GIS_layer TableLayer(CsvTable csvTable, String fileName){
GIS_layer tableLayer(CsvTable csvTable, String fileName){

GIS_layer layer = new GIS_layer_obj();
Iterator<String []> iterator = csvTable.iterator();
Expand All @@ -44,7 +44,7 @@ public GIS_layer TableLayer(CsvTable csvTable, String fileName){
} else if (header[i].equals("SSID") || header[i].equals("Name")) { //name
nameIndex = i;
} else if (header[i].equals("Color")) {
colorIndex = i;
colorIndex = i; //will be used later in assignments.
} else if (header[i].equals("FirstSeen") || header[i].equals("Timestamp")) {
timeIndex = i;
} else if (header[i].equals("MAC")) {
Expand Down
4 changes: 2 additions & 2 deletions src/GIS/GIS_element_obj.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* color, string, timing...
*/
public class GIS_element_obj implements GIS_element {
Geom_element geom;
Meta_data metaData;
private Geom_element geom;
private Meta_data metaData;


/**
Expand Down
14 changes: 6 additions & 8 deletions src/GIS/GIS_layer_obj.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package GIS;

import Algorithms.TimeChange;
import Geom.Point3D;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.security.spec.AlgorithmParameterSpec;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -16,7 +16,7 @@
*/
public class GIS_layer_obj extends HashSet<GIS_element> implements GIS_layer {

Meta_data layerMeta;
private Meta_data layerMeta;

/**
* Getter method for the layer meta data.
Expand Down Expand Up @@ -95,16 +95,14 @@ public String toKmlForProject() {
//first two lines is irrelevant for the google format KML.

String kmlContent = "<Folder>\n<name>"+layerMeta.getName()+"</name>\n";
Iterator<GIS_element> it = this.iterator();
while(it.hasNext()) {
GIS_element elem = it.next();
for (GIS_element elem : this) {
Point3D point = (Point3D) elem.getGeom();
kmlContent += "<Placemark>\n" +
"<name>" + elem.getData().getName() + "</name>\n" +
"<description>" + elem.getData().allInfo() + "</description>\n" +
"<styleUrl>"+ elem.getData().getStyleUrlColor()+"</styleUrl>\n" +
"<TimeStamp><when>"+ Algorithms.TimeChange.longtoUTC(elem.getData().getUTC())+"</when></TimeStamp>\n"+
"<Point>\n"+
"<styleUrl>" + elem.getData().getStyleUrlColor() + "</styleUrl>\n" +
"<TimeStamp><when>" + TimeChange.longtoUTC(elem.getData().getUTC()) + "</when></TimeStamp>\n" +
"<Point>\n" +
"<coordinates>" + point.y() + "," + point.x() + ",0 </coordinates>\n" + //0 at Z is relative to ground height
"</Point>\n" +
"</Placemark>\n";
Expand Down
7 changes: 2 additions & 5 deletions src/GIS/GIS_project_obj.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class GIS_project_obj extends HashSet<GIS_layer> implements GIS_project {

Meta_data projectMeta;
private Meta_data projectMeta;

/**
* Constructor for the GIS_project. takes projectName as string to create the project with current system time in meta.
Expand All @@ -34,7 +34,6 @@ public Meta_data get_Meta_data() {
* This method will transform the current GIS_project (the current HashMap of GIS_Layers) into one KML file.
* It will include a complete code which can be run through Google Earth application.
* The method will return the filename of the KML output file as string.
* @return String, the filename of the KML output file.
* @param fileNameForNewKML String, the filename requested as the name of the file output.
*/
public void toKml(String fileNameForNewKML) {
Expand All @@ -56,9 +55,7 @@ public void toKml(String fileNameForNewKML) {
try {
FileWriter fw = new FileWriter(fileNameForNewKML);
BufferedWriter bw = new BufferedWriter(fw);
Iterator<GIS_layer> iterator = this.iterator();
while (iterator.hasNext()) {
GIS_layer layer = iterator.next();
for (GIS_layer layer : this) {
String kmlLayer = layer.toKmlForProject();
kmlContent.add(kmlLayer);
}
Expand Down
18 changes: 9 additions & 9 deletions src/GIS/Meta_data_obj.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ public Meta_data_obj(String name, long UTCtimeLONG, String type, double speed, d
*/
public String allInfo(){ //name is also handled separately, as a placemark name.
StringBuilder info = new StringBuilder();
info.append("Name: <b>" + this.name +"</b><br/>");
info.append("Timestamp (UTC): <b>" + this.UTCtime +"</b><br/>");
info.append("Date: <b>" + Algorithms.TimeChange.longtoUTC(this.UTCtime).replaceAll("[T,Z]"," ")+"</b><br/>");
info.append("Name: <b>").append(this.name).append("</b><br/>");
info.append("Timestamp (UTC): <b>").append(this.UTCtime).append("</b><br/>");
info.append("Date: <b>").append(Algorithms.TimeChange.longtoUTC(this.UTCtime).replaceAll("[T,Z]", " ")).append("</b><br/>");
if(wifiPointEx2DATA!=null){
info.append("BSSID: <b>" + wifiPointEx2DATA[0] + "</b><br/>");
info.append("Capabilities: <b>" + wifiPointEx2DATA[1] + "</b><br/>");
info.append("AccuracyMeters: <b>" + wifiPointEx2DATA[2] + "</b><br/>");
info.append("BSSID: <b>").append(wifiPointEx2DATA[0]).append("</b><br/>");
info.append("Capabilities: <b>").append(wifiPointEx2DATA[1]).append("</b><br/>");
info.append("AccuracyMeters: <b>").append(wifiPointEx2DATA[2]).append("</b><br/>");
}
if(this.color!=null)
info.append("Color in HEX: <b>" + this.color +"</b><br/>");
info.append("Color in HEX: <b>").append(this.color).append("</b><br/>");
if(this.type != null)
if (this.type.equals("P"))
info.append("Type: Player<br/>");
else if (this.type.equals("F"))
info.append("Type: Fruit<br/>");
if (this.speed != null)
info.append("Speed: " + this.speed +"<br/>");
info.append("Speed: ").append(this.speed).append("<br/>");
if(this.radius != null)
info.append("Eating Radius: " + radius +"<br/>");
info.append("Eating Radius: ").append(radius).append("<br/>");

return info.toString();
}
Expand Down

0 comments on commit c07dbe3

Please sign in to comment.