24
24
import java .util .Map ;
25
25
import java .util .Optional ;
26
26
import java .util .function .Function ;
27
-
28
27
import software .amazon .awssdk .annotations .SdkPublicApi ;
29
28
import software .amazon .awssdk .enhanced .dynamodb .AttributeConverter ;
30
29
import software .amazon .awssdk .enhanced .dynamodb .EnhancedType ;
@@ -255,9 +254,12 @@ public StaticPolymorphicTableSchema<T> build() {
255
254
}
256
255
}
257
256
258
- // Sort subtypes: deeper (more specific) before shallower
257
+ // Sort subtypes so that deeper subclasses (more specific) are checked first by resolveByInstance.
259
258
List <StaticSubtype <? extends T >> ordered = new ArrayList <>(staticSubtypes );
260
- sortSubtypesMostSpecificFirst (ordered , root );
259
+ ordered .sort ((first , second ) -> Integer .compare (
260
+ inheritanceDepthFromRoot (second .tableSchema ().itemType ().rawClass (), root ),
261
+ inheritanceDepthFromRoot (first .tableSchema ().itemType ().rawClass (), root )
262
+ ));
261
263
262
264
return new StaticPolymorphicTableSchema <>(
263
265
rootTableSchema ,
@@ -269,18 +271,9 @@ public StaticPolymorphicTableSchema<T> build() {
269
271
}
270
272
271
273
/**
272
- * Orders subtypes so that deeper subclasses (more specific) are checked first by resolveByInstance.
273
- */
274
- private static <T > void sortSubtypesMostSpecificFirst (List <StaticSubtype <? extends T >> subs , Class <?> root ) {
275
- subs .sort ((first , second ) -> Integer .compare (
276
- inheritanceDepthFromRoot (second .tableSchema ().itemType ().rawClass (), root ),
277
- inheritanceDepthFromRoot (first .tableSchema ().itemType ().rawClass (), root )
278
- ));
279
- }
280
-
281
- /**
282
- * Counts how many superclass steps it takes to reach the given root. Example: if Manager extends Employee extends Person
283
- * (root), then Manager → depth 2, Employee → depth 1, Person → depth 0.
274
+ * Counts how many superclass steps it takes to reach the given root.
275
+ * Example: if Manager extends Employee extends Person (root), then:
276
+ * Manager → depth 2, Employee → depth 1, Person → depth 0.
284
277
*/
285
278
private static int inheritanceDepthFromRoot (Class <?> type , Class <?> root ) {
286
279
int depth = 0 ;
0 commit comments