-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
locations.geojson POC phase2: End-to-end partial support of json data #1810
base: master
Are you sure you want to change the base?
Changes from 23 commits
f8a966d
204f931
e7751f0
1131d7d
f027e9a
2eae957
ae500ef
acab716
138d550
e1ea3f1
435876e
75e8d80
1e9fac5
209d203
b82b39b
8bdab6d
6f82f03
77805f3
e3dbb2b
63d03e9
bffef74
c90bd7e
b794c3a
4badc74
2380dae
67504ab
3e6845c
2a423cc
86ea2c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,58 @@ | ||||||
package org.mobilitydata.gtfsvalidator.table; | ||||||
|
||||||
import java.util.List; | ||||||
import java.util.Optional; | ||||||
|
||||||
/** | ||||||
* This class is the parent of the containers holding table (csv) entities and containers holding | ||||||
* geojson entities | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [suggestion]: change this term to a more generic one:
Suggested change
|
||||||
* | ||||||
* @param <T> The entity for this container (e.g. GtfsCalendarDate or {@link GtfsGeojsonFeature} ) | ||||||
* @param <D> The descriptor for the table for the container (e.g. GtfsCalendarDateTableDescriptor | ||||||
* or {@link GtfsGeojsonFileDescriptor}) | ||||||
*/ | ||||||
public abstract class GtfsEntityContainer<T extends GtfsEntity, D extends GtfsFileDescriptor> { | ||||||
|
||||||
private final D descriptor; | ||||||
private final TableStatus tableStatus; | ||||||
|
||||||
public GtfsEntityContainer(D descriptor, TableStatus tableStatus) { | ||||||
this.tableStatus = tableStatus; | ||||||
this.descriptor = descriptor; | ||||||
} | ||||||
|
||||||
public TableStatus getTableStatus() { | ||||||
return tableStatus; | ||||||
} | ||||||
|
||||||
public D getDescriptor() { | ||||||
return descriptor; | ||||||
} | ||||||
|
||||||
public abstract Class<T> getEntityClass(); | ||||||
|
||||||
public int entityCount() { | ||||||
return getEntities().size(); | ||||||
} | ||||||
|
||||||
public abstract List<T> getEntities(); | ||||||
|
||||||
public abstract String gtfsFilename(); | ||||||
|
||||||
public abstract Optional<T> byTranslationKey(String recordId, String recordSubId); | ||||||
|
||||||
public boolean isMissingFile() { | ||||||
return tableStatus == TableStatus.MISSING_FILE; | ||||||
} | ||||||
|
||||||
public boolean isParsedSuccessfully() { | ||||||
switch (tableStatus) { | ||||||
case PARSABLE_HEADERS_AND_ROWS: | ||||||
return true; | ||||||
case MISSING_FILE: | ||||||
return !descriptor.isRequired(); | ||||||
default: | ||||||
return false; | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,20 +18,19 @@ | |||||
|
||||||
import com.google.common.base.Ascii; | ||||||
import java.util.*; | ||||||
import org.mobilitydata.gtfsvalidator.table.GtfsTableContainer.TableStatus; | ||||||
|
||||||
/** | ||||||
* Container for a whole parsed GTFS feed with all its tables. | ||||||
* | ||||||
* <p>The tables are kept as {@code GtfsTableContainer} instances. | ||||||
* <p>The tables are kept as {@code GtfsContainer} instances. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [doc]:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
*/ | ||||||
public class GtfsFeedContainer { | ||||||
private final Map<String, GtfsTableContainer<?>> tables = new HashMap<>(); | ||||||
private final Map<Class<? extends GtfsTableContainer>, GtfsTableContainer<?>> tablesByClass = | ||||||
private final Map<String, GtfsEntityContainer<?, ?>> tables = new HashMap<>(); | ||||||
private final Map<Class<? extends GtfsEntityContainer>, GtfsEntityContainer<?, ?>> tablesByClass = | ||||||
new HashMap<>(); | ||||||
|
||||||
public GtfsFeedContainer(List<GtfsTableContainer<?>> tableContainerList) { | ||||||
for (GtfsTableContainer<?> table : tableContainerList) { | ||||||
public GtfsFeedContainer(List<GtfsEntityContainer<?, ?>> tableContainerList) { | ||||||
for (GtfsEntityContainer<?, ?> table : tableContainerList) { | ||||||
tables.put(table.gtfsFilename(), table); | ||||||
tablesByClass.put(table.getClass(), table); | ||||||
} | ||||||
|
@@ -49,11 +48,12 @@ public GtfsFeedContainer(List<GtfsTableContainer<?>> tableContainerList) { | |||||
* @param filename file name, including ".txt" extension | ||||||
* @return GTFS table or empty if the table is not supported by schema | ||||||
*/ | ||||||
public Optional<GtfsTableContainer<?>> getTableForFilename(String filename) { | ||||||
return Optional.ofNullable(tables.getOrDefault(Ascii.toLowerCase(filename), null)); | ||||||
public <T extends GtfsEntityContainer<?, ?>> Optional<T> getTableForFilename(String filename) { | ||||||
return (Optional<T>) | ||||||
Optional.ofNullable(tables.getOrDefault(Ascii.toLowerCase(filename), null)); | ||||||
} | ||||||
|
||||||
public <T extends GtfsTableContainer<?>> T getTable(Class<T> clazz) { | ||||||
public <T extends GtfsEntityContainer<?, ?>> T getTable(Class<T> clazz) { | ||||||
return (T) tablesByClass.get(clazz); | ||||||
} | ||||||
|
||||||
|
@@ -65,21 +65,21 @@ public <T extends GtfsTableContainer<?>> T getTable(Class<T> clazz) { | |||||
* @return true if all files were successfully parsed, false otherwise | ||||||
*/ | ||||||
public boolean isParsedSuccessfully() { | ||||||
for (GtfsTableContainer<?> table : tables.values()) { | ||||||
for (GtfsEntityContainer<?, ?> table : tables.values()) { | ||||||
if (!table.isParsedSuccessfully()) { | ||||||
return false; | ||||||
} | ||||||
} | ||||||
return true; | ||||||
} | ||||||
|
||||||
public Collection<GtfsTableContainer<?>> getTables() { | ||||||
public Collection<GtfsEntityContainer<?, ?>> getTables() { | ||||||
return tables.values(); | ||||||
} | ||||||
|
||||||
public String tableTotalsText() { | ||||||
List<String> totalList = new ArrayList<>(); | ||||||
for (GtfsTableContainer<?> table : tables.values()) { | ||||||
for (GtfsEntityContainer<?, ?> table : tables.values()) { | ||||||
if (table.getTableStatus() == TableStatus.MISSING_FILE | ||||||
&& !table.getDescriptor().isRequired()) { | ||||||
continue; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion]: rename this class as
CsvFileLoader
and the parentFileLoader
. The loader for JSON files is already namedJsonFileLoader
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done