Skip to content

Commit

Permalink
CTX parser from Skywave
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Jun 21, 2012
1 parent 7527f1a commit 18ab411
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.opentripplanner.common;

import java.util.ArrayList;
import java.util.HashMap;

/**
* CTX parser for receiving Dutch realtime updates
*
* @author skywave
*/
public class CTX {

public ArrayList<HashMap<String, String>> rows = new ArrayList<HashMap<String, String>>();

public String subscription;

public String timestamp;

public String type;

public CTX(String ctx) {
String[] lines = ctx.split("\r\n");
String[] labels = null;
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (line.length() > 0) {
if (line.charAt(0) == '\\') {
if (line.charAt(1) == 'G') {
String[] header = line.split("\\|");
subscription = header[2];
} else if (line.charAt(1) == 'T') {
String[] table = line.split("\\|");
type = table[1];
} else if (line.charAt(1) == 'L') {
labels = line.substring(2).split("\\|");
}
} else {
HashMap<String, String> row = new HashMap<String, String>();
String[] values = line.split("\\|");
for (int j = 0; j < values.length; j++) {
if (values[j] == "\0") {
values[j] = null;
}
row.put(labels[j], values[j]);
}
rows.add(row);
}
}
}
}
}

0 comments on commit 18ab411

Please sign in to comment.