-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
295 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>snippets</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>edu.aalto.emn</groupId> | ||
<artifactId>snippets</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<description>Project for analyzing bus schedule data</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.beust</groupId> | ||
<artifactId>jcommander</artifactId> | ||
<version>1.30</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.aalto.emn; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Bus { | ||
|
||
private Map<String, BusStop> stops; // time - stop | ||
private int route; | ||
|
||
public Bus() { | ||
this.stops = new HashMap<String, BusStop>(); | ||
} | ||
|
||
public void setRoute(int route) { | ||
this.route = route; | ||
} | ||
|
||
public void addStop(String time, BusStop stop) { | ||
this.stops.put(time, stop); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package edu.aalto.emn; | ||
|
||
import org.xml.sax.Attributes; | ||
|
||
|
||
public class BusStop { | ||
private String id; | ||
private String name; | ||
private String x; | ||
private String y; | ||
|
||
public BusStop() { | ||
|
||
} | ||
|
||
public BusStop(Attributes atts) { | ||
String name = atts.getValue("Name"); | ||
String id = atts.getValue("StationId"); | ||
String x = atts.getValue("X"); | ||
String y = atts.getValue("Y"); | ||
|
||
if(name != null) { | ||
this.setName(name); | ||
} | ||
|
||
if(id !=null ) { | ||
this.setId(id); | ||
} | ||
|
||
if(x !=null) { | ||
this.setX(x); | ||
} | ||
|
||
if(y !=null) { | ||
this.setY(y); | ||
} | ||
} | ||
|
||
public BusStop(String id, String name, String x, String y) { | ||
this.setId(id); | ||
this.setName(name); | ||
this.setX(x); | ||
this.setY(y); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getX() { | ||
return x; | ||
} | ||
|
||
public void setX(String x) { | ||
this.x = x; | ||
} | ||
|
||
public String getY() { | ||
return y; | ||
} | ||
|
||
public void setY(String y) { | ||
this.y = y; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package edu.aalto.emn; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Stack; | ||
|
||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
public class DBHandler extends DefaultHandler { | ||
private Map<String, BusStop> stops; | ||
private List<Bus> buses; | ||
private int route; | ||
|
||
private Stack<String> elementStack = new Stack<String>(); | ||
private Stack<Object> objectStack = new Stack<Object>(); | ||
|
||
public DBHandler(int route) { | ||
this.route = route; | ||
this.stops = new HashMap(); | ||
this.buses = new ArrayList<Bus>(); | ||
} | ||
|
||
public List<Bus> getBuses() { | ||
return this.buses; | ||
} | ||
|
||
public boolean isReal(Attributes atts) { | ||
String type = atts.getValue("type"); | ||
String isVirtual = atts.getValue("isVirtual"); | ||
|
||
if(type == null && isVirtual == null) { | ||
return true; | ||
} | ||
|
||
return (type != null && "0".equals(type)) || (isVirtual != null && "false".equals(isVirtual)); | ||
} | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { | ||
|
||
this.elementStack.push(qName); | ||
|
||
if ("station".equals(qName.toLowerCase())) { | ||
if(isReal(attributes)) { | ||
BusStop stop = new BusStop(attributes); | ||
this.objectStack.push(stop); | ||
this.stops.put(stop.getId(), stop); | ||
} else { | ||
this.elementStack.pop(); | ||
} | ||
} else if ("service".equals(qName.toLowerCase())) { | ||
Bus bus = new Bus(); | ||
this.objectStack.push(bus); | ||
} | ||
} | ||
|
||
public void endElement(String uri, String localName, String qName) throws SAXException { | ||
|
||
this.elementStack.pop(); | ||
String qNameLow = qName.toLowerCase(); | ||
|
||
if ("station".equals(qNameLow) || "service".equals(qNameLow)) { | ||
Object object = this.objectStack.pop(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package edu.aalto.emn; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
|
||
import javax.xml.parsers.SAXParser; | ||
import javax.xml.parsers.SAXParserFactory; | ||
|
||
import com.beust.jcommander.Parameter; | ||
|
||
public class SnippetMain { | ||
|
||
@Parameter(names = { "-route" }, description = "Route number") | ||
private static Integer route = 23; | ||
|
||
@Parameter(names = "-xml", description = "Path to XML database dump", required=true) | ||
private static String path; | ||
|
||
public static void main(String[] args) { | ||
File xmlFile = new File(args[0]); | ||
|
||
SAXParserFactory factory = SAXParserFactory.newInstance(); | ||
try { | ||
InputStream xmlInput = new FileInputStream(args[0]); | ||
|
||
SAXParser saxParser = factory.newSAXParser(); | ||
DBHandler handler = new DBHandler(route); | ||
saxParser.parse(xmlInput, handler); | ||
|
||
for(Bus bus : handler.getBuses()){ | ||
// System.out.println(bus); | ||
} | ||
System.out.println("Done"); | ||
} catch (Throwable err) { | ||
err.printStackTrace (); | ||
} | ||
} | ||
|
||
} |