-
Notifications
You must be signed in to change notification settings - Fork 3
Remove unused methods and improve functionality in core classes #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c30a10f
d6565fc
74808e0
8d77269
479cc70
c7c8362
28e12b3
3d16a70
d4dbc9e
df9343a
214b5a9
47db958
89883f0
734a3bd
a66c154
c3b0e11
4512c3d
7bf14ca
2d0851a
06feff8
56f8352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,8 @@ | |
| public class Schema { | ||
| private final DataVersion version; | ||
| private final Schema parent; | ||
| private TypeRegistry types; | ||
| private volatile TypeRegistry types; | ||
| private TypeRegistry buildingTypes; | ||
|
|
||
| /** | ||
| * Creates a new schema for the specified version with the given types. | ||
|
|
@@ -161,10 +162,17 @@ public Schema parent() { | |
| */ | ||
| @NotNull | ||
| public TypeRegistry types() { | ||
| if (this.types == null) { | ||
| this.types = this.buildTypes(); | ||
| TypeRegistry result = this.types; | ||
| if (result == null) { | ||
| synchronized (this) { | ||
| result = this.types; | ||
| if (result == null) { | ||
| result = this.buildTypes(); | ||
| this.types = result; | ||
| } | ||
| } | ||
| } | ||
| return this.types; | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -178,18 +186,22 @@ public TypeRegistry types() { | |
| @NotNull | ||
| private TypeRegistry buildTypes() { | ||
| final TypeRegistry registry = this.createTypeRegistry(); | ||
| this.types = registry; | ||
| this.buildingTypes = registry; | ||
|
|
||
| // Inherit types from parent if present | ||
| if (this.parent != null) { | ||
| // Copy types from parent | ||
| this.parent.types(); | ||
| // Parent types are already registered in parent's registry | ||
| // For now, we don't copy - subclass must re-register all types it needs | ||
| final TypeRegistry parentTypes = this.parent.types(); | ||
| for (final TypeReference ref : parentTypes.references()) { | ||
| final Type<?> parentType = parentTypes.get(ref); | ||
| if (parentType != null) { | ||
| registry.register(parentType); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Let subclass register types | ||
| this.registerTypes(); | ||
| this.buildingTypes = null; | ||
|
|
||
|
Comment on lines
187
to
205
|
||
| return registry; | ||
| } | ||
|
|
@@ -232,8 +244,9 @@ protected void registerTypes() { | |
| */ | ||
| protected final void registerType(@NotNull final Type<?> type) { | ||
| Preconditions.checkNotNull(type, "type must not be null"); | ||
| Preconditions.checkState(this.types != null, "Cannot register types before types() is called"); | ||
| this.types.register(type); | ||
| final TypeRegistry registry = this.buildingTypes; | ||
| Preconditions.checkState(registry != null, "Cannot register types outside of registerTypes()"); | ||
| registry.register(type); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -267,13 +280,14 @@ protected final void registerType(@NotNull final TypeReference reference, | |
| @NotNull final TypeTemplate template) { | ||
| Preconditions.checkNotNull(reference, "reference must not be null"); | ||
| Preconditions.checkNotNull(template, "template must not be null"); | ||
| Preconditions.checkState(this.types != null, "Cannot register types before types() is called"); | ||
| final TypeRegistry registry = this.buildingTypes; | ||
| Preconditions.checkState(registry != null, "Cannot register types outside of registerTypes()"); | ||
|
|
||
| // Apply the template with an empty family to get the concrete type | ||
| final Type<?> templateType = template.apply(TypeFamily.empty()); | ||
|
|
||
| // Wrap the template type with the reference | ||
| this.types.register(new TemplateBasedType<>(reference, templateType)); | ||
| registry.register(new TemplateBasedType<>(reference, templateType)); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -384,7 +384,8 @@ public <T> DataResult<Typed<A>> updateDynamic(@NotNull final DynamicOps<T> ops, | |
| * @param ops the dynamic operations for encoding, must not be {@code null} | ||
| * @param finder the finder that locates the desired sub-value, must not be {@code null} | ||
| * @param <T> the underlying data format type | ||
| * @return a {@link DataResult} containing the found dynamic value or {@code null} if not found, never {@code null} | ||
| * @return a {@link DataResult} containing the found dynamic value on success, or an error result if the path | ||
| * was not found; never {@code null} | ||
| * @throws NullPointerException if {@code ops} or {@code finder} is {@code null} | ||
| * @see #updateAt(DynamicOps, Finder, Function) | ||
| */ | ||
|
|
@@ -393,12 +394,12 @@ public <T> DataResult<Dynamic<T>> getAt(@NotNull final DynamicOps<T> ops, | |
| @NotNull final Finder<?> finder) { | ||
| Preconditions.checkNotNull(ops, "ops must not be null"); | ||
| Preconditions.checkNotNull(finder, "finder must not be null"); | ||
| return encode(ops).map(dynamic -> { | ||
| return encode(ops).flatMap(dynamic -> { | ||
| final Dynamic<?> found = finder.get(dynamic); | ||
| if (found == null) { | ||
| return null; | ||
| return DataResult.error("Path not found: " + finder); | ||
| } | ||
| return found.convert(ops); | ||
| return DataResult.success(found.convert(ops)); | ||
|
Comment on lines
+397
to
+402
|
||
| }); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Javadoc for
Finder.index(...)says negative indices causeget()to returnnull, but the method now throwsIllegalArgumentExceptionat construction time forindex < 0. Please update the Javadoc to reflect the new contract (and clarify that only out-of-range positive indices returnnull/leave root unchanged).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback