Expanded the number of candidates from 5 to 10-15
This commit is contained in:
1315
logs/Voting.log
1315
logs/Voting.log
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,6 @@ import javax.annotation.PostConstruct;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
public class VotingController {
|
||||
|
||||
@@ -71,12 +71,8 @@ public class TableAction {
|
||||
authCodesRepository.delete(authCodesRepository.findByName(name));
|
||||
}
|
||||
|
||||
private boolean fiveMinutesPassed(Long time){
|
||||
return System.currentTimeMillis() >= (time + 300*1000);
|
||||
}
|
||||
|
||||
private int getLimit(List<PossibleCandidate> possibleCandidates){
|
||||
return possibleCandidates.size() <= 5 ? possibleCandidates.size() : 5;
|
||||
return possibleCandidates.size() <= 15 ? possibleCandidates.size() : 15;
|
||||
}
|
||||
|
||||
public void voteForCandidate(String id, CandidateRepository candidateRepository){
|
||||
@@ -123,9 +119,18 @@ public class TableAction {
|
||||
Collections.sort(possibleCandidatesPerCategory, Comparator.comparing(PossibleCandidate::getVotes));
|
||||
Collections.reverse(possibleCandidatesPerCategory);
|
||||
for (int j = 0; j < getLimit(possibleCandidatesPerCategory); j++){
|
||||
if (j >= 10 && possibleCandidatesPerCategory.get(j).getVotes() == possibleCandidatesPerCategory.get(j-1).getVotes()){
|
||||
Candidate candidate = new Candidate(possibleCandidatesPerCategory.get(j).getName(), possibleCandidatesPerCategory.get(j).getCategory());
|
||||
candidateRepository.save(candidate);
|
||||
}
|
||||
if (j < 10){
|
||||
Candidate candidate = new Candidate(possibleCandidatesPerCategory.get(j).getName(), possibleCandidatesPerCategory.get(j).getCategory());
|
||||
candidateRepository.save(candidate);
|
||||
}
|
||||
if (j == 14){
|
||||
break;
|
||||
}
|
||||
}
|
||||
i += -1;
|
||||
possibleCandidatesPerCategory.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user