extract parseLineAndType()

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@789 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-09-25 11:58:35 +00:00
parent ed80d13ff9
commit 59f72323bc
9 changed files with 43 additions and 183 deletions

View file

@ -1735,6 +1735,42 @@ public abstract class AbstractHafasProvider implements NetworkProvider
throw new IllegalStateException("cannot normalize line " + line);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
// saved from RtProvider
private static final Pattern P_NORMALIZE_LINE_RUSSIA = Pattern.compile("(\\d{3}(BJ|FJ|IJ|MJ|NJ|OJ|TJ|SZ))");
protected final String parseLineAndType(final String lineAndType)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(lineAndType);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
if (type.length() == 0)
{
if (number.length() == 0)
return "?";
if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches())
return "?" + number;
// saved from RtProvider
// if (P_NORMALIZE_LINE_RUSSIA.matcher(number).matches())
// return 'R' + number;
}
else
{
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
}
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line#type " + lineAndType);
}
throw new IllegalStateException("cannot normalize line#type " + lineAndType);
}
private static final Pattern P_CONNECTION_ID = Pattern.compile("co=(C\\d+-\\d+)&");
protected static String extractConnectionId(final String link)

View file

@ -19,8 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -163,25 +161,10 @@ public class DsbProvider extends AbstractHafasProvider
return jsonGetStops(uri);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
@Override

View file

@ -19,8 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -139,25 +137,10 @@ public class LuProvider extends AbstractHafasProvider
return xmlMLcReq(constraint);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2).trim();
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
@Override

View file

@ -21,8 +21,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -170,38 +168,6 @@ public class OebbProvider extends AbstractHafasProvider
WALKSPEED_MAP.put(WalkSpeed.FAST, "85");
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
if (type.length() == 0)
{
if (number.length() == 0)
return "?";
if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches())
return "?" + number;
}
else
{
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
}
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
}
@Override
protected char normalizeType(final String type)
{

View file

@ -19,8 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -159,39 +157,10 @@ public class RtProvider extends AbstractHafasProvider
return jsonGetStops(uri);
}
private static final Pattern P_NORMALIZE_LINE_RUSSIA = Pattern.compile("(\\d{3}(BJ|FJ|IJ|MJ|NJ|OJ|TJ|SZ))");
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
if (type.length() == 0)
{
if (P_NORMALIZE_LINE_RUSSIA.matcher(number).matches())
return 'R' + number;
if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches())
return '?' + number;
if (number.length() == 0)
return "?";
}
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
@Override

View file

@ -19,8 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -155,25 +153,10 @@ public class SbbProvider extends AbstractHafasProvider
return jsonGetStops(uri);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
@Override

View file

@ -19,8 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -146,36 +144,10 @@ public class SncbProvider extends AbstractHafasProvider
return jsonGetStops(uri);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
if (type.length() == 0)
{
if (number.length() == 0)
return "?";
if (P_NORMALIZE_LINE_NUMBER.matcher(number).matches())
return "?" + number;
}
else
{
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
}
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
@Override

View file

@ -173,24 +173,9 @@ public class VbbProvider extends AbstractHafasProvider
return jsonGetStops(uri);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
}

View file

@ -19,8 +19,6 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
@ -163,25 +161,10 @@ public class ZvvProvider extends AbstractHafasProvider
return xmlMLcReq(constraint);
}
private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
@Override
protected String normalizeLine(final String line)
{
final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
if (m.matches())
{
final String number = m.group(1).replaceAll("\\s+", " ");
final String type = m.group(2);
final char normalizedType = normalizeType(type);
if (normalizedType != 0)
return normalizedType + number;
throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
}
throw new IllegalStateException("cannot normalize line " + line);
return parseLineAndType(line);
}
@Override