Skip to content

Commit 7e6c098

Browse files
authored
Merge pull request #263 from aether-framework/bugfix/126-127-130-133-134-135-188-189-final-cleanup
Extend builder and codec support for up to 8 fields
2 parents 596a003 + bfc0751 commit 7e6c098

7 files changed

Lines changed: 405 additions & 16 deletions

File tree

aether-datafixers-api/src/main/java/de/splatgames/aether/datafixers/api/codec/Codecs.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.util.ArrayList;
3333
import java.util.List;
34-
import java.util.Objects;
3534
import java.util.Optional;
3635

3736
/**
@@ -766,8 +765,8 @@ public <T> DataResult<T> encode(@NotNull final Pair<F, S> input,
766765
Preconditions.checkNotNull(input, "input must not be null");
767766
Preconditions.checkNotNull(ops, "ops must not be null");
768767
Preconditions.checkNotNull(prefix, "prefix must not be null");
769-
return first.encode(Objects.requireNonNull(input.first()), ops, prefix)
770-
.flatMap(t -> second.encode(Objects.requireNonNull(input.second()), ops, t));
768+
return first.encode(Preconditions.checkNotNull(input.first(), "pair first must not be null"), ops, prefix)
769+
.flatMap(t -> second.encode(Preconditions.checkNotNull(input.second(), "pair second must not be null"), ops, t));
771770
}
772771

773772
@NotNull
@@ -777,13 +776,13 @@ public <T> DataResult<Pair<Pair<F, S>, T>> decode(@NotNull final DynamicOps<T> o
777776
Preconditions.checkNotNull(ops, "ops must not be null");
778777
Preconditions.checkNotNull(input, "input must not be null");
779778
return first.decode(ops, input).flatMap(p1 ->
780-
second.decode(ops, Objects.requireNonNull(p1.second())).map(p2 ->
779+
second.decode(ops, Preconditions.checkNotNull(p1.second(), "first decode remainder must not be null")).map(p2 ->
781780
Pair.of(
782781
Pair.of(
783-
Objects.requireNonNull(p1.first()),
784-
Objects.requireNonNull(p2.first())
782+
Preconditions.checkNotNull(p1.first(), "first decode value must not be null"),
783+
Preconditions.checkNotNull(p2.first(), "second decode value must not be null")
785784
),
786-
Objects.requireNonNull(p2.second())
785+
Preconditions.checkNotNull(p2.second(), "second decode remainder must not be null")
787786
)
788787
)
789788
);

aether-datafixers-api/src/main/java/de/splatgames/aether/datafixers/api/codec/RecordCodecBuilder.java

Lines changed: 339 additions & 3 deletions
Large diffs are not rendered by default.

aether-datafixers-api/src/main/java/de/splatgames/aether/datafixers/api/diagnostic/FixExecution.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@
5959
* @param startTime the instant when the fix started
6060
* @param duration the total time taken to apply the fix
6161
* @param ruleApplications list of individual rule applications within this fix
62-
* @param beforeSnapshot optional snapshot of data before the fix was applied
63-
* @param afterSnapshot optional snapshot of data after the fix was applied
62+
* @param beforeSnapshot snapshot of data before the fix was applied, or {@code null}
63+
* if snapshot capture was disabled in {@link DiagnosticOptions}
64+
* @param afterSnapshot snapshot of data after the fix was applied, or {@code null}
65+
* if snapshot capture was disabled or the fix failed
6466
* @author Erik Pförtner
6567
* @see RuleApplication
6668
* @see MigrationReport

aether-datafixers-api/src/main/java/de/splatgames/aether/datafixers/api/exception/DataFixerException.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.jetbrains.annotations.NotNull;
2626
import org.jetbrains.annotations.Nullable;
2727

28+
import java.io.Serial;
29+
2830
/**
2931
* Base exception class for all data fixer related errors.
3032
*
@@ -74,6 +76,15 @@
7476
*/
7577
public class DataFixerException extends RuntimeException {
7678

79+
/**
80+
* Serial version UID for serialization compatibility.
81+
*/
82+
@Serial
83+
private static final long serialVersionUID = 2074356976574888083L;
84+
85+
/**
86+
* Optional context information about where the error occurred (e.g., field path, type name).
87+
*/
7788
@Nullable
7889
private final String context;
7990

@@ -145,9 +156,10 @@ public String getContext() {
145156
*/
146157
@Override
147158
public String toString() {
159+
final String base = getClass().getSimpleName() + ": " + getMessage();
148160
if (this.context != null) {
149-
return super.toString() + " [context: " + this.context + "]";
161+
return base + " [context: " + this.context + "]";
150162
}
151-
return super.toString();
163+
return base;
152164
}
153165
}

aether-datafixers-api/src/main/java/de/splatgames/aether/datafixers/api/util/Unit.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
import org.jetbrains.annotations.NotNull;
2626

27+
import java.io.Serial;
28+
import java.io.Serializable;
29+
2730
/**
2831
* A singleton type representing the absence of a meaningful value.
2932
*
@@ -65,7 +68,7 @@
6568
* @see de.splatgames.aether.datafixers.api.result.DataResult
6669
* @since 0.1.0
6770
*/
68-
public final class Unit {
71+
public final class Unit implements Serializable {
6972

7073
/**
7174
* The singleton instance of Unit.
@@ -76,6 +79,15 @@ public final class Unit {
7679
@NotNull
7780
public static final Unit INSTANCE = new Unit();
7881

82+
/**
83+
* Serial version UID for serialization compatibility.
84+
*
85+
* <p>This value is arbitrary but should be changed if the class structure changes in a way that affects
86+
* serialization.</p>
87+
*/
88+
@Serial
89+
private static final long serialVersionUID = -7628105959309438762L;
90+
7991
/**
8092
* Private constructor to prevent external instantiation.
8193
*
@@ -120,4 +132,14 @@ public int hashCode() {
120132
public boolean equals(final Object obj) {
121133
return obj instanceof Unit;
122134
}
135+
136+
/**
137+
* Preserves the singleton guarantee during deserialization.
138+
*
139+
* @return {@link #INSTANCE}
140+
*/
141+
@Serial
142+
private Object readResolve() {
143+
return INSTANCE;
144+
}
123145
}

aether-datafixers-testkit/src/main/java/de/splatgames/aether/datafixers/testkit/TestDataBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
* A fluent builder for creating {@link Dynamic} objects.
3838
*
3939
* <p>This builder provides a clean, readable API for constructing test data
40-
* without the boilerplate of manual JSON construction. It supports primitives,
40+
* without the boilerplate of manual JSON construction. Each builder instance should
41+
* only be used for a single {@link #build()} call — create a new instance for each
42+
* Dynamic value. It supports primitives,
4143
* nested objects, and lists through method chaining.</p>
4244
*
4345
* <h2>Basic Usage</h2>

aether-datafixers-testkit/src/main/java/de/splatgames/aether/datafixers/testkit/TestDataListBuilder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,22 @@ public TestDataListBuilder<T> addAll(final double... values) {
320320
return this;
321321
}
322322

323+
/**
324+
* Adds multiple float elements to the list.
325+
*
326+
* @param values the float values
327+
* @return this builder for chaining
328+
* @throws NullPointerException if {@code values} is null
329+
*/
330+
@NotNull
331+
public TestDataListBuilder<T> addAll(final float... values) {
332+
Preconditions.checkNotNull(values, "values must not be null");
333+
for (final float value : values) {
334+
this.add(value);
335+
}
336+
return this;
337+
}
338+
323339
/**
324340
* Adds multiple boolean elements to the list.
325341
*

0 commit comments

Comments
 (0)