File tree 2 files changed +64
-1
lines changed
main/java/org/metafacture/metafix
test/java/org/metafacture/metafix
2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -484,7 +484,18 @@ private Set<Integer> findFields(final String pattern) {
484
484
indexes ().forEach (fieldSet ::add );
485
485
}
486
486
else {
487
- final int index = Integer .parseInt (pattern ) - 1 ; // TODO: 0-based Catmandu vs. 1-based Metafacture
487
+ final int index ;
488
+
489
+ switch (pattern ) {
490
+ case "$first" :
491
+ index = 0 ;
492
+ break ;
493
+ case "$last" :
494
+ index = size () - 1 ;
495
+ break ;
496
+ default :
497
+ index = Integer .parseInt (pattern ) - 1 ; // TODO: 0-based Catmandu vs. 1-based Metafacture
498
+ }
488
499
489
500
if (index >= 0 && index < size ()) {
490
501
fieldSet .add (index );
Original file line number Diff line number Diff line change @@ -2418,6 +2418,58 @@ public void retainNested() {
2418
2418
);
2419
2419
}
2420
2420
2421
+ @ Test
2422
+ public void retainNestedReservedFields () {
2423
+ MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
2424
+ "retain('b[].$first.b','c[].$last')"
2425
+ ),
2426
+ i -> {
2427
+ i .startRecord ("1" );
2428
+ i .startEntity ("b[]" );
2429
+ i .startEntity ("1" );
2430
+ i .literal ("a" , "1" );
2431
+ i .literal ("b" , "2" );
2432
+ i .endEntity ();
2433
+ i .startEntity ("2" );
2434
+ i .literal ("a" , "1" );
2435
+ i .literal ("b" , "2" );
2436
+ i .literal ("c" , "3" );
2437
+ i .endEntity ();
2438
+ i .startEntity ("3" );
2439
+ i .literal ("c" , "4" );
2440
+ i .endEntity ();
2441
+ i .endEntity ();
2442
+ i .startEntity ("c[]" );
2443
+ i .startEntity ("1" );
2444
+ i .literal ("a" , "1" );
2445
+ i .literal ("b" , "2" );
2446
+ i .endEntity ();
2447
+ i .startEntity ("2" );
2448
+ i .literal ("a" , "1" );
2449
+ i .literal ("b" , "2" );
2450
+ i .literal ("c" , "3" );
2451
+ i .endEntity ();
2452
+ i .startEntity ("3" );
2453
+ i .literal ("c" , "4" );
2454
+ i .endEntity ();
2455
+ i .endEntity ();
2456
+ i .endRecord ();
2457
+ },
2458
+ (o , f ) -> {
2459
+ o .get ().startRecord ("1" );
2460
+ o .get ().startEntity ("b[]" );
2461
+ o .get ().startEntity ("1" );
2462
+ o .get ().literal ("b" , "2" );
2463
+ f .apply (2 ).endEntity ();
2464
+ o .get ().startEntity ("c[]" );
2465
+ o .get ().startEntity ("1" );
2466
+ o .get ().literal ("c" , "4" );
2467
+ f .apply (2 ).endEntity ();
2468
+ o .get ().endRecord ();
2469
+ }
2470
+ );
2471
+ }
2472
+
2421
2473
@ Test
2422
2474
public void shouldDeleteEmptyArrays () {
2423
2475
MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
You can’t perform that action at this time.
0 commit comments