From d4e4daff938a55a0f05c1116f4b17a897a13138b Mon Sep 17 00:00:00 2001 From: nguillaumin Date: Fri, 5 Feb 2016 13:54:08 +1100 Subject: [PATCH 1/2] Added accessors to the list of all country names and codes --- src/main/java/com/maxmind/geoip/LookupService.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/maxmind/geoip/LookupService.java b/src/main/java/com/maxmind/geoip/LookupService.java index eadfd41..af582ce 100644 --- a/src/main/java/com/maxmind/geoip/LookupService.java +++ b/src/main/java/com/maxmind/geoip/LookupService.java @@ -402,6 +402,20 @@ public synchronized void close() { } } + /** + * @return The list of all known country names + */ + public String[] getAllCountryNames() { + return countryName; + } + + /** + * @return The list of all known country codes + */ + public String[] getAllCountryCodes() { + return countryCode; + } + /** * Returns the country the IP address is in. * From 6204c686e3e93abfd2678e0e4f7007568b2a2436 Mon Sep 17 00:00:00 2001 From: nguillaumin Date: Sat, 6 Feb 2016 10:52:51 +1100 Subject: [PATCH 2/2] Avoid returning the backing array to prevent modifications. Also return a `List` rather than an array for convenience. --- src/main/java/com/maxmind/geoip/LookupService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/maxmind/geoip/LookupService.java b/src/main/java/com/maxmind/geoip/LookupService.java index af582ce..94687fb 100644 --- a/src/main/java/com/maxmind/geoip/LookupService.java +++ b/src/main/java/com/maxmind/geoip/LookupService.java @@ -29,6 +29,8 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; +import java.util.Arrays; +import java.util.List; /** * Provides a lookup service for information based on an IP address. The @@ -405,15 +407,15 @@ public synchronized void close() { /** * @return The list of all known country names */ - public String[] getAllCountryNames() { - return countryName; + public List getAllCountryNames() { + return Arrays.asList(Arrays.copyOf(countryName, countryName.length)); } /** * @return The list of all known country codes */ - public String[] getAllCountryCodes() { - return countryCode; + public List getAllCountryCodes() { + return Arrays.asList(Arrays.copyOf(countryCode, countryCode.length)); } /**