Skip to content

Package: MultilingualString

MultilingualString

nameinstructionbranchcomplexitylinemethod
MultilingualString()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
MultilingualString(Map)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
equals(Object)
M: 4 C: 15
79%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 4
67%
M: 0 C: 1
100%
get(String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getValue()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
set(String, String)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
toString()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.model;
19:
20: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
21:
22: import java.io.Serializable;
23: import java.util.Collections;
24: import java.util.HashMap;
25: import java.util.Map;
26: import java.util.Objects;
27:
28: /**
29: * Value object representing the same string in multiple languages.
30: * <p>
31: * This is not a general-purpose type, it should be used only in instances where multiple translations of the same
32: * string need to be treated as a single value. Its main purpose is to allow support for multilingual strings in
33: * referenced lists (e.g., {@link cz.cvut.kbss.ontodriver.Lists#loadReferencedList(ReferencedListDescriptor)}).
34: */
35: public final class MultilingualString implements Serializable {
36:
37: private final Map<String, String> value;
38:
39: public MultilingualString() {
40: this.value = new HashMap<>();
41: }
42:
43: public MultilingualString(Map<String, String> value) {
44: this.value = new HashMap<>(Objects.requireNonNull(value));
45: }
46:
47: /**
48: * Sets translation in the specified language.
49: *
50: * @param language Language tag value
51: * @param value Translation in the specified language
52: */
53: public void set(String language, String value) {
54: Objects.requireNonNull(value);
55: this.value.put(language, value);
56: }
57:
58: /**
59: * Gets translation in the specified language (if present).
60: *
61: * @param language Language tag
62: * @return Translation in the specified language, {@code null} if it is not available
63: */
64: public String get(String language) {
65: return value.get(language);
66: }
67:
68: /**
69: * Gets an unmodifiable view of the internal representation of this multilingual string.
70: *
71: * @return Unmodifiable map
72: */
73: public Map<String, String> getValue() {
74: return Collections.unmodifiableMap(value);
75: }
76:
77: @Override
78: public boolean equals(Object o) {
79:• if (this == o) {
80: return true;
81: }
82:• if (!(o instanceof MultilingualString)) {
83: return false;
84: }
85: MultilingualString that = (MultilingualString) o;
86: return value.equals(that.value);
87: }
88:
89: @Override
90: public int hashCode() {
91: return Objects.hash(value);
92: }
93:
94: @Override
95: public String toString() {
96: return value.toString();
97: }
98: }