use of io.github.izzyleung.zhihudailypurify.bean.Question in project ZhihuDailyPurify by izzyleung.
the class NewsListFromZhihuObservable method getQuestions.
private static List<Question> getQuestions(Document document, String dailyTitle) {
List<Question> result = new ArrayList<>();
Elements questionElements = getQuestionElements(document);
for (Element questionElement : questionElements) {
Question question = new Question();
String questionTitle = getQuestionTitleFromQuestionElement(questionElement);
String questionUrl = getQuestionUrlFromQuestionElement(questionElement);
// Make sure that the question's title is not empty.
questionTitle = TextUtils.isEmpty(questionTitle) ? dailyTitle : questionTitle;
question.setTitle(questionTitle);
question.setUrl(questionUrl);
result.add(question);
}
return result;
}
use of io.github.izzyleung.zhihudailypurify.bean.Question in project ZhihuDailyPurify by izzyleung.
the class NewsListFromZhihuObservable method convertToDailyNews.
private static Optional<DailyNews> convertToDailyNews(Pair<Story, Document> pair) {
DailyNews result = null;
Story story = pair.first;
Document document = pair.second;
String dailyTitle = story.getDailyTitle();
List<Question> questions = getQuestions(document, dailyTitle);
if (Stream.of(questions).allMatch(Question::isValidZhihuQuestion)) {
result = new DailyNews();
result.setDailyTitle(dailyTitle);
result.setThumbnailUrl(story.getThumbnailUrl());
result.setQuestions(questions);
}
return Optional.ofNullable(result);
}
Aggregations