Class PersistenceJsonParser
- java.lang.Object
-
- org.openstreetmap.atlas.generator.tools.json.PersistenceJsonParser
-
public final class PersistenceJsonParser extends java.lang.ObjectDefine a JSON format for the RDD keys used by the spark job. This class provides methods for constructing the key as well as parsing data out of the key. The JSON format should follow this structure:{ "country": "USA-0-generated", "shard": "1-2-3", "metadata": { "scheme": "zz/", } }
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcreateJsonKey(java.lang.String country, java.lang.String shard, java.lang.String scheme)Create a JSON key with a given country and shard.static java.lang.StringcreateJsonKey(java.lang.String country, java.lang.String shard, java.util.Map<java.lang.String,java.lang.String> metadata)Create a JSON key with a given country and shard.static java.lang.StringparseCountry(java.lang.String json)Given a valid JSON key, parse and return the value of the "country" property.static java.util.Map<java.lang.String,java.lang.String>parseMetadata(java.lang.String json)Given a valid JSON key, parse and return the "metadata" property as a string to stringMap.static java.util.Optional<java.lang.String>parseScheme(java.lang.String json)Given a valid JSON key, parse and return the value of the "scheme" property within the "metadata" object, if present.static java.lang.StringparseShard(java.lang.String json)Given a valid JSON key, parse and return the value of the "shard" property.
-
-
-
Method Detail
-
createJsonKey
public static java.lang.String createJsonKey(java.lang.String country, java.lang.String shard, java.lang.String scheme)Create a JSON key with a given country and shard. Automatically populate a metadata object with some given scheme information.- Parameters:
country- the country, usually the ISO3 country code as well as possible creative additionsshard- the shard name, i.e. the result ofShard.getName()scheme- the scheme string, e.g. zz/- Returns:
- a JSON key with the given elements
-
createJsonKey
public static java.lang.String createJsonKey(java.lang.String country, java.lang.String shard, java.util.Map<java.lang.String,java.lang.String> metadata)Create a JSON key with a given country and shard. Also, provide a string to stringMapcontaining the desired metadata.- Parameters:
country- the country, usually the ISO3 country code as well as possible creative additionsshard- the shard name, i.e. the result ofShard.getName()metadata- a string to stringMapcontaining the metadata- Returns:
- a JSON key with the given elements
-
parseCountry
public static java.lang.String parseCountry(java.lang.String json)
Given a valid JSON key, parse and return the value of the "country" property.- Parameters:
json- the JSON key- Returns:
- the value of the country property
-
parseMetadata
public static java.util.Map<java.lang.String,java.lang.String> parseMetadata(java.lang.String json)
Given a valid JSON key, parse and return the "metadata" property as a string to stringMap.- Parameters:
json- the JSON key- Returns:
- the value of the metadata property
-
parseScheme
public static java.util.Optional<java.lang.String> parseScheme(java.lang.String json)
Given a valid JSON key, parse and return the value of the "scheme" property within the "metadata" object, if present. Otherwise, return an emptyOptional.- Parameters:
json- the JSON key- Returns:
- the value of the scheme property if present, otherwise an empty
Optional
-
parseShard
public static java.lang.String parseShard(java.lang.String json)
Given a valid JSON key, parse and return the value of the "shard" property.- Parameters:
json- the JSON key- Returns:
- the value of the shard property
-
-