String[] groups = currentValue.split("\\s+"); int ignore = groups.length - 1; String targetGroup = groups[ignore]; StringBuffer prefix = new StringBuffer(); for (int i = 0; i < ignore; i++) { prefix.append(groups[i]).append(' '); }
    public static Collection getAutoCompleteCandidates(Collection namedItems, String currentValue) {        if (StringUtils.isBlank(currentValue) || currentValue.endsWith(" ")) {            return Collections.EMPTY_LIST;        }                String[] groups = currentValue.split("\\s+");        int ignore = groups.length - 1;        String targetGroup = groups[ignore];        StringBuffer prefix = new StringBuffer();        for (int i = 0; i < ignore; i++) {            prefix.append(groups[i]).append(' ');        }        List candidates = new ArrayList();        for (Iterator i = namedItems.iterator(); i.hasNext();) {            NamedObject candidate = (NamedObject) i.next();            if (candidate.getName().startsWith(targetGroup)) {                candidates.add(prefix.toString() + candidate.getName());            }                       }        return candidates;            }