Skip to content

Commit 6846d50

Browse files
committed
Extract updateIndexes method to ParentTag
1 parent 0f79b07 commit 6846d50

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/main/java/org/glavo/nbt/tag/CompoundTag.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ public void remove(Tag tag) {
115115
tag.parent = null;
116116

117117
// Update the index of the successor tags.
118-
for (int i = subtagIndex; i < subTags.size(); i++) {
119-
subTags.get(i).index = i;
120-
}
118+
updateIndexes(subtagIndex);
121119
}
122120

123121
@Override

src/main/java/org/glavo/nbt/tag/ListTag.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public void remove(Tag tag) {
149149
tag.parent = null;
150150

151151
// Update the index of the successor tags.
152-
for (int i = subtagIndex; i < subTags.size(); i++) {
153-
subTags.get(i).index = i;
154-
}
152+
updateIndexes(subtagIndex);
155153
}
156154

157155
@Override

src/main/java/org/glavo/nbt/tag/ParentTag.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ protected ParentTag(String name) {
3737
/// @see Tag#setName(String)
3838
abstract void updateSubTagName(Tag tag, String name) throws IllegalStateException;
3939

40+
protected final void updateIndexes(int startIndex) {
41+
for (int i = startIndex, end = subTags.size(); i < end; i++) {
42+
subTags.get(i).index = i;
43+
}
44+
}
45+
4046
/// Returns `true` if this tag is the root tag, `false` otherwise.
4147
public final boolean isRoot() {
4248
return parent == null;

0 commit comments

Comments
 (0)