Skip to content

Commit

Permalink
Make proper split between long and short name
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 24, 2024
1 parent d3c2137 commit e637437
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -55,28 +54,28 @@ public class GtfsMergerMain {
* Generic Arguments
****/

private static CommandLineParser _parser = new PosixParser();
private static final CommandLineParser _parser = new PosixParser();

private Options _options = new Options();
private final Options options = new Options();

/**
* Mapping from GTFS file name to the entity type handled by that class.
*/
private Map<String, Class<?>> _entityClassesByFilename = new HashMap<String, Class<?>>();
private final Map<String, Class<?>> _entityClassesByFilename = new HashMap<>();

/**
* If we ever need to register a custom option handler for a specific entity
* type, we would do it here.
*/
private Map<Class<?>, OptionHandler> _optionHandlersByEntityClass = new HashMap<Class<?>, OptionHandler>();
private final Map<Class<?>, OptionHandler> _optionHandlersByEntityClass = new HashMap<>();

public static void main(String[] args) throws IOException {
GtfsMergerMain m = new GtfsMergerMain();
m.run(args);
}

public GtfsMergerMain() {
buildOptions(_options);
buildOptions(options);
mapEntityClassesToFilenames();
}

Expand All @@ -92,12 +91,9 @@ public void run(String[] args) throws IOException {
}

try {
CommandLine cli = _parser.parse(_options, args, true);
runApplication(cli, args);
} catch (MissingOptionException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
} catch (MissingArgumentException ex) {
CommandLine cli = _parser.parse(options, args, true);
runApplication(cli);
} catch (MissingOptionException | MissingArgumentException ex) {
System.err.println("Missing argument: " + ex.getMessage());
printHelp();
} catch (UnrecognizedOptionException ex) {
Expand Down Expand Up @@ -128,11 +124,11 @@ protected void buildOptions(Options options) {
"error on dropped duplicates");
}

protected void printHelp(PrintWriter out, Options options) throws IOException {
protected void printHelp() throws IOException {

InputStream is = getClass().getResourceAsStream("usage.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
String line;

while ((line = reader.readLine()) != null) {
System.err.println(line);
Expand All @@ -141,7 +137,7 @@ protected void printHelp(PrintWriter out, Options options) throws IOException {
reader.close();
}

protected void runApplication(CommandLine cli, String[] originalArgs)
protected void runApplication(CommandLine cli)
throws Exception {

String[] args = cli.getArgs();
Expand All @@ -164,14 +160,6 @@ protected void runApplication(CommandLine cli, String[] originalArgs)
merger.run(inputPaths, outputPath);
}

/*****************************************************************************
* Protected Methods
****************************************************************************/

protected void printHelp() throws IOException {
printHelp(new PrintWriter(System.err, true), _options);
}

private boolean needsHelp(String[] args) {
for (String arg : args) {
if (arg.equals("-h") || arg.equals("--help") || arg.equals("-help"))
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-gtfs-transformer-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,29 @@ public void run(String[] args) throws IOException {

protected void buildOptions(Options options) {

options.addOption(ARG_AGENCY_ID, true, "agency id");

options.addOption(ARG_MODIFICATIONS, true, "data modifications");
options.addOption(ARG_TRANSFORM, true, "data transformation");
options.addOption(ARG_REFERENCE, true, "reference GTFS to merge from");
options.addOption(ARG_STOP_MAPPING, true, "Stop Name Mapping File");
options.addOption(ARG_IGNORE_STOPS, true, "List of stops names to ignore");
options.addOption(ARG_REGEX_FILE, true, "Regex pattern mapping file");
options.addOption(ARG_CONTROL_FILE, true, "file to remap stop ids and other properties");
options.addOption(ARG_CONCURRENCY_FILE, true, "file to remap wrong way concurrencies");
options.addOption(ARG_OMNY_ROUTES_FILE, true, "file to add OMNY enabled routes to GTFS");
options.addOption(ARG_OMNY_STOPS_FILE, true, "file to add OMNY enabled stops to GTFS");
options.addOption(ARG_VERIFY_ROUTES_FILE, true, "file to check route names vs route ids in GTFS");

options.addOption(ARG_LOCAL_VS_EXPRESS, false,
options.addOption(null, ARG_AGENCY_ID, true, "agency id");

options.addOption(null, ARG_MODIFICATIONS, true, "data modifications");
options.addOption(null, ARG_TRANSFORM, true, "data transformation");
options.addOption(null, ARG_REFERENCE, true, "reference GTFS to merge from");
options.addOption(null, ARG_STOP_MAPPING, true, "Stop Name Mapping File");
options.addOption(null, ARG_IGNORE_STOPS, true, "List of stops names to ignore");
options.addOption(null, ARG_REGEX_FILE, true, "Regex pattern mapping file");
options.addOption(null, ARG_CONTROL_FILE, true, "file to remap stop ids and other properties");
options.addOption(null, ARG_CONCURRENCY_FILE, true, "file to remap wrong way concurrencies");
options.addOption(null, ARG_OMNY_ROUTES_FILE, true, "file to add OMNY enabled routes to GTFS");
options.addOption(null, ARG_OMNY_STOPS_FILE, true, "file to add OMNY enabled stops to GTFS");
options.addOption(null, ARG_VERIFY_ROUTES_FILE, true, "file to check route names vs route ids in GTFS");

options.addOption(null, ARG_LOCAL_VS_EXPRESS, false,
"add additional local vs express fields");
options.addOption(ARG_CHECK_STOP_TIMES, false,
options.addOption(null, ARG_CHECK_STOP_TIMES, false,
"check stop times are in order");
options.addOption(ARG_REMOVE_REPEATED_STOP_TIMES, false,
options.addOption(null, ARG_REMOVE_REPEATED_STOP_TIMES, false,
"remove repeated stop times");
options.addOption(ARG_REMOVE_DUPLICATE_TRIPS, false,
options.addOption(null, ARG_REMOVE_DUPLICATE_TRIPS, false,
"remove duplicate trips");
options.addOption(ARG_OVERWRITE_DUPLICATES, false,
options.addOption(null, ARG_OVERWRITE_DUPLICATES, false,
"overwrite duplicate elements");
}

Expand Down Expand Up @@ -210,7 +210,7 @@ protected void runApplication(CommandLine cli, String[] originalArgs)

for (Option option : options) {

String name = option.getOpt();
String name = option.getLongOpt();

if (name.equals(ARG_REMOVE_REPEATED_STOP_TIMES))
configureRemoveRepeatedStopTimes(transformer);
Expand Down Expand Up @@ -281,11 +281,11 @@ private Option[] getOptionsInCommandLineOrder(CommandLine cli,
String[] originalArgs) {

Option[] options = cli.getOptions();
List<Ordered<Option>> orderedOptions = new ArrayList<Ordered<Option>>();
List<Ordered<Option>> orderedOptions = new ArrayList<>();

for (Option option : options) {

String argName = option.getOpt();
String argName = option.getLongOpt();
int optionPosition = originalArgs.length;

for (int i = 0; i < originalArgs.length; i++) {
Expand All @@ -295,7 +295,7 @@ private Option[] getOptionsInCommandLineOrder(CommandLine cli,
}
}

orderedOptions.add(new Ordered<Option>(option, optionPosition));
orderedOptions.add(new Ordered<>(option, optionPosition));
}

Collections.sort(orderedOptions);
Expand Down

0 comments on commit e637437

Please sign in to comment.