Skip to content

Instantly share code, notes, and snippets.

@mgenov
Created July 1, 2011 08:56
Show Gist options
  • Save mgenov/1058121 to your computer and use it in GitHub Desktop.
Save mgenov/1058121 to your computer and use it in GitHub Desktop.
Sourcing Sample
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