@ Action ( name = "List Prepender" , outputs = { @ Output ( RESPONSE ) , @ Output ( RETURN_RESULT ) , @ Output ( RETURN_CODE ) } , responses = { @ Response ( text = SUCCESS , field = RETURN_CODE , value = RETURN_CODE_SUCCESS , matchType = MatchType . COMPARE_EQUAL ) , @ Response ( text = FAILURE , field = RETURN_CODE , value = RETURN_CODE_FAILURE , matchType = MatchType . COMPARE_EQUAL , isOnFail = true , isDefault = true ) } ) public Map < String , String > prependElement ( @ Param ( value = LIST , required = true ) String list , @ Param ( value = ELEMENT , required = true ) String element , @ Param ( value = DELIMITER ) String delimiter ) { Map < String , String > result = new HashMap <> ( ) ; try { StringBuilder sb = new StringBuilder ( ) ; sb = StringUtils . isEmpty ( list ) ? sb . append ( element ) : sb . append ( element ) . append ( delimiter ) . append ( list ) ; result . put ( RESPONSE , SUCCESS ) ; result . put ( RETURN_RESULT , sb . toString ( ) ) ; result . put ( RETURN_CODE , RETURN_CODE_SUCCESS ) ; } catch ( Exception e ) { result . put ( RESPONSE , FAILURE ) ; result . put ( RETURN_RESULT , e . getMessage ( ) ) ; result . put ( RETURN_CODE , RETURN_CODE_FAILURE ) ; } return result ; }
This method pre - pends an element to a list of strings .