package uk.ac.ebi.quickgo.annotation.model;

import uk.ac.ebi.quickgo.annotation.service.search.SearchConfig;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Modify filter values for references.
 *
 *
 * @author Tony Wardell
 * Date: 24/05/2016
 * Time: 17:25
 * Created with IntelliJ IDEA.
 */
public class ReferenceModifier implements FilterModifier{

    private static final Pattern ALL_NUMERIC = Pattern.compile("\\d*");
    private final SearchConfig searchConfig;

    @Autowired
    public ReferenceModifier(SearchConfig searchConfig) {
        this.searchConfig = searchConfig;
    }

    public String[] modify(String[] original){
        Set<String> modifiedArgs = new LinkedHashSet<>();
        for (int i = 0; i < original.length; i++) {

            //If given just a Database identifier, make it a wildcard search
            if( searchConfig.referenceDbs.contains(original[i]) ){
                modifiedArgs.add(original[i]+":*");
            } else {

                //If we have just an id, create a request for all known DBs
                Matcher m = ALL_NUMERIC.matcher(original[i]);
                if (m.matches()) {
                    for (String db : searchConfig.referenceDbs)
                        modifiedArgs.add(db + ":" + original[i]);
                } else {
                    modifiedArgs.add(original[i]);
                }
            }
        }
        return modifiedArgs.toArray(new String[modifiedArgs.size()]);
    }
}

@@ -188,16 +188,52 @@
 attern;%0A
+import java.util.stream.Collectors;%0A
 import o
@@ -288,16 +288,67 @@
 wired;%0A%0A
+import static java.util.stream.Collectors.toList;%0A%0A
 /**%0A * M
@@ -1655,10 +1655,414 @@
 ;%0A    %7D%0A
+%0A%0A    public String%5B%5D modify2(String%5B%5D original)%7B%0A        List%3CString%3E modifiedArgs = new ArrayList%3C%3E();%0A%0A        Arrays.stream(original)%0A                .distinct()%0A                .filter(arg -%3E searchConfig.referenceDbs.contains(arg))%0A                .map(arg -%3E arg+%22:*%22)%0A                .forEach(modifiedArgs::add);%0A%0A%0A%0A%0A        return modifiedArgs.toArray(new String%5BmodifiedArgs.size()%5D);%0A    %7D%0A%0A%0A%0A
 %7D%0A

Add alternate method using streams.