public String replaceListTokens(String queryString,Map<String,Integer> numberOfReplacements,String replacement){
  Matcher matcher=tokenPattern.matcher(queryString);
  StringBuffer buf=new StringBuffer();
  while (matcher.find()) {
    String origToken=matcher.group(1);
    if (origToken != null) {
      matcher.appendReplacement(buf,"");
      Integer length=numberOfReplacements.get(origToken);
      if (length != null) {
        for (int i=0; i < length; i++) {
          buf.append(replacement);
          if (i != length - 1) {
            buf.append(", ");
          }
        }
      }
 else {
        buf.append("${" + origToken + "}");
      }
    }
  }
  matcher.appendTail(buf);
  return buf.toString();
}

public String replaceListTokens ( String queryString , Map < String , Integer > numberOfReplacements , String replacement ) { Matcher matcher = tokenPattern . matcher ( queryString ) ; StringBuffer buf = new StringBuffer ( ) ; while ( matcher . find ( ) ) { String origToken = matcher . group ( 1 ) ; if ( origToken != null ) { matcher . appendReplacement ( buf , "" ) ; Integer length = numberOfReplacements . get ( origToken ) ; if ( length != null ) { for ( int i = 0 ; i < length ; i ++ ) { buf . append ( replacement ) ; if ( i != length - 1 ) { buf . append ( ", " ) ; } } } else { buf . append ( "${" + origToken + "}" ) ; } } } matcher . appendTail ( buf ) ; return buf . toString ( ) ; }
replaces some tokens in a query string with tokens of format $ { token - name } where token - name represents a list of values . the numberofreplacements map tells how many replacements to produce ( comma - separated ) for each token . the replacement ( for all tokens ) is provided . tokens that have no replacement defined stay in the original token format .
