@@ -50,7 +50,8 @@ private sealed interface State {
5050 * The cursor should either point to a comma or a closing brace.
5151 * </p>
5252 */
53- record InCompound () implements State {
53+ enum InCompound implements State {
54+ INSTANCE
5455 }
5556
5657 /**
@@ -60,7 +61,8 @@ record InCompound() implements State {
6061 * After this, the cursor will be one character after the colon.
6162 * </p>
6263 */
63- record CompoundEntryName () implements State {
64+ enum CompoundEntryName implements State {
65+ INSTANCE
6466 }
6567
6668 /**
@@ -70,7 +72,8 @@ record CompoundEntryName() implements State {
7072 * The cursor should either point to a comma or a closing bracket.
7173 * </p>
7274 */
73- record InList () implements State {
75+ enum InList implements State {
76+ INSTANCE
7477 }
7578
7679 /**
@@ -80,7 +83,8 @@ record InList() implements State {
8083 * The cursor should always point to the start of a value.
8184 * </p>
8285 */
83- record InByteArray () implements State {
86+ enum InByteArray implements State {
87+ INSTANCE
8488 }
8589
8690 /**
@@ -90,7 +94,8 @@ record InByteArray() implements State {
9094 * The cursor should always point to the start of a value.
9195 * </p>
9296 */
93- record InIntArray () implements State {
97+ enum InIntArray implements State {
98+ INSTANCE
9499 }
95100
96101 /**
@@ -100,14 +105,17 @@ record InIntArray() implements State {
100105 * The cursor should always point to the start of a value.
101106 * </p>
102107 */
103- record InLongArray () implements State {
108+ enum InLongArray implements State {
109+ INSTANCE
104110 }
105111
106112 /**
107113 * We need to read a value. Usually, we'll just return the value, and not push a new state, unless we need to
108114 * read a complex value such as a compound or list.
109115 */
110- record ReadValue (boolean mustBeCompound ) implements State {
116+ enum ReadValue implements State {
117+ ANY ,
118+ COMPOUND_ONLY ,
111119 }
112120 }
113121
@@ -135,7 +143,7 @@ record ReadValue(boolean mustBeCompound) implements State {
135143 */
136144 public LinSnbtReader (Iterator <? extends SnbtTokenWithMetadata > input ) {
137145 this .input = input ;
138- this .stateStack = new ArrayDeque <>(List .of (new State .ReadValue ( true ) ));
146+ this .stateStack = new ArrayDeque <>(List .of (State .ReadValue . COMPOUND_ONLY ));
139147 this .tokenQueue = new ArrayDeque <>();
140148 this .readAgainStack = new ArrayDeque <>();
141149 }
@@ -182,7 +190,7 @@ private NbtParseException unexpectedTokenSpecificError(SnbtToken token, String e
182190
183191 private void fillTokenStack (State state ) {
184192 switch (state ) {
185- case State .ReadValue ( boolean mustBeCompound ) -> readValue (mustBeCompound );
193+ case State .ReadValue readValue -> readValue (readValue );
186194 case State .InCompound inCompound -> advanceCompound ();
187195 case State .CompoundEntryName compoundEntryName -> readName ();
188196 case State .InList inList -> advanceList ();
@@ -211,18 +219,18 @@ private void fillTokenStack(State state) {
211219 }
212220 }
213221
214- private void readValue (boolean mustBeCompound ) {
222+ private void readValue (State . ReadValue readValue ) {
215223 // Remove the ReadValue
216224 stateStack .removeLast ();
217225 var token = read ().token ();
218226 if (token instanceof SnbtToken .CompoundStart ) {
219- stateStack .addLast (new State .InCompound () );
220- stateStack .addLast (new State .CompoundEntryName () );
227+ stateStack .addLast (State .InCompound . INSTANCE );
228+ stateStack .addLast (State .CompoundEntryName . INSTANCE );
221229 tokenQueue .addLast (new LinToken .CompoundStart ());
222230 return ;
223231 }
224232
225- if (mustBeCompound ) {
233+ if (readValue == State . ReadValue . COMPOUND_ONLY ) {
226234 throw unexpectedTokenSpecificError (token , SnbtToken .CompoundStart .INSTANCE .toString ());
227235 }
228236
@@ -243,7 +251,7 @@ private void advanceCompound() {
243251 stateStack .removeLast ();
244252 tokenQueue .addLast (new LinToken .CompoundEnd ());
245253 }
246- case SnbtToken .Separator separator -> stateStack .addLast (new State .CompoundEntryName () );
254+ case SnbtToken .Separator separator -> stateStack .addLast (State .CompoundEntryName . INSTANCE );
247255 default -> throw unexpectedTokenError (token );
248256 }
249257 }
@@ -259,7 +267,7 @@ private void readName() {
259267 if (!(token instanceof SnbtToken .EntrySeparator )) {
260268 throw unexpectedTokenSpecificError (token , SnbtToken .EntrySeparator .INSTANCE .toString ());
261269 }
262- stateStack .addLast (new State .ReadValue ( false ) );
270+ stateStack .addLast (State .ReadValue . ANY );
263271 tokenQueue .addLast (new LinToken .Name (text .content ()));
264272 }
265273
@@ -270,7 +278,7 @@ private void advanceList() {
270278 stateStack .removeLast ();
271279 tokenQueue .addLast (new LinToken .ListEnd ());
272280 }
273- case SnbtToken .Separator separator -> stateStack .addLast (new State .ReadValue ( false ) );
281+ case SnbtToken .Separator separator -> stateStack .addLast (State .ReadValue . ANY );
274282 default -> throw unexpectedTokenError (token );
275283 }
276284 }
@@ -324,23 +332,23 @@ private <T extends Buffer, L extends LinToken> void advanceArray(
324332 private void prepareListLike () {
325333 int initialCharIndex = charIndex ;
326334 var typing = read ();
327- if (typing .token () instanceof SnbtToken .Text text && !text . quoted () && text . content () .length () == 1 ) {
335+ if (typing .token () instanceof SnbtToken .Text ( boolean quoted , String content ) && !quoted && content .length () == 1 ) {
328336 var separatorCheck = read ();
329337 if (separatorCheck .token () instanceof SnbtToken .ListTypeSeparator ) {
330- switch (text . content () .charAt (0 )) {
338+ switch (content .charAt (0 )) {
331339 case 'B' -> {
332- stateStack .addLast (new State .InByteArray () );
340+ stateStack .addLast (State .InByteArray . INSTANCE );
333341 tokenQueue .addLast (new LinToken .ByteArrayStart ());
334342 }
335343 case 'I' -> {
336- stateStack .addLast (new State .InIntArray () );
344+ stateStack .addLast (State .InIntArray . INSTANCE );
337345 tokenQueue .addLast (new LinToken .IntArrayStart ());
338346 }
339347 case 'L' -> {
340- stateStack .addLast (new State .InLongArray () );
348+ stateStack .addLast (State .InLongArray . INSTANCE );
341349 tokenQueue .addLast (new LinToken .LongArrayStart ());
342350 }
343- default -> throw new NbtParseException (errorPrefix () + "Invalid array type: " + text . content () );
351+ default -> throw new NbtParseException (errorPrefix () + "Invalid array type: " + content );
344352 }
345353 return ;
346354 }
@@ -349,8 +357,8 @@ private void prepareListLike() {
349357 readAgainStack .addFirst (typing );
350358 charIndex = initialCharIndex ;
351359
352- stateStack .addLast (new State .InList () );
353- stateStack .addLast (new State .ReadValue ( false ) );
360+ stateStack .addLast (State .InList . INSTANCE );
361+ stateStack .addLast (State .ReadValue . ANY );
354362 tokenQueue .addLast (new LinToken .ListStart ());
355363 }
356364
0 commit comments