Enum Class GeoLocation.Status

java.lang.Object
java.lang.Enum<GeoLocation.Status>
co.mindus.ip2location.GeoLocation.Status
All Implemented Interfaces:
Serializable, Comparable<GeoLocation.Status>, Constable
Enclosing class:
GeoLocation

public static enum GeoLocation.Status extends Enum<GeoLocation.Status>
Enumeration of possible lookup result statuses.

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
  • Enum Constant Details

    • OK

      public static final GeoLocation.Status OK
      Lookup was successful.

      All applicable fields for the database type are populated with valid data.

    • EMPTY_IP

      public static final GeoLocation.Status EMPTY_IP
      The IP address was null or empty.

      The lookup method was called with a null or whitespace-only string.

    • INVALID_IP

      public static final GeoLocation.Status INVALID_IP
      The IP address format was invalid.

      The string could not be parsed as either a valid IPv4 or IPv6 address.

    • NOT_FOUND

      public static final GeoLocation.Status 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

      public static final GeoLocation.Status 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

      public static final GeoLocation.Status 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 to true.

    • DB_ERROR

      public static final GeoLocation.Status 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

      public static final GeoLocation.Status SERVICE_DISABLED
      The service is disabled.

      The service was configured with IP2LocationService.Builder.enabled(boolean) set to false. No databases are loaded and lookups cannot be performed.

      See Also:
    • SERVICE_DISPOSED

      public static final GeoLocation.Status 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

      public static final GeoLocation.Status 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

      public static final GeoLocation.Status SERVICE_NOT_CONFIGURED
    • SERVICE_RECONFIGURING

      public static final GeoLocation.Status 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

      public static GeoLocation.Status[] 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

      public static GeoLocation.Status valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getCode

      public String 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

      public String 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:
      toString in class Enum<GeoLocation.Status>
      Returns:
      The string code
    • fromCode

      public static GeoLocation.Status fromCode(String code)
      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 code
      NullPointerException - if code is null
    • fromCodeOrDefault

      public static GeoLocation.Status fromCodeOrDefault(String code, GeoLocation.Status defaultValue)
      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