The following is a quickly thrown together method that will return the accepted answer percentage of the user with the given ID.
Note: This is using some code that will be available in the next release. Notice how it dramatically reduces complexity, and the length of code.
public static double getAcceptedAnswerPercentage(StackWrapper sw, int userId)
throws JSONException, IOException, ParameterNotSetException {
int acceptedCount = 0;
int answerCount = 0;
List<Answer> answers = new AnswerFromUserList(sw, (AnswerQuery) new AnswerQuery()
.setIds(userId));
for (Answer a : answers) {
answerCount++;
if (a.isIsAccepted())
acceptedCount++;
}
return acceptedCount / (double) answerCount;
}
Are you tired of manually paging queries? We were too. Introducing the AutoFetchList
!!
The class AutoFetchList
will automatically pull the next pages as needed. Looks like a list, acts like a list...must be a list. Just throw it a Query and it will take care of the paging for you.