public String replaceTokensWithValues(String queryString,Map<String,Object> params) throws BadRequestException {
  java.util.regex.Matcher matcher=tokenPattern.matcher(queryString);
  StringBuffer buffer=new StringBuffer();
  while (matcher.find()) {
    String tokenKey=matcher.group(1);
    if (!params.containsKey(tokenKey)) {
      throw new BadRequestException("Missing entry in params passed to query for token " + tokenKey);
    }
 else {
      Object replacement=params.get(tokenKey);
      if (replacement instanceof List) {
        StringBuffer commaSeparated=new StringBuffer();
        boolean first=true;
        for (        Object entry : ((List)replacement)) {
          if (!first) {
            commaSeparated.append(",");
          }
 else {
            first=false;
          }
          commaSeparated.append(entry.toString());
        }
        replacement=commaSeparated.toString();
      }
      if (replacement == null) {
        replacement="";
      }
      matcher.appendReplacement(buffer,"");
      buffer.append(replacement);
    }
  }
  matcher.appendTail(buffer);
  return buffer.toString();
}

public String replaceTokensWithValues ( String queryString , Map < String , Object > params ) throws BadRequestException { java . util . regex . Matcher matcher = tokenPattern . matcher ( queryString ) ; StringBuffer buffer = new StringBuffer ( ) ; while ( matcher . find ( ) ) { String tokenKey = matcher . group ( 1 ) ; if ( ! params . containsKey ( tokenKey ) ) { throw new BadRequestException ( "Missing entry in params passed to query for token " + tokenKey ) ; } else { Object replacement = params . get ( tokenKey ) ; if ( replacement instanceof List ) { StringBuffer commaSeparated = new StringBuffer ( ) ; boolean first = true ; for ( Object entry : ( ( List ) replacement ) ) { if ( ! first ) { commaSeparated . append ( "," ) ; } else { first = false ; } commaSeparated . append ( entry . toString ( ) ) ; } replacement = commaSeparated . toString ( ) ; } if ( replacement == null ) { replacement = "" ; } matcher . appendReplacement ( buffer , "" ) ; buffer . append ( replacement ) ; } } matcher . appendTail ( buffer ) ; return buffer . toString ( ) ; }
replaces a query string with tokens of format $ { token - name } with the values from the passed in map , where the token - name must be the key in the map
