@ SuppressWarnings ( "unchecked" ) private void mergeResponsesArrayList ( ArrayList < Object > originalList , ArrayList < Object > shardList ) throws IOException { // get keys from original HashMap < String , Object > originalKeyList = new HashMap <> ( ) ; for ( Object item : originalList ) { if ( item instanceof NamedList < ? > ) { NamedList < Object > itemList = ( NamedList < Object > ) item ; Object key = itemList . get ( "key" ) ; if ( ( key != null ) && ( key instanceof String ) ) { originalKeyList . put ( ( String ) key , item ) ; } } } for ( Object item : shardList ) { if ( item instanceof NamedList < ? > ) { NamedList < Object > itemList = ( NamedList < Object > ) item ; Object key = itemList . get ( "key" ) ; // item with key if ( ( key != null ) && ( key instanceof String ) ) { // merge if ( originalKeyList . containsKey ( key ) ) { Object originalItem = originalKeyList . get ( key ) ; if ( originalItem . getClass ( ) . equals ( item . getClass ( ) ) ) { mergeResponsesNamedList ( ( NamedList < Object > ) originalItem , ( NamedList < Object > ) item ) ; } else { // ignore? } // add } else { Object clonedItem = adjustablePartsCloned ( item ) ; originalList . add ( clonedItem ) ; originalKeyList . put ( ( String ) key , clonedItem ) ; } } else { originalList . add ( item ) ; } } else { originalList . add ( item ) ; } } }
Merge responses array list .