Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created July 23, 2009 20:23
Show Gist options
  • Save jaydonnell/153535 to your computer and use it in GitHub Desktop.
Save jaydonnell/153535 to your computer and use it in GitHub Desktop.
private List<String> itemsWithAllTokens(String phrase, Map<String, List<String>> map) {
List<String> tokens = tokenize(phrase);
List<String> items = map.get(tokens.get(0));
if (items == null) {
return new ArrayList<String>();
}
for (int i=1; i<tokens.size(); i++) {
List<String> tempListings = map.get(tokens.get(i));
if (tempListings == null) return new ArrayList<String>(); //As soon as we have a token with nothing in it, we can return an empty list...
List<String> toDelete = new ArrayList<String>();
for (int j=0; j<items.size(); j++) {
String l = items.get(j);
if (!tempListings.contains(l)) toDelete.add(l);
}
items.removeAll(toDelete);
}
return items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment