private ValidationResult _mergeListInternalForKey ( String key , JSONArray left , JSONArray right , boolean remove , ValidationResult vr ) { if ( left == null ) { vr . setObject ( null ) ; return vr ; } if ( right == null ) { vr . setObject ( left ) ; return vr ; } int maxValNum = Constants . MAX_MULTI_VALUE_ARRAY_LENGTH ; JSONArray mergedList = new JSONArray ( ) ; HashSet < String > set = new HashSet <> ( ) ; int lsize = left . length ( ) , rsize = right . length ( ) ; BitSet dupSetForAdd = null ; if ( ! remove ) dupSetForAdd = new BitSet ( lsize + rsize ) ; int lidx = 0 ; int ridx = scan ( right , set , dupSetForAdd , lsize ) ; if ( ! remove && set . size ( ) < maxValNum ) { lidx = scan ( left , set , dupSetForAdd , 0 ) ; } for ( int i = lidx ; i < lsize ; i ++ ) { try { if ( remove ) { String _j = ( String ) left . get ( i ) ; if ( ! set . contains ( _j ) ) { mergedList . put ( _j ) ; } } else if ( ! dupSetForAdd . get ( i ) ) { mergedList . put ( left . get ( i ) ) ; } } catch ( Throwable t ) { //no-op } } if ( ! remove && mergedList . length ( ) < maxValNum ) { for ( int i = ridx ; i < rsize ; i ++ ) { try { if ( ! dupSetForAdd . get ( i + lsize ) ) { mergedList . put ( right . get ( i ) ) ; } } catch ( Throwable t ) { //no-op } } } // check to see if the list got trimmed in the merge if ( ridx > 0 || lidx > 0 ) { vr . setErrorDesc ( "Multi value property for key " + key + " exceeds the limit of " + maxValNum + " items. Trimmed" ) ; vr . setErrorCode ( 521 ) ; } vr . setObject ( mergedList ) ; return vr ; }
scans right to left until max to maintain latest max values for the multi - value property specified by key .