Class MultilingualString
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ChangeTrackingIndirectMultilingualString
This allows an application to naturally work in an internationalized environment leveraging the language-tagged strings of the Semantic Web.
Instances of this class basically represent all available translations of the string, allowing to read (and write)
particular versions by specifying the corresponding language tag. A special case supported by this class are simple literals (language-less strings with
type xsd:string
), for which the language tag is null
.
Note that this class is not thread-safe.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMultilingualString
(Map<String, String> value) Creates a newMultilingualString
instance based on the specified value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether this string contains value in the specified language.boolean
Checks whether this string contains a simple literal value.static MultilingualString
Creates a new instance ofMultilingualString
and sets the specified value in the specified language.boolean
get()
Gets the value of a simple literal represented by this instance.Gets value for the specified language.Gets the set of languages for which translations exist in the instance.getValue()
Gets the translations contained in this instance as a map of language-value pairs.int
hashCode()
boolean
isEmpty()
Checks whether this instance does not contain any language representations (including a simple literal).void
Removes translation in the specified language.Sets value without language.Sets value in the specified language.toString()
-
Constructor Details
-
MultilingualString
public MultilingualString() -
MultilingualString
Creates a newMultilingualString
instance based on the specified value.Convenience constructor for simple initialization with existing data.
- Parameters:
value
- Map of language to translation values
-
-
Method Details
-
set
Sets value in the specified language.This overrides any previous value in the specified language, if it existed.
- Parameters:
language
- Language to use with the specified value. Passingnull
has the same effect asset(String)
value
- String value in the specified language- Returns:
- This instance
- See Also:
-
set
Sets value without language.That is, the specified value will be stored as a simple literal (type xsd:string).
- Parameters:
value
- Value to set- Returns:
- This instance
- See Also:
-
get
Gets value for the specified language.If no language is specified, either the simple literal value is returned (if present), or any other existing value is returned. However, note that, in case of missing simple literal, repeated calls may return values in different languages. If there are no translations,
null
is returned.- Parameters:
language
- Requested language (language tag). Can benull
- Returns:
- Value of this string for the specified language (or
null
if not available)
-
get
Gets the value of a simple literal represented by this instance.If this instances does not represent a simple literal, any other existing value is returned. However, note that in that case repeated calls may return values in different languages.
If this object is empty (i.e., neither simple literal nor any translations are available),
null
is returned.- Returns:
- Value of simple literal represented by this string
-
contains
Checks whether this string contains value in the specified language.If no language is specified (argument is
null
), this method will returntrue
if there is value without language tag (simple literal) or in any other language.- Parameters:
language
- Requested language (language tag)- Returns:
true
if this string exists in the specified language
-
containsSimple
public boolean containsSimple()Checks whether this string contains a simple literal value.That is, whether this instance contains a value without a language tag.
- Returns:
true
if and only if this string exists as a simple literal
-
isEmpty
public boolean isEmpty()Checks whether this instance does not contain any language representations (including a simple literal).- Returns:
true
if no translations exist in this instance
-
remove
Removes translation in the specified language.Passing in
null
will remove the simple literal contained in this instance.- Parameters:
language
- Language for which translation should be removed
-
getLanguages
Gets the set of languages for which translations exist in the instance.Note that the result may contain
null
, indicating a simple literal.- Returns:
- Set of languages available in this multilingual string
-
getValue
Gets the translations contained in this instance as a map of language-value pairs.Convenience method for accessing all values at once. Note that this method returns the actual value used by this instance, so any changes to it will be reflected in the instance's behavior. It is not a general purpose method, rather a way to access and manipulate the underlying data structure more efficiently when necessary.
- Returns:
- Map of language to translation values
-
equals
-
hashCode
public int hashCode() -
toString
-
create
Creates a new instance ofMultilingualString
and sets the specified value in the specified language.Convenience method for creating strings with one (initial) translation.
- Parameters:
value
- String valuelanguage
- Language of the value (language tag)- Returns:
- New instance of
MultiLangString
-