Class GeoLocation.Builder
java.lang.Object
co.mindus.ip2location.GeoLocation.Builder
- Enclosing class:
GeoLocation
Builder for creating
GeoLocation instances.This builder allows for fluent construction of GeoLocation objects. At minimum, ip(String) should be set before calling build().
Example
GeoLocation loc = GeoLocation.builder()
.ip("8.8.8.8")
.status(GeoLocation.Status.OK)
.countryCode("US")
.countryName("United States of America")
.region("California")
.city("Mountain View")
.latitude(37.4056)
.longitude(-122.0775)
.zipCode("94043")
.timeZone("America/Los_Angeles")
.build();
Thread Safety
Builder instances are not thread-safe. Each thread should use its own builder.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionbuild()Builds the GeoLocation instance.Sets the city name.countryCode(String countryCode) Sets the country code.countryName(String countryName) Sets the country name.Sets the IP address.isIPv6(boolean isIPv6) Sets whether this is an IPv6 lookup.latitude(double latitude) Sets the latitude.longitude(double longitude) Sets the longitude.Sets the region/state name.status(GeoLocation.Status status) Sets the status.Sets the timezone.Sets the ZIP/postal code.
Constructor Details
Builder
public Builder()Creates a new Builder with default values.
Method Details
ip
Sets the IP address.- Parameters:
ip- The IP address string- Returns:
- This builder for chaining
status
Sets the status.- Parameters:
status- The status enum value- Returns:
- This builder for chaining
countryCode
Sets the country code.- Parameters:
countryCode- ISO 3166-1 alpha-2 country code- Returns:
- This builder for chaining
countryName
Sets the country name.- Parameters:
countryName- Full country name- Returns:
- This builder for chaining
region
Sets the region/state name.- Parameters:
region- Region or state name- Returns:
- This builder for chaining
city
Sets the city name.- Parameters:
city- City name- Returns:
- This builder for chaining
latitude
Sets the latitude.- Parameters:
latitude- Latitude in decimal degrees (-90 to 90)- Returns:
- This builder for chaining
longitude
Sets the longitude.- Parameters:
longitude- Longitude in decimal degrees (-180 to 180)- Returns:
- This builder for chaining
zipCode
Sets the ZIP/postal code.- Parameters:
zipCode- ZIP or postal code- Returns:
- This builder for chaining
timeZone
Sets the timezone.- Parameters:
timeZone- Timezone in tz database format- Returns:
- This builder for chaining
isIPv6
Sets whether this is an IPv6 lookup.- Parameters:
isIPv6-trueif IPv6- Returns:
- This builder for chaining
build