Commit b55f2bf1 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Make use of isEmpty instead of checking size

parent 117f630a
......@@ -1044,7 +1044,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
view.setKey(questionId);
view.setGroup(true);
final ViewResults results = getDatabase().view(view);
if (results.getResults().size() == 0) {
if (results.getResults().isEmpty()) {
return 0;
}
return results.getJSONArray("rows").optJSONObject(0).optInt("value");
......@@ -1057,7 +1057,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
view.setStartKey(question.get_id(), String.valueOf(piRound));
view.setEndKey(question.get_id(), String.valueOf(piRound), "{}");
final ViewResults results = getDatabase().view(view);
if (results.getResults().size() == 0) {
if (results.getResults().isEmpty()) {
return 0;
}
......@@ -1071,7 +1071,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
view.setKey(question.get_id());
final ViewResults results = getDatabase().view(view);
if (results.getResults().size() == 0) {
if (results.getResults().isEmpty()) {
return 0;
}
......@@ -1079,7 +1079,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
}
private boolean isEmptyResults(final ViewResults results) {
return results == null || results.getResults().isEmpty() || results.getJSONArray("rows").size() == 0;
return results == null || results.getResults().isEmpty() || results.getJSONArray("rows").isEmpty();
}
@Override
......@@ -1137,7 +1137,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
final NovaView view = new NovaView("skill_question/count_answers_by_session");
view.setKey(s.get_id());
final ViewResults results = getDatabase().view(view);
if (results.getResults().size() == 0) {
if (results.getResults().isEmpty()) {
return 0;
}
return results.getJSONArray("rows").optJSONObject(0).optInt("value");
......@@ -1154,7 +1154,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
view.setKey(s.get_id());
view.setGroup(true);
final ViewResults results = getDatabase().view(view);
if (results.size() == 0 || results.getResults().size() == 0) {
if (results.isEmpty() || results.getResults().isEmpty()) {
return 0;
}
return results.getJSONArray("rows").optJSONObject(0).optInt("value");
......@@ -1180,7 +1180,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
private InterposedReadingCount getInterposedReadingCount(final NovaView view) {
final ViewResults results = getDatabase().view(view);
if (results.size() == 0 || results.getResults().size() == 0) {
if (results.isEmpty() || results.getResults().isEmpty()) {
return new InterposedReadingCount();
}
// A complete result looks like this. Note that the second row is optional, and that the first one may be
......@@ -1746,7 +1746,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
count[2] += qaCount[1];
}
if (results.size() > 0) {
if (!results.isEmpty()) {
logger.info("Deleted {} inactive guest sessions.", results.size());
log("cleanup", "type", "session", "sessionCount", results.size(), "questionCount", count[1], "answerCount", count[2]);
}
......@@ -1777,7 +1777,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
log("delete", "type", "user", "id", oldDoc.getId());
}
if (newDocs.size() > 0) {
if (!newDocs.isEmpty()) {
if (getDatabase().bulkSaveDocuments(newDocs.toArray(new Document[newDocs.size()]))) {
count += newDocs.size();
} else {
......@@ -1918,7 +1918,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
final NovaView view = new NovaView("skill_question/count_answers_by_session_and_question_variant");
view.setKey(session.get_id(), variant);
final ViewResults results = getDatabase().view(view);
if (results.getResults().size() == 0) {
if (results.getResults().isEmpty()) {
return 0;
}
return results.getJSONArray("rows").optJSONObject(0).optInt("value");
......@@ -2016,7 +2016,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
private List<String> collectQuestionIds(final NovaView view) {
final ViewResults results = getDatabase().view(view);
if (results.getResults().size() == 0) {
if (results.getResults().isEmpty()) {
return new ArrayList<>();
}
final List<String> ids = new ArrayList<>();
......@@ -2527,7 +2527,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
}
for (ImportExportQuestion question : importExportSession.getQuestions()) {
numAnswers += question.getAnswers().size();
if (question.getAnswers().size() == 0) {
if (question.getAnswers().isEmpty()) {
numUnanswered++;
}
}
......
......@@ -57,7 +57,7 @@ public class QuestionScore implements Iterable<UserScore> {
}
public boolean hasScores() {
return this.userScores.size() > 0;
return !this.userScores.isEmpty();
}
public void add(int piRound, String username, int userscore) {
......
......@@ -153,7 +153,7 @@ public class UserService implements IUserService {
@Scheduled(fixedDelay = LOGIN_TRY_RESET_DELAY_MS)
public void resetLoginTries() {
if (loginTries.size() > 0) {
if (!loginTries.isEmpty()) {
logger.debug("Reset failed login counters.");
loginTries.clear();
}
......@@ -161,7 +161,7 @@ public class UserService implements IUserService {
@Scheduled(fixedDelay = LOGIN_BAN_RESET_DELAY_MS)
public void resetLoginBans() {
if (loginBans.size() > 0) {
if (!loginBans.isEmpty()) {
logger.info("Reset temporary login bans.");
loginBans.clear();
}
......@@ -415,7 +415,7 @@ public class UserService implements IUserService {
List<String> domainList = Arrays.asList(allowedEmailDomains.split(","));
if (domainList.size() > 0) {
if (!domainList.isEmpty()) {
List<String> patterns = new ArrayList<>();
if (domainList.contains("*")) {
patterns.add("([a-z0-9-]+\\.)+[a-z0-9-]+");
......
......@@ -437,7 +437,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor {
}
/* TODO role handling implementation, send this only to users with role audience */
if (qs.size() > 0) {
if (!qs.isEmpty()) {
broadcastInSession(session.getKeyword(), "lecQuestionAvail", questions.get(0).get_id()); // deprecated!
}
broadcastInSession(session.getKeyword(), "lecturerQuestionAvailable", questions);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment