Class MuLi


  • public class MuLi
    extends java.lang.Object
    Each MuLi represents a multi-lingual identifier or text. Its structure is
     language ::= (String U _syntheticLanguage_)  
     MuLi ::= language -/-> String 
    #_syntheticLanguage_ is a special string value reserved for the cases in which a language differetiation is not applicable (e.g. for pure numeric strings or for personal names).
    The language values should follow the ISO language codes. as specified in ISO 639-2. These are the codes also used by "xml:lang", cf. RFC 4646 / RFC 4647 / IETF BCP 47.

    At least they should not have the value of the #_syntheticLanguage_ string.
    The look-up function get(String) is delegated to a map object and has the usual java-like semantics, esp. returning null if s not in the domain.
    Further, there is a special look-up function get(String...) of type

     get : preference:(SEQ language)->MuLi.TextFound
    with
     
        MuLi.TextFound ::= (index:(NAT U{-1}) * language:String * result:String
       
    The object of class MuLi.TextFound, as returned by the function, reflects the most left language in the original preference list for which an entry can be found in the MuLi object.
    An index of =-1 indicated the fact that the found language is chosen by random and was not in the list of preferred languages.
    ATTENTION
    "language" parameters are currently encoded as "totally free" string values.
    (1) A linkage to the "locale" mechanisms of java is not yet defined.
    (2) A hash storage for all "language" strings (converting them to unique single objects) could be sensible, but has to be decided in connection with (1).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  MuLi.TextFound
      A class representing the result of calls to get(String...) and sim.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Location location  
      static java.lang.String syntheticLanguage
      Use this as key value for put and get in cases where no natural language is applicable.
      protected java.util.Map<java.lang.String,​java.lang.String> texts  
    • Constructor Summary

      Constructors 
      Constructor Description
      MuLi()  
      MuLi​(java.util.Map<java.lang.String,​java.lang.String> data)
      Initialize translations, uses put(Map), see there for important remarks!
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      MuLi cloneUnmodifiable()  
      boolean containsLang​(java.lang.String lang)  
      @Opt java.lang.String get​(java.lang.String lang)  
      @Opt MuLi.TextFound get​(java.lang.String... preference)  
      @Opt MuLi.TextFound get​(java.util.List<java.lang.String> preference)  
      Location get_location()  
      java.util.Set<java.lang.String> getLanguages()  
      void put​(java.lang.String... pairs)
      Deprecated.
      use "put({@link eu.bandm.tools.ops.Collections.literalMap()}" instead!
      void put​(java.lang.String lang, java.lang.String text)
      Put a new key/value pair into the internal map.
      void put​(java.util.List<java.lang.String> pairs)
      Deprecated.
      use "put({@link eu.bandm.tools.ops.Collections.literalMap()}" instead!
      void put​(java.util.Map<java.lang.String,​java.lang.String> data)
      Put a multitude of key/value pairs into the internal map.
      void set_location​(Location loc)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • syntheticLanguage

        public static final java.lang.String syntheticLanguage
        Use this as key value for put and get in cases where no natural language is applicable. E.g. for technical notions, personal names, formulae.
        See Also:
        Constant Field Values
      • texts

        protected java.util.Map<java.lang.String,​java.lang.String> texts
    • Constructor Detail

      • MuLi

        public MuLi()
      • MuLi

        public MuLi​(java.util.Map<java.lang.String,​java.lang.String> data)
        Initialize translations, uses put(Map), see there for important remarks!
    • Method Detail

      • cloneUnmodifiable

        public MuLi cloneUnmodifiable()
        Returns:
        an unmodifiable copy. (Indeed, location is still modifiable !-)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation. currently using java.util.Map default conversion.
      • get_location

        public Location get_location()
      • set_location

        public void set_location​(Location loc)
      • getLanguages

        public java.util.Set<java.lang.String> getLanguages()
        Returns:
        an unmodifiable copy of all languages serving as keys.
      • get

        @Opt
        public @Opt java.lang.String get​(java.lang.String lang)
        Returns:
        the string stored under a certain key representing a "language". Is directly mapped to java.util.Map, i.e. returns null if key not in domain.
      • containsLang

        public boolean containsLang​(java.lang.String lang)
        Returns:
        whether there is an entry in this language.
      • get

        @Opt
        public @Opt MuLi.TextFound get​(java.lang.String... preference)
        Returns:
        a MuLi.TextFound object representing the first string found when trying the listed languages from left to right. If not translation is found, return an arbitrary one. If no translation exists, return null.
      • put

        public void put​(java.lang.String lang,
                        java.lang.String text)
        Put a new key/value pair into the internal map. Existing entries will silently be overwritten.
        Parameters:
        lang - the key, should be a language code.
        text - the value, i.e. the translation into this language.
      • put

        public void put​(java.util.Map<java.lang.String,​java.lang.String> data)
        Put a multitude of key/value pairs into the internal map. The mapentries are separated into key and value, and passed to put(String,String).
        So, existing entries will silently be overwritten.
        Parameters:
        map - map of language to name
      • put

        @Deprecated
        public void put​(java.lang.String... pairs)
        Deprecated.
        use "put({@link eu.bandm.tools.ops.Collections.literalMap()}" instead!
        Put a multitude of key/value pairs into the internal map. The number of arguments must be even. The arguments are intepreted as key and value, alternatingly, and passed to put(String,String).
        So, existing entries will silently be overwritten.
        Parameters:
        pairs - sequence of key/value pairs
        Throws:
        java.lang.IllegalArgumentException - in case the number of Strings in not even.
      • put

        @Deprecated
        public void put​(java.util.List<java.lang.String> pairs)
        Deprecated.
        use "put({@link eu.bandm.tools.ops.Collections.literalMap()}" instead!
        See Also:
        put(String...)