Created
July 23, 2009 20:23
-
-
Save jaydonnell/153535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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