예제 #1
0
 /**
  * Returns the locale formatted as language-region. If region is not set, language is returned. If
  * language is not set, empty string is returned.
  */
 public String toLocaleId() {
   // Return lang-reg only if both lang and reg are present. Else return
   // lang.
   return hasLanguage() && hasRegion()
       ? language.getValue() + "-" + region.getValue()
       : hasLanguage() ? language.getValue() : "";
 }
예제 #2
0
 @Override
 public String toString() {
   return Objects.toStringHelper(this)
       .omitNullValues()
       .addValue(language.getValue())
       .addValue(region.getValue())
       .toString();
 }
예제 #3
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((language == null) ? 0 : language.hashCode());
   result = prime * result + ((region == null) ? 0 : region.hashCode());
   return result;
 }
예제 #4
0
 /**
  * Constructs a new {@linkplain Locale} matching a given language in a given locale.
  *
  * @param language the language
  * @param region the region
  */
 private Locale(@NonNull LanguageQualifier language, @NonNull RegionQualifier region) {
   if (language.getValue().equals(FAKE_LANG_VALUE)) {
     language = ANY_LANGUAGE;
   }
   if (region.getValue().equals(FAKE_REGION_VALUE)) {
     region = ANY_REGION;
   }
   this.language = language;
   this.region = region;
 }
예제 #5
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   Locale other = (Locale) obj;
   if (language == null) {
     if (other.language != null) return false;
   } else if (!language.equals(other.language)) return false;
   if (region == null) {
     if (other.region != null) return false;
   } else if (!region.equals(other.region)) return false;
   return true;
 }
예제 #6
0
  /**
   * Returns a flag image to use for this locale
   *
   * @return a flag image, or a default globe icon
   */
  @NonNull
  public Image getFlagImage() {
    Image image = null;
    String languageCode = hasLanguage() ? language.getValue() : null;
    String regionCode = hasRegion() ? region.getValue() : null;
    if (languageCode == null && regionCode == null) {
      return FlagManager.getGlobeIcon();
    } else {
      FlagManager icons = FlagManager.get();
      image = icons.getFlag(languageCode, regionCode);
      if (image == null) {
        image = FlagManager.getEmptyIcon();
      }

      return image;
    }
  }