Skip to content

Commit 65028b9

Browse files
committed
Add generic type parameters to ValueTag
1 parent d6aa272 commit 65028b9

8 files changed

Lines changed: 74 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121

2222
/// 1 byte signed integer tag type. Sometimes used for booleans.
23-
public final class ByteTag extends ValueTag {
23+
public final class ByteTag extends ValueTag<Byte> {
2424
private byte value;
2525

2626
public ByteTag() {
@@ -46,6 +46,11 @@ public byte get() {
4646
return value;
4747
}
4848

49+
@Override
50+
public Byte getValue() {
51+
return value;
52+
}
53+
4954
/// Returns the value of the tag as a boolean.
5055
public boolean getBoolean() {
5156
// Should stricter checks be performed?
@@ -57,6 +62,11 @@ public void set(byte value) {
5762
this.value = value;
5863
}
5964

65+
@Override
66+
public void setValue(Byte value) {
67+
this.value = value;
68+
}
69+
6070
/// Sets the boolean value of the tag.
6171
///
6272
/// If the `value` is `true`, the tag will be set to `1`; otherwise, it will be set to `0`.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121

2222
/// 8 byte floating point tag type.
23-
public final class DoubleTag extends ValueTag {
23+
public final class DoubleTag extends ValueTag<Double> {
2424
private double value;
2525

2626
public DoubleTag() {
@@ -46,11 +46,21 @@ public double get() {
4646
return value;
4747
}
4848

49+
@Override
50+
public Double getValue() {
51+
return value;
52+
}
53+
4954
/// Sets the value of the tag.
5055
public void set(double value) {
5156
this.value = value;
5257
}
5358

59+
@Override
60+
public void setValue(Double value) {
61+
this.value = value;
62+
}
63+
5464
@Override
5565
protected void readContent(NBTReader reader) throws IOException {
5666
set(reader.readDouble());

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121

2222
/// 4 byte floating point tag type.
23-
public final class FloatTag extends ValueTag {
23+
public final class FloatTag extends ValueTag<Float> {
2424
private float value;
2525

2626
public FloatTag() {
@@ -46,11 +46,21 @@ public float get() {
4646
return value;
4747
}
4848

49+
@Override
50+
public Float getValue() {
51+
return value;
52+
}
53+
4954
/// Sets the value of the tag.
5055
public void set(float value) {
5156
this.value = value;
5257
}
5358

59+
@Override
60+
public void setValue(Float value) {
61+
this.value = value;
62+
}
63+
5464
@Override
5565
protected void readContent(NBTReader reader) throws IOException {
5666
set(reader.readFloat());

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121

2222
/// 4 byte signed integer tag type.
23-
public final class IntTag extends ValueTag {
23+
public final class IntTag extends ValueTag<Integer> {
2424
private int value;
2525

2626
public IntTag() {
@@ -46,11 +46,21 @@ public int get() {
4646
return value;
4747
}
4848

49+
@Override
50+
public Integer getValue() {
51+
return value;
52+
}
53+
4954
/// Sets the value of the tag.
5055
public void set(int value) {
5156
this.value = value;
5257
}
5358

59+
@Override
60+
public void setValue(Integer value) {
61+
this.value = value;
62+
}
63+
5464
@Override
5565
protected void readContent(NBTReader reader) throws IOException {
5666
set(reader.readInt());

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121

2222
/// 8 byte signed integer tag type.
23-
public final class LongTag extends ValueTag {
23+
public final class LongTag extends ValueTag<Long> {
2424
private long value;
2525

2626
public LongTag() {
@@ -46,11 +46,21 @@ public long get() {
4646
return value;
4747
}
4848

49+
@Override
50+
public Long getValue() {
51+
return value;
52+
}
53+
4954
/// Sets the value of the tag.
5055
public void set(long value) {
5156
this.value = value;
5257
}
5358

59+
@Override
60+
public void setValue(Long value) {
61+
this.value = value;
62+
}
63+
5464
@Override
5565
protected void readContent(NBTReader reader) throws IOException {
5666
set(reader.readLong());

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121

2222
/// 2 byte signed integer tag type.
23-
public final class ShortTag extends ValueTag {
23+
public final class ShortTag extends ValueTag<Short> {
2424
private short value;
2525

2626
public ShortTag() {
@@ -46,11 +46,21 @@ public short get() {
4646
return value;
4747
}
4848

49+
@Override
50+
public Short getValue() {
51+
return value;
52+
}
53+
4954
/// Sets the value of the tag.
5055
public void set(short value) {
5156
this.value = value;
5257
}
5358

59+
@Override
60+
public void setValue(Short value) {
61+
this.value = value;
62+
}
63+
5464
@Override
5565
protected void readContent(NBTReader reader) throws IOException {
5666
set(reader.readShort());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121
import java.util.Objects;
2222

23-
public final class StringTag extends ValueTag {
23+
public final class StringTag extends ValueTag<String> {
2424
private String value;
2525

2626
public StringTag() {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
*/
1616
package org.glavo.nbt.tag;
1717

18-
public sealed abstract class ValueTag extends Tag
18+
public sealed abstract class ValueTag<V> extends Tag
1919
permits ByteTag, ShortTag, IntTag, LongTag, DoubleTag, FloatTag, StringTag {
2020
protected ValueTag(String name) {
2121
super(name);
2222
}
23+
24+
/// Returns the value of the tag.
25+
public abstract V getValue();
26+
27+
/// Sets the value of the tag.
28+
public abstract void setValue(V value);
2329
}

0 commit comments

Comments
 (0)