public void addTemplateId ( String id , Integer index ) throws HelloSignException { List < String > currentList = getList ( String . class , TEMPLATE_IDS ) ; if ( index == null ) { index = currentList . size ( ) ; } else if ( index < 0 ) { throw new HelloSignException ( "index cannot be negative" ) ; } else if ( index > currentList . size ( ) ) { throw new HelloSignException ( "index is greater than template ID list size: " + currentList . size ( ) ) ; } if ( index == currentList . size ( ) ) { add ( TEMPLATE_IDS , id ) ; // Just append the item } else { // Insert the item at the given index clearList ( TEMPLATE_IDS ) ; int limit = currentList . size ( ) ; // We'll be adding one for ( int i = 0 ; i < limit + 1 ; i ++ ) { if ( i == index ) { add ( TEMPLATE_IDS , id ) ; } if ( i < limit ) { add ( TEMPLATE_IDS , currentList . get ( i ) ) ; } } } }
Add the template ID to be used at the specified index .