Skip to content

Commit 75c359a

Browse files
committed
Make array tag setters return fluent interface
1 parent 34844a2 commit 75c359a

5 files changed

Lines changed: 40 additions & 15 deletions

File tree

‎src/main/java/org/glavo/nbt/tag/ArrayTag.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ final void setArrayWithoutClone(A array, int size) {
235235
/// Sets the value at the given index.
236236
///
237237
/// @throws IndexOutOfBoundsException if the index is out of bounds.
238-
@Contract(mutates = "this")
239-
public abstract void set(int index, @Flow(targetIsContainer = true) E value) throws IndexOutOfBoundsException;
238+
@Contract(value = "_, _ -> this", mutates = "this")
239+
public abstract ArrayTag<E, T, A, B> set(int index, @Flow(targetIsContainer = true) E value) throws IndexOutOfBoundsException;
240240

241241
/// Sets all values of the tag from an array.
242242
///
@@ -276,7 +276,7 @@ public final void setAll(@Flow(sourceIsContainer = true, targetIsContainer = tru
276276
/// Appends the specified value to the end of this array.
277277
@Contract(value = "_ -> this", mutates = "this")
278278
public abstract ArrayTag<E, T, A, B> add(@Flow(targetIsContainer = true)
279-
E value);
279+
E value);
280280

281281
@Override
282282
@MustBeInvokedByOverriders

‎src/main/java/org/glavo/nbt/tag/ByteArrayTag.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,27 @@ void setDirect(int index, byte value) {
7878
/// Sets the value at the given index.
7979
///
8080
/// @throws IndexOutOfBoundsException if the index is out of bounds.
81-
@Contract(mutates = "this")
82-
public void set(int index, byte value) throws IndexOutOfBoundsException {
81+
@Contract(value = "_, _ -> this", mutates = "this")
82+
public ByteArrayTag set(int index, byte value) throws IndexOutOfBoundsException {
8383
Objects.checkIndex(index, size);
8484
setDirect(index, value);
8585

8686
ByteTag tag = getTagOrNull(index);
8787
if (tag != null) {
8888
tag.setDirect(value);
8989
}
90+
return this;
9091
}
9192

9293
/// {@inheritDoc}
9394
///
9495
/// @see #set(int, byte)
9596
@Override
96-
@Contract(mutates = "this")
97+
@Contract(value = "_, _ -> this", mutates = "this")
9798
@ApiStatus.Obsolete
98-
public void set(int index, Byte value) throws IndexOutOfBoundsException {
99+
public ByteArrayTag set(int index, Byte value) throws IndexOutOfBoundsException {
99100
set(index, value.byteValue());
101+
return this;
100102
}
101103

102104
@Override

‎src/main/java/org/glavo/nbt/tag/IntArrayTag.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,27 @@ void setDirect(int index, int value) {
108108
/// Sets the value at the given index.
109109
///
110110
/// @throws IndexOutOfBoundsException if the index is out of bounds.
111-
@Contract(mutates = "this")
112-
public void set(int index, int value) throws IndexOutOfBoundsException {
111+
@Contract(value = "_, _ -> this", mutates = "this")
112+
public IntArrayTag set(int index, int value) throws IndexOutOfBoundsException {
113113
Objects.checkIndex(index, size);
114114
setDirect(index, value);
115115

116116
IntTag tag = getTagOrNull(index);
117117
if (tag != null) {
118118
tag.setDirect(value);
119119
}
120+
return this;
120121
}
121122

122123
/// {@inheritDoc}
123124
///
124125
/// @see #set(int, int)
125126
@Override
126-
@Contract(mutates = "this")
127+
@Contract(value = "_, _ -> this", mutates = "this")
127128
@ApiStatus.Obsolete
128-
public void set(int index, Integer value) throws IndexOutOfBoundsException {
129+
public IntArrayTag set(int index, Integer value) throws IndexOutOfBoundsException {
129130
set(index, value.intValue());
131+
return this;
130132
}
131133

132134
@Override

‎src/main/java/org/glavo/nbt/tag/LongArrayTag.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,27 @@ void setDirect(int index, long value) {
8282
/// Sets the value at the given index.
8383
///
8484
/// @throws IndexOutOfBoundsException if the index is out of bounds.
85-
@Contract(mutates = "this")
86-
public void set(int index, long value) throws IndexOutOfBoundsException {
85+
@Contract(value = "_, _ -> this", mutates = "this")
86+
public LongArrayTag set(int index, long value) throws IndexOutOfBoundsException {
8787
Objects.checkIndex(index, size);
8888
setDirect(index, value);
8989

9090
LongTag tag = getTagOrNull(index);
9191
if (tag != null) {
9292
tag.setDirect(value);
9393
}
94+
return this;
9495
}
9596

9697
/// {@inheritDoc}
9798
///
9899
/// @see #set(int, long)
99100
@Override
100-
@Contract(mutates = "this")
101+
@Contract(value = "_, _ -> this", mutates = "this")
101102
@ApiStatus.Obsolete
102-
public void set(int index, Long value) throws IndexOutOfBoundsException {
103+
public LongArrayTag set(int index, Long value) throws IndexOutOfBoundsException {
103104
set(index, value.longValue());
105+
return this;
104106
}
105107

106108
@Override
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2026 Glavo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.glavo.nbt.validator;
17+
18+
public final class NBTSchema {
19+
}

0 commit comments

Comments
 (0)