List of usage examples for java.util Set toArray
<T> T[] toArray(T[] a);
From source file:hugonicolau.openbrailleinput.wordcorrection.mafsa.MAFSA.java
public String[] searchPrefix(String prefix) { Set<String> results = new HashSet<String>(); if ((prefix == null) || (prefix.length() < 2)) return results.toArray(new String[results.size()]); char[] letters = prefix.toUpperCase().toCharArray(); long ptr = nodes[0]; for (char c : letters) { ptr = findChild(ptr, c);//from w w w.j a va 2 s. c o m if (-1 == ptr) return results.toArray(new String[results.size()]); } // iteratively (to prevent stack overflow) search each branch of the graph Stack<StackEntry> stack = new Stack<StackEntry>(); // a stack of paths to traverse. This prevents the StackOverflowException. stack.push(new StackEntry(ptr, prefix.toUpperCase().toCharArray(), "")); while (!stack.empty()) { StackEntry entry = stack.pop(); // if current node is a valid word if (canTerminate(entry.node)) { results.add(String.valueOf(entry.chars) + entry.subword); } for (Iterator<Long> iter = childIterator(entry.node); iter.hasNext();) { long child = iter.next(); stack.push(new StackEntry(child, entry.chars, entry.subword + getChar(child))); } } return results.toArray(new String[results.size()]); }
From source file:com.marvelution.jira.plugins.hudson.streams.HudsonStreamsActivityProvider.java
/** * Get a single {@link Project} from the Standard Streams Filter * //from www. j av a 2 s. co m * @param activityRequest the {@link ActivityRequest} * @return the {@link Project}, may be <code>null</code> */ private Project getProjectFromFilter(ActivityRequest activityRequest) { Set<String> keys = Filters .getIsValues(activityRequest.getStandardFilters().get(StandardStreamsFilterOption.PROJECT_KEY)); if (keys != null && keys.size() == 1) { try { return projectManager.getProjectObjByKey(keys.toArray(new String[keys.size()])[0]); } catch (Exception e) { // Ignore this. Just invalid configuration } } return null; }