Class NameTranslations


  • public final class NameTranslations
    extends java.lang.Object
    A helper class for bundling language-to-name maps. It assures a Language.DEFAULT translation is always provided on its initialization. It has init methods simplifying its initialization:
       private static final NameTranslations nameTranslations = NameTranslations.of(
                 Language.DE, "Setze Nächste Dokument-Stage",
                 Language.EN, "Set Next Document Stage"
       );
     
    Finally, it encapsulates a consistent way of getting a translation in a desired language, expressed by a Language object or by a simple 2-char String representation of it. It makes sure that even if the language one provides is not supported for any reason, at the very least the default translation will be returned.
    • Constructor Summary

      Constructors 
      Constructor Description
      NameTranslations​(java.util.Map<Language,​java.lang.String> translations)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<Language,​java.lang.String> asMap()
      Returns the whole immutable map of language-translation pairs this object holds.
      java.lang.String getTranslationForLanguage​(Language language)
      Gets a translation for a given language or the Language.DEFAULT translation if the requested one is not available.
      java.lang.String getTranslationForLanguage​(java.lang.String language)
      Gets a translation for a given language or the Language.DEFAULT translation if the requested one is not available.
      static NameTranslations of​(Language lang, java.lang.String translation)
      Returns a NameTranslations containing a single language-to-translation entry.
      static NameTranslations of​(Language lang1, java.lang.String translation1, Language lang2, java.lang.String translation2)
      Returns a NameTranslations containing two language-to-translation entries.
      static NameTranslations of​(Language lang1, java.lang.String translation1, Language lang2, java.lang.String translation2, Language lang3, java.lang.String translation3)
      Returns a NameTranslations containing three language-to-translation entries.
      static NameTranslations of​(Language lang1, java.lang.String translation1, Language lang2, java.lang.String translation2, Language lang3, java.lang.String translation3, Language lang4, java.lang.String translation4)
      Returns a NameTranslations containing four language-to-translation entries.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • NameTranslations

        public NameTranslations​(java.util.Map<Language,​java.lang.String> translations)
        Parameters:
        translations - a language-to-name map containing all desired translations. Needs to contain an entry for the Language.DEFAULT. No nulls are allowed.
    • Method Detail

      • of

        public static NameTranslations of​(Language lang,
                                          java.lang.String translation)
        Returns a NameTranslations containing a single language-to-translation entry. No nulls are allowed.
        Parameters:
        lang - the Language.DEFAULT value object
        translation - a string translation for that language
        Returns:
        a NameTranslations containing a single language-to-translation entry
      • of

        public static NameTranslations of​(Language lang1,
                                          java.lang.String translation1,
                                          Language lang2,
                                          java.lang.String translation2)
        Returns a NameTranslations containing two language-to-translation entries. One of them needs to be for the Language.DEFAULT language. No nulls are allowed.
        Parameters:
        lang1 - the first entry language
        translation1 - the first entry string translation
        lang2 - the second entry language
        translation2 - the second entry string translation
        Returns:
        a NameTranslations containing the listed language-to-translation entries
      • of

        public static NameTranslations of​(Language lang1,
                                          java.lang.String translation1,
                                          Language lang2,
                                          java.lang.String translation2,
                                          Language lang3,
                                          java.lang.String translation3)
        Returns a NameTranslations containing three language-to-translation entries. One of them needs to be for the Language.DEFAULT language. No nulls are allowed.
        Parameters:
        lang1 - the first entry language
        translation1 - the first entry string translation
        lang2 - the second entry language
        translation2 - the second entry string translation
        lang3 - the third entry language
        translation3 - the third entry string translation
        Returns:
        a NameTranslations containing the listed language-to-translation entries
      • of

        public static NameTranslations of​(Language lang1,
                                          java.lang.String translation1,
                                          Language lang2,
                                          java.lang.String translation2,
                                          Language lang3,
                                          java.lang.String translation3,
                                          Language lang4,
                                          java.lang.String translation4)
        Returns a NameTranslations containing four language-to-translation entries. One of them needs to be for the Language.DEFAULT language. No nulls are allowed.
        Parameters:
        lang1 - the first entry language
        translation1 - the first entry string translation
        lang2 - the second entry language
        translation2 - the second entry string translation
        lang3 - the third entry language
        translation3 - the third entry string translation
        lang4 - the fourth entry language
        translation4 - the fourth entry string translation
        Returns:
        a NameTranslations containing the listed language-to-translation entries
      • getTranslationForLanguage

        public java.lang.String getTranslationForLanguage​(Language language)
        Gets a translation for a given language or the Language.DEFAULT translation if the requested one is not available.
        Parameters:
        language - a translation language to look for
        Returns:
        a translation for a selected language or a default translation if the requested one is not available.
      • getTranslationForLanguage

        public java.lang.String getTranslationForLanguage​(java.lang.String language)
        Gets a translation for a given language or the Language.DEFAULT translation if the requested one is not available.
        Parameters:
        language - a translation language to look for, expecting a two lower case letter Language compatible code.
        Returns:
        a translation for a selected language or a default translation if the requested one is not available.
      • asMap

        public java.util.Map<Language,​java.lang.String> asMap()
        Returns the whole immutable map of language-translation pairs this object holds.
        Returns:
        all translations in a form of an immutable map
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object