View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import org.apache.commons.lang3.StringUtils;
23  
24  import java.util.ArrayList;
25  import java.util.Arrays;
26  import java.util.Collections;
27  import java.util.HashSet;
28  import java.util.List;
29  import java.util.Locale;
30  import java.util.Set;
31  
32  public class LocaleList {
33  
34    public static final List<LocaleEntry> DATA;
35  
36    public static final List<String> COUNTRY_LANGUAGE;
37  
38    public static final List<String> COUNTRY;
39  
40    public static final List<String> HOLIDAY;
41  
42    static {
43      final List<LocaleEntry> init = new ArrayList<>();
44      for (final Locale displayLocale : Locale.getAvailableLocales()) {
45        for (final Locale locale : Locale.getAvailableLocales()) {
46          init.add(new LocaleEntry(locale, displayLocale));
47        }
48      }
49      DATA = Collections.unmodifiableList(init);
50    }
51  
52    static {
53      final Set<String> init = new HashSet<>();
54      for (final LocaleEntry localeEntry : DATA) {
55        if (StringUtils.isNotBlank(localeEntry.getCountry())
56            && StringUtils.isNotBlank(localeEntry.getLanguage())) {
57          final String name = localeEntry.getCountry() + " (" + localeEntry.getLanguage() + ")";
58          init.add(name);
59        }
60      }
61      final ArrayList<String> list = new ArrayList<>(init);
62      Collections.sort(list);
63      COUNTRY_LANGUAGE = Collections.unmodifiableList(list);
64    }
65  
66    static {
67      final Set<String> init = new HashSet<>();
68      for (final LocaleEntry localeEntry : DATA) {
69        if (StringUtils.isNotBlank(localeEntry.getCountry())) {
70          init.add(localeEntry.getCountry());
71        }
72      }
73      final ArrayList<String> list = new ArrayList<>(init);
74      Collections.sort(list);
75      COUNTRY = Collections.unmodifiableList(list);
76    }
77  
78    static {
79      final List<String> list = Arrays.asList(
80          "Trinidad and Tobago",
81          "Portugal",
82          "Norway",
83          "New Zealand",
84          "Equador",
85          "Greece",
86          "Reunion",
87          "Mauritius",
88          "Dominica");
89      Collections.sort(list);
90      HOLIDAY = Collections.unmodifiableList(list);
91    }
92  
93  
94    private LocaleList() {
95      // do not call
96    }
97  }