mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 16:20:34 +00:00
refactored normalizeLine to parseLine
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@788 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
5cbbd7f175
commit
ed80d13ff9
5 changed files with 41 additions and 25 deletions
|
@ -923,8 +923,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
if (category == null)
|
if (category == null)
|
||||||
category = shortCategory;
|
category = shortCategory;
|
||||||
|
|
||||||
final String lineStr = normalizeLine(category, name);
|
line = parseLine(category, name);
|
||||||
line = new Line(null, lineStr, lineColors(lineStr));
|
|
||||||
}
|
}
|
||||||
else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute"))
|
else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute"))
|
||||||
{
|
{
|
||||||
|
@ -1687,26 +1686,32 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
|
|
||||||
protected static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zßÄÅäáàâåéèêíìîÖöóòôÜüúùûØ/]+)[\\s-]*(.*)");
|
protected static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zßÄÅäáàâåéèêíìîÖöóòôÜüúùûØ/]+)[\\s-]*(.*)");
|
||||||
|
|
||||||
protected String normalizeLine(final String type, final String line)
|
protected Line parseLine(final String type, final String line)
|
||||||
{
|
{
|
||||||
final char normalizedType = normalizeType(type);
|
final char normalizedType = normalizeType(type);
|
||||||
|
|
||||||
if (normalizedType != 0)
|
if (normalizedType != 0)
|
||||||
{
|
{
|
||||||
|
final String lineStr;
|
||||||
|
|
||||||
if (line != null)
|
if (line != null)
|
||||||
{
|
{
|
||||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||||
final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line;
|
final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line;
|
||||||
|
|
||||||
return normalizedType + strippedLine;
|
lineStr = normalizedType + strippedLine;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Character.toString(normalizedType);
|
lineStr = Character.toString(normalizedType);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalStateException("cannot normalize type '" + type + "' line '" + line + "'");
|
return new Line(null, lineStr, lineColors(lineStr));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("cannot normalize type '" + type + "' line '" + line + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String normalizeLine(final String line)
|
protected String normalizeLine(final String line)
|
||||||
|
|
|
@ -235,7 +235,7 @@ public class InvgProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String lineType = mDepFine.group(3);
|
final String lineType = mDepFine.group(3);
|
||||||
|
|
||||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
final Line line = parseLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
||||||
|
|
||||||
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
||||||
|
|
||||||
|
@ -243,8 +243,8 @@ public class InvgProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, new Line(
|
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line,
|
||||||
null, line, line != null ? lineColors(line) : null), position, destinationId, destination, null, null);
|
position, destinationId, destination, null, null);
|
||||||
|
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
@ -282,28 +282,40 @@ public class InvgProvider extends AbstractHafasProvider
|
||||||
protected static final Pattern P_NORMALIZE_LINE_BUS_X = Pattern.compile("Bus\\s*X\\s*(\\d+)");
|
protected static final Pattern P_NORMALIZE_LINE_BUS_X = Pattern.compile("Bus\\s*X\\s*(\\d+)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String normalizeLine(final String type, final String line)
|
protected Line parseLine(final String type, final String line)
|
||||||
{
|
{
|
||||||
if ("1".equals(type))
|
if ("1".equals(type))
|
||||||
{
|
{
|
||||||
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
|
final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
|
||||||
if (mBus.matches())
|
if (mBus.matches())
|
||||||
return "B" + mBus.group(1);
|
{
|
||||||
|
final String lineStr = "B" + mBus.group(1);
|
||||||
|
return new Line(null, lineStr, lineColors(lineStr));
|
||||||
|
}
|
||||||
|
|
||||||
final Matcher mNachtbus = P_NORMALIZE_LINE_NACHTBUS.matcher(line);
|
final Matcher mNachtbus = P_NORMALIZE_LINE_NACHTBUS.matcher(line);
|
||||||
if (mNachtbus.matches())
|
if (mNachtbus.matches())
|
||||||
return "BN" + mNachtbus.group(1);
|
{
|
||||||
|
final String lineStr = "BN" + mNachtbus.group(1);
|
||||||
|
return new Line(null, lineStr, lineColors(lineStr));
|
||||||
|
}
|
||||||
|
|
||||||
final Matcher mBusS = P_NORMALIZE_LINE_BUS_S.matcher(line);
|
final Matcher mBusS = P_NORMALIZE_LINE_BUS_S.matcher(line);
|
||||||
if (mBusS.matches())
|
if (mBusS.matches())
|
||||||
return "BS" + mBusS.group(1);
|
{
|
||||||
|
final String lineStr = "BS" + mBusS.group(1);
|
||||||
|
return new Line(null, lineStr, lineColors(lineStr));
|
||||||
|
}
|
||||||
|
|
||||||
final Matcher mBusX = P_NORMALIZE_LINE_BUS_X.matcher(line);
|
final Matcher mBusX = P_NORMALIZE_LINE_BUS_X.matcher(line);
|
||||||
if (mBusX.matches())
|
if (mBusX.matches())
|
||||||
return "BX" + mBusX.group(1);
|
{
|
||||||
|
final String lineStr = "BX" + mBusX.group(1);
|
||||||
|
return new Line(null, lineStr, lineColors(lineStr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.normalizeLine(type, line);
|
return super.parseLine(type, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -257,7 +257,7 @@ public class SeptaProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String lineType = mDepFine.group(3);
|
final String lineType = mDepFine.group(3);
|
||||||
|
|
||||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
final Line line = parseLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
||||||
|
|
||||||
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
||||||
|
|
||||||
|
@ -265,8 +265,8 @@ public class SeptaProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, new Line(null,
|
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line,
|
||||||
line, line != null ? lineColors(line) : null), position, destinationId, destination, null, null);
|
position, destinationId, destination, null, null);
|
||||||
|
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class ShProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String lineType = mDepFine.group(2);
|
final String lineType = mDepFine.group(2);
|
||||||
|
|
||||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(3).trim()));
|
final Line line = parseLine(lineType, ParserUtils.resolveEntities(mDepFine.group(3).trim()));
|
||||||
|
|
||||||
final int destinationId = mDepFine.group(4) != null ? Integer.parseInt(mDepFine.group(4)) : 0;
|
final int destinationId = mDepFine.group(4) != null ? Integer.parseInt(mDepFine.group(4)) : 0;
|
||||||
|
|
||||||
|
@ -230,8 +230,7 @@ public class ShProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String position = mDepFine.group(6) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(6)) : null;
|
final String position = mDepFine.group(6) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(6)) : null;
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime.getTime(), null, new Line(null, line, line != null ? lineColors(line) : null),
|
final Departure dep = new Departure(plannedTime.getTime(), null, line, position, destinationId, destination, null, null);
|
||||||
position, destinationId, destination, null, null);
|
|
||||||
|
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
|
|
@ -264,7 +264,7 @@ public class VgsProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String lineType = mDepFine.group(3);
|
final String lineType = mDepFine.group(3);
|
||||||
|
|
||||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
final Line line = parseLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
||||||
|
|
||||||
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
||||||
|
|
||||||
|
@ -272,8 +272,8 @@ public class VgsProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, new Line(
|
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line,
|
||||||
null, line, line != null ? lineColors(line) : null), position, destinationId, destination, null, null);
|
position, destinationId, destination, null, null);
|
||||||
|
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue