public class StkCityDatabase extends Object
The following example shows how to query the city database for cities matching certain criteria:
StkCityDatabase db = new StkCityDatabase(dbDirectory, "stkCityDb");
// Create a query object and then populate it with the properties to query on.
// Regular expressions are used to query on strings.
StkCityDatabaseQuery query = new StkCityDatabaseQuery();
query.setCityName(Pattern.compile("Philadelphia"));
// only look in PA, because there's also a New Philadelphia in Ohio
query.setProvinceName(Pattern.compile("Pennsylvania"));
// Get the database entries matching the query and print out the Longitude and Latitude of each.
for (StkCityDatabaseEntry entry : db.getEntries(query)) {
System.out.format("%s: Longitude %f, Latitude %f%n", entry.getCityName(), entry.getLongitude(), entry.getLatitude());
}
Constructor and Description |
---|
StkCityDatabase(String directory,
String baseFileName)
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
ArrayList<String> |
getCentralBodies()
Gets the central bodies in the database.
|
ArrayList<String> |
getCityTypes()
Gets the types of cities in the database.
|
ArrayList<String> |
getCountries()
Gets the countries in the database.
|
ArrayList<StkCityDatabaseEntry> |
getEntries()
Gets all of the entries in the database.
|
ArrayList<StkCityDatabaseEntry> |
getEntries(StkCityDatabaseQuery query)
Gets all of the entries in the database matching a specified query.
|
GregorianDate |
getLastUpdateDate()
Gets the last update date reported in the Generic Database (.gd) file, or
GregorianDate.MinValue
if the file does not exist or does not contain a LastUpdate field. |
String |
getVersion()
Gets the version number reported in the Generic Database (.gd) file, or "Unknown" if
the file does not exist or does not contain a Version field.
|
public StkCityDatabase(@Nonnull String directory, @Nonnull String baseFileName)
directory
- The directory in which the city database is located.baseFileName
- The base filename (without extension) of the database within the directory.ArgumentNullException
- Thrown when directory
or baseFileName
is null
.public final String getVersion()
@Nonnull public final GregorianDate getLastUpdateDate()
GregorianDate.MinValue
if the file does not exist or does not contain a LastUpdate field.@Nonnull public final ArrayList<String> getCountries()
@Nonnull public final ArrayList<String> getCentralBodies()
@Nonnull public final ArrayList<String> getCityTypes()
@Nonnull public final ArrayList<StkCityDatabaseEntry> getEntries()
@Nonnull public final ArrayList<StkCityDatabaseEntry> getEntries(@Nullable StkCityDatabaseQuery query)
query
- The query that returned entries must match,
or null
to return all entries.InvalidDataException
- Thrown when a required data file was not found.