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 Double.isNaN(double)
- Author:
- Christopher Mindus
- Nested Class SummaryNested ClassesModifier and TypeClassDescription- static 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_RADIUS
- Constructor SummaryConstructorsConstructorDescription- RegionLocation- (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 SummaryModifier and TypeMethodDescription- static RegionLocation.Connection- connectionFrom- (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.- boolean- hasError()Checks if the information is not valid, i.e.- int- hashCode()Gets the hash code.- boolean- isValid()Checks if the information is valid, i.e.- static RegionLocation.Language- languageFrom- (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.Timezone- timezoneFrom- (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, wait- Methods inherited from interface com.iizix.geo.ILongitudeLatitude- getDistance
- Constructor Details- RegionLocationCreates an instance of the region information.- Parameters:
- ipAddress- The IP address.
- error- The error string.
 
- RegionLocationpublic 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- getCreationTimepublic long getCreationTime()Gets the creation time of this instance.- Returns:
- Time in milliseconds since the epoch.
 
- getRequestDurationpublic 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.
 
- getIPAddressGets the IP address.- Returns:
- The IP address string.
 
- isValidpublic 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.
 
- hasErrorpublic 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.
 
- getErrorGets the service provider error message why this request failed.- Returns:
- The error message, or null for no error.
 
- getContinentGets the continent name, e.g. 'North America', null for none.- Returns:
- The continent name.
 
- getContinentCodeGets 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.
 
- getCountryGets the country name, e.g. 'United States'.- Returns:
- The country name.
 
- getCountryISOGets the ISO code for the country, e.g. 'US'.- Returns:
- The country ISO code.
 
- getCountryConfidencepublic int getCountryConfidence()Gets the confidence (0-100) of the country, -1 for none, e.g. '99'.- Returns:
- The country confidence.
 
- getRegionGets the region name, e.g. 'California', null for none.- Returns:
- The region name.
 
- getRegionCodeGets the region code, e.g. 'CA', null for none.- Returns:
- The region code.
 
- getCityGets the city name, null for none, e.g. 'Minneapolis'.- Returns:
- The city name.
 
- getCityISOGets the city ISO code, null for none, e.g. 'MN'.- Returns:
- The city ISO code.
 
- getCityConfidencepublic int getCityConfidence()Gets the confidence (0-100) of the city, -1 for none, e.g. '50'.- Returns:
- The city confidence.
 
- getZipCodeGets the zip code, null for none, e.g. '55455'.- Returns:
- The zip code.
 
- getPostalCodeConfidencepublic int getPostalCodeConfidence()Gets the confidence (0-100) of the zip code, -1 for none, e.g. '40'.- Returns:
- The zip code confidence.
 
- getLongitudepublic double getLongitude()Gets the longitude, e.g. '44.9733'.- Specified by:
- getLongitudein interface- ILongitudeLatitude
- Returns:
- The longitude, Double.NaN for none.
 
- getLatitudepublic double getLatitude()Gets the latitude, e.g. '-93.2323'.- Specified by:
- getLatitudein interface- ILongitudeLatitude
- Returns:
- The latitude, Double.NaN for none.
 
- getAccuracyRadiuspublic double getAccuracyRadius()Gets the accuracy radius of the longitude/latitude location,- -1dfor none, e.g. '3'.- Returns:
- The accuracyRadius, -1d for none.
 
- getGeoNameIDGets the unique geoname identifier in accordance with the Geonames Registry, null for none.- Returns:
- The geoNameID, or null if not available.
 
- getTimezoneGets the time zone, null for none.- Returns:
- The Timezone instance, null if this information is not available.
 
- getCurrencyThe currency, null for none.- Returns:
- The Currency instance or null for none.
 
- getLanguagesThe languages spoken in the country, null if information is not available.- Returns:
- The array of Language instances if this information is available, null otherwise.
 
- getConnectionThe connection, null for none.- Returns:
- The Connection instance, or null if this information is not available.
 
- getSecurityThe security, null for none.- Returns:
- The Security instance, or null if this information is not available.
 
- hashCodepublic int hashCode()Gets the hash code.
- equalsChecks for equality.
- toStringGets a string representation of this instance as "className[countryISO=..,country=..,...]". Values that are- nullor- Double.isNaN(value)are not present.
- timezoneFromCreates 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.
 
- languageFromCreates 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- If- codeis- null.
 
- currencyFrompublic 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.
 
- connectionFromCreates 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.
 
- securityThreadLevelFromParses 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.