Enum Class GeoLocation.Status
- All Implemented Interfaces:
Serializable, Comparable<GeoLocation.Status>, Constable
- Enclosing class:
GeoLocation
This enum provides type-safe status codes for geolocation lookup results, replacing the previous string constants. Each status has a corresponding string code for backward compatibility and logging purposes.
Usage Example
GeoLocation loc = service.lookup("8.8.8.8");
switch (loc.getStatus()) {
case OK:
System.out.println("Country: " + loc.getCountryCode());
break;
case NOT_FOUND:
System.out.println("IP not in database");
break;
case SERVICE_DISABLED:
System.out.println("Geolocation is disabled");
break;
default:
System.err.println("Error: " + loc.getStatus().getCode());
}
- Author:
- Christopher Mindus
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E>Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionAn I/O error occurred during the lookup.No database is currently loaded.The IP address was null or empty.The IP address format was invalid.IPv6 lookup was attempted but no IPv6 database is loaded.The IP address was not found in the database.Lookup was successful.The service is disabled.The service has been disposed.The manager has not been configured yet.The service is currently being reconfigured.The manager has been shut down.Method Summary
Modifier and TypeMethodDescriptionstatic GeoLocation.StatusFinds a status by its string code.static GeoLocation.StatusfromCodeOrDefault(String code, GeoLocation.Status defaultValue) Finds a status by its string code, returning a default if not found.getCode()Returns the string code for this status.toString()Returns the string code for this status.static GeoLocation.StatusReturns the enum constant of this class with the specified name.static GeoLocation.Status[]values()Returns an array containing the constants of this enum class, in the order they are declared.
Enum Constant Details
OK
Lookup was successful.All applicable fields for the database type are populated with valid data.
EMPTY_IP
The IP address was null or empty.The lookup method was called with a null or whitespace-only string.
INVALID_IP
The IP address format was invalid.The string could not be parsed as either a valid IPv4 or IPv6 address.
NOT_FOUND
The IP address was not found in the database.The IP address was valid but not present in the loaded database. This can occur for reserved/private IP ranges, very new allocations, or IP ranges not covered by the LITE database.
DB_NOT_LOADED
No database is currently loaded.The service has not yet loaded any database files. This typically occurs during initialization or after a failed database download.
IPV6_NOT_SUPPORTED
IPv6 lookup was attempted but no IPv6 database is loaded.To enable IPv6 lookups, configure the service with
IP2LocationService.Builder.includeIPv6(boolean)set totrue.DB_ERROR
An I/O error occurred during the lookup.This typically indicates a problem reading the database file, such as disk errors, file corruption, or the file being unexpectedly modified.
SERVICE_DISABLED
The service is disabled.The service was configured with
IP2LocationService.Builder.enabled(boolean)set tofalse. No databases are loaded and lookups cannot be performed.- See Also:
SERVICE_DISPOSED
The service has been disposed.The
IP2LocationService.dispose()method was called, releasing all resources. The service can no longer perform lookups.SERVICE_SHUTDOWN
The manager has been shut down.The
IP2LocationManager.shutdown()method was called. The manager can no longer perform lookups or be reconfigured.SERVICE_NOT_CONFIGURED
The manager has not been configured yet.A lookup was attempted on
IP2LocationManagerbefore callingIP2LocationManager.configure(IP2LocationService.Builder)orIP2LocationManager.configureAsync(IP2LocationService.Builder, IInitializationCallback).SERVICE_RECONFIGURING
The service is currently being reconfigured.A lookup was attempted during the brief window when the service is transitioning between configurations. This is rare and transient.
Method Details
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
getCode
Returns the string code for this status.This is useful for logging, serialization, or backward compatibility with code that expects string status codes.
- Returns:
- The string code (e.g., "OK", "EMPTY_IP_ADDRESS", "DATABASE_ERROR")
toString
Returns the string code for this status.This override ensures that logging and string concatenation produce the expected string code rather than the enum name.
- Overrides:
toStringin classEnum<GeoLocation.Status>- Returns:
- The string code
fromCode
Finds a status by its string code.This method enables backward compatibility with code that uses string status codes, such as status codes returned from the underlying IP2Location BIN reader.
- Parameters:
code- The string code to search for (case-sensitive)- Returns:
- The matching status
- Throws:
IllegalArgumentException- if no status matches the codeNullPointerException- if code is null
fromCodeOrDefault
Finds a status by its string code, returning a default if not found.This is useful when parsing status codes that might not match any known status, such as unexpected responses from the database reader.
- Parameters:
code- The string code to search for (case-sensitive)defaultValue- The value to return if no status matches- Returns:
- The matching status, or defaultValue if not found or code is null