Skip to content

Commit d9c8a96

Browse files
committed
Add DelegatingReadContext and DelegatingWriteContext
1 parent ae64751 commit d9c8a96

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package net.roxymc.jserialize.adapter;
2+
3+
import net.roxymc.jserialize.adapter.object.FormatUtils;
4+
import org.jspecify.annotations.Nullable;
5+
6+
public class DelegatingReadContext implements ReadContext {
7+
private final ReadContext delegate;
8+
9+
public DelegatingReadContext(ReadContext delegate) {
10+
this.delegate = delegate;
11+
}
12+
13+
public final ReadContext delegate() {
14+
return delegate;
15+
}
16+
17+
protected ReadContext wrap(ReadContext delegate) {
18+
return new DelegatingReadContext(delegate);
19+
}
20+
21+
@Override
22+
public TypeAdapters typeAdapters() {
23+
return delegate.typeAdapters();
24+
}
25+
26+
@Override
27+
public @Nullable Object parent() {
28+
return delegate.parent();
29+
}
30+
31+
@Override
32+
public ReadContext withParent(@Nullable Object parent) {
33+
return wrap(delegate.withParent(parent));
34+
}
35+
36+
@Override
37+
public @Nullable String key() {
38+
return delegate.key();
39+
}
40+
41+
@Override
42+
public ReadContext withKey(@Nullable String key) {
43+
return wrap(delegate.withKey(key));
44+
}
45+
46+
@Override
47+
public FormatUtils<?> formatUtils() {
48+
return delegate.formatUtils();
49+
}
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.roxymc.jserialize.adapter;
2+
3+
import net.roxymc.jserialize.adapter.object.FormatUtils;
4+
5+
public class DelegatingWriteContext implements WriteContext {
6+
private final WriteContext delegate;
7+
8+
protected DelegatingWriteContext(WriteContext delegate) {
9+
this.delegate = delegate;
10+
}
11+
12+
public final WriteContext delegate() {
13+
return delegate;
14+
}
15+
16+
@Override
17+
public TypeAdapters typeAdapters() {
18+
return delegate.typeAdapters();
19+
}
20+
21+
@Override
22+
public FormatUtils<?> formatUtils() {
23+
return delegate.formatUtils();
24+
}
25+
}

core/src/main/java/net/roxymc/jserialize/adapter/ReadContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.io.IOException;
1010

11+
@ApiStatus.NonExtendable
1112
public interface ReadContext {
1213
@ApiStatus.Internal
1314
static ReadContext of(TypeAdapters typeAdapters, FormatUtils<?> formatUtils) {

core/src/main/java/net/roxymc/jserialize/adapter/WriteContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.io.IOException;
1010

11+
@ApiStatus.NonExtendable
1112
public interface WriteContext {
1213
@ApiStatus.Internal
1314
static WriteContext of(TypeAdapters typeAdapters, FormatUtils<?> formatUtils) {

0 commit comments

Comments
 (0)