Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GeoIP API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Foundation
IT
APIs
GeoIP API
Merge requests
!16
Create an endpoint for creating country lists
#15
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Create an endpoint for creating country lists
#15
github/fork/autumnfound/malowe/master/15
into
master
Overview
0
Commits
1
Changes
6
Closed
Martin Lowe
requested to merge
github/fork/autumnfound/malowe/master/15
into
master
3 years ago
Overview
0
Commits
1
Changes
6
Expand
0
0
Merge request reports
Compare
master
version 1
c84135a0
3 years ago
master (base)
and
latest version
latest version
c84135a0
1 commit,
3 years ago
version 1
c84135a0
1 commit,
3 years ago
6 files
+
148
−
10
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
src/main/java/org/eclipsefoundation/geoip/client/helper/CountryHelper.java
0 → 100644
+
48
−
0
Options
/**
* Copyright (c) 2021 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
package
org.eclipsefoundation.geoip.client.helper
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.eclipsefoundation.geoip.client.model.ISOCountry
;
/**
* Helper to retrieve and cache countries and country codes in a light manner.
*/
public
class
CountryHelper
{
private
static
final
Map
<
String
,
List
<
ISOCountry
>>
countryListCache
=
new
HashMap
<>();
public
static
List
<
ISOCountry
>
getCountries
(
Locale
l
)
{
// Default to EN locale if not specified
Locale
actualLocale
=
l
!=
null
?
l
:
Locale
.
ENGLISH
;
// get the cached data if it exists
List
<
ISOCountry
>
countries
=
countryListCache
.
get
(
actualLocale
.
getLanguage
());
if
(
countries
==
null
)
{
// generate cached data
String
[]
isoCountries
=
Locale
.
getISOCountries
();
countries
=
new
ArrayList
<>(
isoCountries
.
length
);
for
(
String
isoCountry
:
isoCountries
)
{
Locale
c
=
new
Locale
(
""
,
isoCountry
);
countries
.
add
(
new
ISOCountry
(
c
.
getDisplayCountry
(
actualLocale
),
c
.
getCountry
()));
}
countryListCache
.
put
(
actualLocale
.
getLanguage
(),
countries
);
}
return
new
ArrayList
<>(
countries
);
}
private
CountryHelper
()
{
}
}
Loading