1
- /*
2
- * This file is a part of MDClasses.
3
- *
4
- * Copyright (c) 2019 - 2024
5
- * Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6
- *
7
- * SPDX-License-Identifier: LGPL-3.0-or-later
8
- *
9
- * MDClasses is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU Lesser General Public
11
- * License as published by the Free Software Foundation; either
12
- * version 3.0 of the License, or (at your option) any later version.
13
- *
14
- * MDClasses is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- * Lesser General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU Lesser General Public
20
- * License along with MDClasses.
21
- */
22
- package com .github ._1c_syntax .bsl .mdo .support ;
1
+ /*
2
+ * This file is a part of MDClasses.
3
+ *
4
+ * Copyright (c) 2019 - 2024
5
+ * Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6
+ *
7
+ * SPDX-License-Identifier: LGPL-3.0-or-later
8
+ *
9
+ * MDClasses is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3.0 of the License, or (at your option) any later version.
13
+ *
14
+ * MDClasses is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with MDClasses.
21
+ */
22
+ package com .github ._1c_syntax .bsl .mdo .support ;
23
23
24
- import lombok . AllArgsConstructor ;
24
+ import com . github . _1c_syntax . utils . StringInterner ;
25
25
import lombok .NonNull ;
26
26
import lombok .Value ;
27
27
34
34
* Используется для хранения текстовой строки на разных языках
35
35
*/
36
36
@ Value
37
- @ AllArgsConstructor
38
37
public class MultiLanguageString {
39
38
40
39
/**
41
40
* Ссылка на пустой элемент
42
41
*/
43
42
public static final MultiLanguageString EMPTY = new MultiLanguageString (Collections .emptyMap ());
44
43
44
+ private static final StringInterner stringInterner = new StringInterner ();
45
+
45
46
/**
46
47
* Содержимое описания для каждого языка
47
48
*/
48
49
Map <String , String > content ;
49
50
51
+ public MultiLanguageString (Map <String , String > source ) {
52
+ Map <String , String > newContent = new HashMap <>();
53
+ source .forEach (
54
+ (langKey , text ) -> newContent .put (stringInterner .intern (langKey ), text ));
55
+ content = newContent ;
56
+ }
57
+
50
58
public MultiLanguageString (@ NonNull MultiLanguageString first , @ NonNull MultiLanguageString second ) {
51
59
var fullContent = new HashMap <>(first .getContent ());
52
- fullContent . putAll ( second . getContent () );
60
+ putContent ( fullContent , second );
53
61
content = fullContent ;
54
62
}
55
63
@@ -68,7 +76,7 @@ public static MultiLanguageString of(@NonNull List<MultiLanguageString> strings)
68
76
return strings .get (0 );
69
77
} else {
70
78
Map <String , String > content = new HashMap <>();
71
- strings .forEach (string -> content . putAll ( string . getContent () ));
79
+ strings .forEach (string -> putContent ( content , string ));
72
80
return new MultiLanguageString (content );
73
81
}
74
82
}
@@ -103,4 +111,9 @@ public static MultiLanguageString of(@NonNull List<MultiLanguageString> strings)
103
111
public boolean isEmpty () {
104
112
return this == EMPTY ;
105
113
}
114
+
115
+ private static void putContent (Map <String , String > destination , MultiLanguageString source ) {
116
+ source .getContent ().forEach (
117
+ (langKey , text ) -> destination .put (stringInterner .intern (langKey ), text ));
118
+ }
106
119
}
0 commit comments