Created
July 1, 2011 08:56
-
-
Save mgenov/1058121 to your computer and use it in GitHub Desktop.
Sourcing Sample
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
class Sample { | |
interface Source<T> { | |
T get(); | |
} | |
class WordsSource implements Source<List<Word>> { | |
private final Document document; | |
private final List<String> listOfWords; | |
public WordsSource(Document document, List<String> listOfWords) { | |
this.document = document; | |
this.listOfWords = listOfWords; | |
} | |
public List<Word> get() { | |
List<Word> words = document.getWords(); | |
return Lists.newArrayList(Iterables.filter(words, new Predicate<Word>() { | |
public boolean apply(Word word) { | |
if (listOfWords.contains(word.getText())) { | |
return true; | |
} | |
return false; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment