Skip to content

Commit 710d1fb

Browse files
committed
refactor
1 parent 9a8e7c0 commit 710d1fb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/main/java/org/scm4j/commons/RegexConfig.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,27 @@ public void loadFromYamlUrls(String... separatedUrls) throws IOException {
3939
if (map != null) {
4040
this.content.putAll(map);
4141
}
42-
4342
}
4443
}
4544
}
4645
}
4746

4847
String prependOmapIfNeed(String content, Yaml yaml) throws IOException {
49-
if (isNotEmptyAndHasNoOMAPTag(content)) {
50-
StringReader sr = new StringReader(content);
51-
Node node = yaml.compose(sr);
52-
if (node.getNodeId().equals(NodeId.sequence)) {
48+
if (isSequence(content, yaml)) {
49+
if (noOMAPTag(content)) {
5350
return OMAP_TAG + "\r\n" + content;
5451
}
5552
}
5653
return content;
5754
}
5855

59-
private boolean isNotEmptyAndHasNoOMAPTag(String content) throws IOException {
56+
boolean isSequence(String content, Yaml yaml) {
57+
StringReader sr = new StringReader(content);
58+
Node node = yaml.compose(sr);
59+
return node != null && node.getNodeId().equals(NodeId.sequence);
60+
}
61+
62+
boolean noOMAPTag(String content) throws IOException {
6063
StringReader sr = new StringReader(content);
6164
BufferedReader br = new BufferedReader(sr);
6265
String line = br.readLine();
@@ -67,7 +70,7 @@ private boolean isNotEmptyAndHasNoOMAPTag(String content) throws IOException {
6770
}
6871
line = br.readLine();
6972
}
70-
return false;
73+
return true;
7174
}
7275

7376
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)