Package com.iizix.geo
Class RegionLocation
java.lang.Object
com.iizix.geo.RegionLocation
- All Implemented Interfaces:
ILongitudeLatitude
Region location information, originating from a host name or IPv4/IPv6 address.
Programming note: DO NOT COMPARE WITH Double.NaN as e.g. value==Double.NaN, use instead as comparison is always false.Double.isNaN(double)
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConnection class holding information about the connection.static classCurrency class holding information about a currency.static classLanguage class holding information about a language.static classClass containing security-related data.static classClass containing timezone information.Field Summary
Fields inherited from interface com.iizix.geo.ILongitudeLatitude
EARTH_RADIUSConstructor Summary
ConstructorsConstructorDescriptionRegionLocation(String ipAddress, String error) Creates an instance of the region information.RegionLocation(String ipAddress, String continent, String continentCode, String country, String countryISO, int countryConfidence, String region, String regionCode, String city, String cityISO, int cityConfidence, String zipCode, int zipCodeConfidence, double longitude, double latitude, double accuracyRadius, String geoNameID, RegionLocation.Timezone timezone, RegionLocation.Currency currency, RegionLocation.Language[] languages, RegionLocation.Connection connection, RegionLocation.Security security) Creates an instance of the region information.Method Summary
Modifier and TypeMethodDescriptionstatic RegionLocation.ConnectionconnectionFrom(String asn, String isp) Creates a Connection instance from the ASN and ISP parameters.static RegionLocation.CurrencyCreates or gets a cached version of the currency.booleanChecks for equality.doubleGets the accuracy radius of the longitude/latitude location,-1dfor none, e.g.getCity()Gets the city name, null for none, e.g.intGets the confidence (0-100) of the city, -1 for none, e.g.Gets the city ISO code, null for none, e.g.The connection, null for none.Gets the continent name, e.g.Gets the continent code, e.g.Gets the country name, e.g.intGets the confidence (0-100) of the country, -1 for none, e.g.Gets the ISO code for the country, e.g.longGets the creation time of this instance.The currency, null for none.getError()Gets the service provider error message why this request failed.Gets the unique geoname identifier in accordance with the Geonames Registry, null for none.Gets the IP address.The languages spoken in the country, null if information is not available.doubleGets the latitude, e.g.doubleGets the longitude, e.g.intGets the confidence (0-100) of the zip code, -1 for none, e.g.Gets the region name, e.g.Gets the region code, e.g.longGets the time it took to retrieve this information in the first place.The security, null for none.Gets the time zone, null for none.Gets the zip code, null for none, e.g.booleanhasError()Checks if the information is not valid, i.e.inthashCode()Gets the hash code.booleanisValid()Checks if the information is valid, i.e.static RegionLocation.LanguagelanguageFrom(String code, String name, String nativeName) Creates or gets a cached version of the language.static intParses the threat level string to a level of: 0 = unknown, 1 = low, 2 = medium, 3 = high.static RegionLocation.TimezonetimezoneFrom(String id, String code, Integer gmtOffset) Creates an instance of a Timezone or get a cached version.toString()Gets a string representation of this instance as "className[countryISO=..,country=..,...]".Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.iizix.geo.ILongitudeLatitude
getDistance
Constructor Details
RegionLocation
Creates an instance of the region information.- Parameters:
ipAddress- The IP address.error- The error string.
RegionLocation
public RegionLocation(String ipAddress, String continent, String continentCode, String country, String countryISO, int countryConfidence, String region, String regionCode, String city, String cityISO, int cityConfidence, String zipCode, int zipCodeConfidence, double longitude, double latitude, double accuracyRadius, String geoNameID, RegionLocation.Timezone timezone, RegionLocation.Currency currency, RegionLocation.Language[] languages, RegionLocation.Connection connection, RegionLocation.Security security) Creates an instance of the region information.- Parameters:
ipAddress- The IP address.continent- Continent name, e.g. 'North America'.continentCode- Continent code, e.g. 'NA'.country- Country name, e.g. 'United States'.countryISO- ISO code for the country, e.g. 'US'.countryConfidence- Confidence (0-100) of the country, -1 for none, e.g. '99'.region- Region name, e.g. 'California'.regionCode- Region code, e.g. 'CA'.city- City name, null for none, e.g. 'Minneapolis'.cityISO- City ISO code, null for none, e.g. 'MN'.cityConfidence- Confidence (0-100) of the city, -1 for none, e.g. '50'.zipCode- Zip code, null for none, e.g. '55455'.zipCodeConfidence- Confidence (0-100) of the zip code, -1 for none, e.g. '40'.longitude- Longitude, e.g. '44.9733'.latitude- Latitude, e.g. '-93.2323'.accuracyRadius- Accuracy radius of the longitude/latitude location,-1dfor none, e.g. '3'.geoNameID- The unique geoname identifier in accordance with the Geonames Registry, null for none.timezone- Time zone, null for none.currency- The currency, null for none.languages- Array of languages spoken in the country, null for none.connection- The connection, null for none.security- The security, null for none.
Method Details
getCreationTime
public long getCreationTime()Gets the creation time of this instance.- Returns:
- Time in milliseconds since the epoch.
getRequestDuration
public long getRequestDuration()Gets the time it took to retrieve this information in the first place. If cached, this information is not relevant.- Returns:
- The request duration in milliseconds.
getIPAddress
Gets the IP address.- Returns:
- The IP address string.
isValid
public boolean isValid()Checks if the information is valid, i.e. that there is no error present.- Returns:
- true if valid, false if an error is present.
hasError
public boolean hasError()Checks if the information is not valid, i.e. if there is an error present.- Returns:
- true if there is an error, false if information is valid.
getError
Gets the service provider error message why this request failed.- Returns:
- The error message, or null for no error.
getContinent
Gets the continent name, e.g. 'North America', null for none.- Returns:
- The continent name.
getContinentCode
Gets the continent code, e.g. 'NA', null for none. The normal codes are:- AF - Africa,
- AS - Asia,
- EU - Europe,
- NA - North America,
- OC - Oceania,
- SA - South America,
- AN - Antarctica.
- Returns:
- The continent code.
getCountry
Gets the country name, e.g. 'United States'.- Returns:
- The country name.
getCountryISO
Gets the ISO code for the country, e.g. 'US'.- Returns:
- The country ISO code.
getCountryConfidence
public int getCountryConfidence()Gets the confidence (0-100) of the country, -1 for none, e.g. '99'.- Returns:
- The country confidence.
getRegion
Gets the region name, e.g. 'California', null for none.- Returns:
- The region name.
getRegionCode
Gets the region code, e.g. 'CA', null for none.- Returns:
- The region code.
getCity
Gets the city name, null for none, e.g. 'Minneapolis'.- Returns:
- The city name.
getCityISO
Gets the city ISO code, null for none, e.g. 'MN'.- Returns:
- The city ISO code.
getCityConfidence
public int getCityConfidence()Gets the confidence (0-100) of the city, -1 for none, e.g. '50'.- Returns:
- The city confidence.
getZipCode
Gets the zip code, null for none, e.g. '55455'.- Returns:
- The zip code.
getPostalCodeConfidence
public int getPostalCodeConfidence()Gets the confidence (0-100) of the zip code, -1 for none, e.g. '40'.- Returns:
- The zip code confidence.
getLongitude
public double getLongitude()Gets the longitude, e.g. '44.9733'.- Specified by:
getLongitudein interfaceILongitudeLatitude- Returns:
- The longitude, Double.NaN for none.
getLatitude
public double getLatitude()Gets the latitude, e.g. '-93.2323'.- Specified by:
getLatitudein interfaceILongitudeLatitude- Returns:
- The latitude, Double.NaN for none.
getAccuracyRadius
public double getAccuracyRadius()Gets the accuracy radius of the longitude/latitude location,-1dfor none, e.g. '3'.- Returns:
- The accuracyRadius, -1d for none.
getGeoNameID
Gets the unique geoname identifier in accordance with the Geonames Registry, null for none.- Returns:
- The geoNameID, or null if not available.
getTimezone
Gets the time zone, null for none.- Returns:
- The Timezone instance, null if this information is not available.
getCurrency
The currency, null for none.- Returns:
- The Currency instance or null for none.
getLanguages
The languages spoken in the country, null if information is not available.- Returns:
- The array of Language instances if this information is available, null otherwise.
getConnection
The connection, null for none.- Returns:
- The Connection instance, or null if this information is not available.
getSecurity
The security, null for none.- Returns:
- The Security instance, or null if this information is not available.
hashCode
public int hashCode()Gets the hash code.equals
Checks for equality.toString
Gets a string representation of this instance as "className[countryISO=..,country=..,...]". Values that arenullorDouble.isNaN(value)are not present.timezoneFrom
Creates an instance of a Timezone or get a cached version.- Parameters:
id- The timezone ID, null for none.code- The timezone code, null for none.gmtOffset- The GMT offset of the given time zone in seconds, e.g. -25200 for PST's -7h GMT offset, null for none.- Returns:
- The timezone instance, or null if
idisnull.
languageFrom
Creates or gets a cached version of the language.- Parameters:
code- The 2-letter language code for the given language.name- The name (in the API request's main language) of the given language, e.g. 'Portuguese', null for none.nativeName- The native name of the given language, e.g. 'Português', null for none.- Throws:
NullPointerException- Ifcodeisnull.
currencyFrom
public static RegionLocation.Currency currencyFrom(String code, String name, String pluralName, String symbol, String nativeSymbol) Creates or gets a cached version of the currency.- Parameters:
code- The 3-letter language code for the given currency code, never null.name- Name in English of the given currency, null for none.pluralName- Plural name of the given currency, null for none.symbol- Symbol letter of the given currency, null for none.nativeSymbol- Native symbol letter of the given currency, null for none.- Returns:
- A Currency instance if
codeis notnull, otherwise null.
connectionFrom
Creates a Connection instance from the ASN and ISP parameters.- Parameters:
asn- The Autonomous System Number associated with the IP, null if not defined.isp- The name of the ISP associated with the IP, null if not defined.- Returns:
- A new Connection instance if either ASN or ASP is non-null.
securityThreadLevelFrom
Parses the threat level string to a level of:- 0 = unknown,
- 1 = low,
- 2 = medium,
- 3 = high.
- Parameters:
s- The string, perhaps null.- Returns:
- A security thread level 0-3.