Skip to content

Commit

Permalink
refactor(YamlDocumentReader): move readSequenceElements to SequenceRe…
Browse files Browse the repository at this point in the history
…ader

- Encapsulate sequence reading logic within SequenceReader for better organization.
- Improve maintainability and readability of YamlDocumentReader by delegating sequence-specific operations.
  • Loading branch information
ramchaik committed Mar 28, 2024
1 parent 6dd2680 commit 7bddc22
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/com/esotericsoftware/yamlbeans/document/YamlDocumentReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ public YamlElement read(Parser parser) {
}
}

private class SequenceReader implements YamlElementReader {
@Override
public YamlElement read(Parser parser) {
Event event = parser.getNextEvent();
if(event.type!=SEQUENCE_START)
throw new IllegalStateException();
YamlSequence element = new YamlSequence();
SequenceStartEvent sequence = (SequenceStartEvent)event;
element.setTag(sequence.tag);
element.setAnchor(sequence.anchor);
readSequenceElements(element);
return element;
}
}

private class AliasReader implements YamlElementReader {
@Override
public YamlElement read(Parser parser) {
Expand Down Expand Up @@ -220,15 +205,30 @@ public YamlElement read(Parser parser) {
}
}

private void readSequenceElements(YamlSequence sequence) {
while(true) {
Event event = parser.peekNextEvent();
if(event.type==SEQUENCE_END) {
parser.getNextEvent(); // consume it
return;
} else {
YamlElement element = readValue();
sequence.addElement(element);
private class SequenceReader implements YamlElementReader {
@Override
public YamlElement read(Parser parser) {
Event event = parser.getNextEvent();
if(event.type!=SEQUENCE_START)
throw new IllegalStateException();
YamlSequence element = new YamlSequence();
SequenceStartEvent sequence = (SequenceStartEvent)event;
element.setTag(sequence.tag);
element.setAnchor(sequence.anchor);
readSequenceElements(element);
return element;
}

private void readSequenceElements(YamlSequence sequence) {
while(true) {
Event event = parser.peekNextEvent();
if(event.type==SEQUENCE_END) {
parser.getNextEvent(); // consume it
return;
} else {
YamlElement element = readValue();
sequence.addElement(element);
}
}
}
}
Expand Down

0 comments on commit 7bddc22

Please sign in to comment.