Hello I'll need some help to reduce the execution time of this 2 methods
andCode:/**
*
* @param textData text where the words will be replaced
* @param designations List<Map<String, String>> containing the words to be replaced and is replacement
* @return
*/
private String createConceptLinks(final String textData, final List<Map<String, String>> designations) {
String retString = textData;
for(Map<String, String> map : designations){
retString = replaceForLink(retString, map.get("designation"), map.get("replacement"));
}
return retString;
}
this runs on a avg of 188ms. the thing is that I run it 100 times, so the total runing time is 18800ms which is a lot :(.Code:private String replaceForLink(final String text, final String word, final String replacement) {
String newText = text;
if(newText.toUpperCase(Constants.LOCALE_PT).contains(word.toUpperCase(Constants.LOCALE_PT))){
final Pattern pattern = Pattern.compile("(?:<([aA][A-Za-z0-9/=\\\":]*)[^>]*>)[�“\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\=\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\s\\w]*[�“\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\=\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\s\\w\\s\\w]*</[Aa\\s]*>|[a-zA-Z[&[a-z]+;]]+"+word+"[a-zA-Z[&[a-z]+;]]+|[a-zA-Z[&[a-z]+;]]*"+word+"[a-zA-Z[&[a-z]+;]]+|[a-zA-Z[&[a-z]+;]]+"+word+"[a-zA-Z[&[a-z]+;]]*",Pattern.CASE_INSENSITIVE);
final Pattern pattern3 = Pattern.compile(word, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(newText);
final List<String> list = new ArrayList<String>();
while (matcher.find()) {
list.add(matcher.group());
}
int i = 0;
final String key1 = String.valueOf(new Date().getTime());
for(String string : list){
newText = newText.replaceFirst(string.replaceAll("\\?", "\\\\?"), "{"+key1+i+"}");
i++;
}
final List<String> list3 = new ArrayList<String>();
matcher = pattern3.matcher(newText);
while (matcher.find()) {
list3.add(matcher.group());
}
i=0;
for(String string : list3){
newText = newText.replaceFirst(string, replacement.replaceAll("@word@", string));
i++;
}
i = 0;
for(String string : list){
newText=newText.replaceFirst("\\{"+key1+i+"\\}", string);
i++;
}
}
return newText;
}
can anyone give-me a alternative assuming that i need to run it 100times

