|
1 | 1 | package tech.jhipster.lite.module.infrastructure.secondary;
|
2 | 2 |
|
3 |
| -import static org.yaml.snakeyaml.comments.CommentType.*; |
| 3 | +import static org.yaml.snakeyaml.comments.CommentType.BLOCK; |
4 | 4 |
|
5 |
| -import java.io.File; |
6 |
| -import java.io.FileReader; |
7 |
| -import java.io.FileWriter; |
8 |
| -import java.io.IOException; |
9 |
| -import java.io.Writer; |
| 5 | +import java.io.*; |
10 | 6 | import java.nio.file.Files;
|
11 | 7 | import java.nio.file.Path;
|
12 |
| -import java.util.ArrayList; |
13 |
| -import java.util.Arrays; |
14 |
| -import java.util.Collection; |
15 |
| -import java.util.List; |
16 |
| -import java.util.Map; |
17 |
| -import java.util.function.Consumer; |
| 8 | +import java.util.*; |
18 | 9 | import java.util.function.Function;
|
19 | 10 | import java.util.function.Predicate;
|
20 |
| -import org.yaml.snakeyaml.DumperOptions; |
| 11 | +import org.yaml.snakeyaml.*; |
21 | 12 | import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
22 |
| -import org.yaml.snakeyaml.LoaderOptions; |
23 |
| -import org.yaml.snakeyaml.Yaml; |
24 | 13 | import org.yaml.snakeyaml.comments.CommentLine;
|
25 | 14 | import org.yaml.snakeyaml.constructor.Constructor;
|
26 |
| -import org.yaml.snakeyaml.nodes.MappingNode; |
27 |
| -import org.yaml.snakeyaml.nodes.Node; |
28 |
| -import org.yaml.snakeyaml.nodes.NodeTuple; |
29 |
| -import org.yaml.snakeyaml.nodes.ScalarNode; |
30 |
| -import org.yaml.snakeyaml.nodes.SequenceNode; |
31 |
| -import org.yaml.snakeyaml.nodes.Tag; |
| 15 | +import org.yaml.snakeyaml.nodes.*; |
32 | 16 | import org.yaml.snakeyaml.representer.Representer;
|
33 | 17 | import tech.jhipster.lite.module.domain.Indentation;
|
34 |
| -import tech.jhipster.lite.module.domain.javaproperties.Comment; |
35 |
| -import tech.jhipster.lite.module.domain.javaproperties.PropertyKey; |
36 |
| -import tech.jhipster.lite.module.domain.javaproperties.PropertyValue; |
| 18 | +import tech.jhipster.lite.module.domain.javaproperties.*; |
37 | 19 | import tech.jhipster.lite.shared.error.domain.Assert;
|
38 | 20 | import tech.jhipster.lite.shared.error.domain.GeneratorException;
|
39 | 21 | import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage;
|
@@ -91,13 +73,21 @@ private void appendPropertyToConfiguration(PropertyKey key, PropertyValue value,
|
91 | 73 |
|
92 | 74 | List<NodeTuple> parentValue = parentPropertyNode(key, configuration).getValue();
|
93 | 75 |
|
94 |
| - parentValue.stream().filter(nodeTupleKeyEquals(localKey)).findFirst().ifPresent(removeNode(parentValue)); |
95 |
| - |
96 |
| - parentValue.add(new NodeTuple(buildScalarNode(localKey), buildValueNode(value))); |
| 76 | + NodeTuple nodeProperty = new NodeTuple(buildScalarNode(localKey), buildValueNode(value)); |
| 77 | + indexInCollection(parentValue, localKey).ifPresentOrElse( |
| 78 | + index -> parentValue.set(index, nodeProperty), |
| 79 | + () -> parentValue.add(nodeProperty) |
| 80 | + ); |
97 | 81 | }
|
98 | 82 |
|
99 |
| - private Consumer<NodeTuple> removeNode(List<NodeTuple> parentValue) { |
100 |
| - return parentValue::remove; |
| 83 | + private Optional<Integer> indexInCollection(List<NodeTuple> nodesTuples, String key) { |
| 84 | + Predicate<NodeTuple> matchesKey = nodeTupleKeyEquals(key); |
| 85 | + for (int i = 0; i < nodesTuples.size(); i++) { |
| 86 | + if (matchesKey.test(nodesTuples.get(i))) { |
| 87 | + return Optional.of(i); |
| 88 | + } |
| 89 | + } |
| 90 | + return Optional.empty(); |
101 | 91 | }
|
102 | 92 |
|
103 | 93 | private Node buildValueNode(PropertyValue value) {
|
|
0 commit comments