Skip to content

Commit 4ea8407

Browse files
committed
интернирование для ролей и мультиязычных строк
1 parent ee30c88 commit 4ea8407

File tree

3 files changed

+68
-51
lines changed

3 files changed

+68
-51
lines changed

src/main/java/com/github/_1c_syntax/bsl/mdo/storage/RoleData.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
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.storage;
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.storage;
2323

2424
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
2525
import com.github._1c_syntax.bsl.reader.MDOReader;
26+
import com.github._1c_syntax.utils.GenericInterner;
2627
import lombok.Builder;
2728
import lombok.Builder.Default;
2829
import lombok.EqualsAndHashCode;
@@ -46,6 +47,7 @@
4647
public class RoleData {
4748

4849
public static final RoleData EMPTY = RoleData.builder().build();
50+
public static final GenericInterner<Right> RIGHT_INTERNER = new GenericInterner<>();
4951

5052
/**
5153
* Устанавливать права для новых объектов
@@ -97,8 +99,8 @@ public static class ObjectRight {
9799
}
98100

99101
@Value
100-
@ToString(of = {"name"})
101-
@EqualsAndHashCode(of = {"name"})
102+
@ToString(of = {"name", "value"})
103+
@EqualsAndHashCode(of = {"name", "value"})
102104
@Builder
103105
public static class Right {
104106
/**

src/main/java/com/github/_1c_syntax/bsl/mdo/support/MultiLanguageString.java

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
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;
2323

24-
import lombok.AllArgsConstructor;
24+
import com.github._1c_syntax.utils.StringInterner;
2525
import lombok.NonNull;
2626
import lombok.Value;
2727

@@ -34,22 +34,30 @@
3434
* Используется для хранения текстовой строки на разных языках
3535
*/
3636
@Value
37-
@AllArgsConstructor
3837
public class MultiLanguageString {
3938

4039
/**
4140
* Ссылка на пустой элемент
4241
*/
4342
public static final MultiLanguageString EMPTY = new MultiLanguageString(Collections.emptyMap());
4443

44+
private static final StringInterner stringInterner = new StringInterner();
45+
4546
/**
4647
* Содержимое описания для каждого языка
4748
*/
4849
Map<String, String> content;
4950

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+
5058
public MultiLanguageString(@NonNull MultiLanguageString first, @NonNull MultiLanguageString second) {
5159
var fullContent = new HashMap<>(first.getContent());
52-
fullContent.putAll(second.getContent());
60+
putContent(fullContent, second);
5361
content = fullContent;
5462
}
5563

@@ -68,7 +76,7 @@ public static MultiLanguageString of(@NonNull List<MultiLanguageString> strings)
6876
return strings.get(0);
6977
} else {
7078
Map<String, String> content = new HashMap<>();
71-
strings.forEach(string -> content.putAll(string.getContent()));
79+
strings.forEach(string -> putContent(content, string));
7280
return new MultiLanguageString(content);
7381
}
7482
}
@@ -103,4 +111,9 @@ public static MultiLanguageString of(@NonNull List<MultiLanguageString> strings)
103111
public boolean isEmpty() {
104112
return this == EMPTY;
105113
}
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+
}
106119
}

src/main/java/com/github/_1c_syntax/bsl/reader/common/converter/RoleDataConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.github._1c_syntax.bsl.mdo.storage.RoleData;
2525
import com.github._1c_syntax.bsl.reader.common.TransformationUtils;
2626
import com.github._1c_syntax.bsl.reader.common.xstream.ReadConverter;
27+
import com.github._1c_syntax.utils.GenericInterner;
2728
import com.thoughtworks.xstream.converters.UnmarshallingContext;
2829
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
2930

@@ -89,7 +90,8 @@ private static RoleData.Right readRight(HierarchicalStreamReader reader, Unmarsh
8990
TransformationUtils.setValue(builder, name, value);
9091
reader.moveUp();
9192
}
92-
return builder.build();
93+
94+
return RoleData.RIGHT_INTERNER.intern(builder.build());
9395
}
9496

9597
@Override

0 commit comments

Comments
 (0)