Implemented suggestions from Code Analysis
This commit is contained in:
-2
@@ -1,9 +1,7 @@
|
||||
package de.twomartens.wahlrecht.repository;
|
||||
|
||||
import de.twomartens.wahlrecht.model.db.ElectionResult;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
public interface ElectionResultRepository extends MongoRepository<ElectionResult, String> {
|
||||
Optional<ElectionResult> findByElectionName(String name);
|
||||
}
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package de.twomartens.wahlrecht.repository;
|
||||
|
||||
import de.twomartens.wahlrecht.model.db.VotingResult;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
public interface VotingResultRepository extends MongoRepository<VotingResult, String> {
|
||||
|
||||
}
|
||||
@@ -37,11 +37,10 @@ public class CalculationService {
|
||||
private final NominationService nominationService;
|
||||
private final ElectionService electionService;
|
||||
private final LinkedList<Double> electionNumberHistory = new LinkedList<>();
|
||||
private StopWatch stopWatch;
|
||||
|
||||
public ElectedCandidates determineElectedCandidates(@NonNull ElectionResult electionResult) {
|
||||
log.info("Calculate election result for election {}", electionResult.electionName());
|
||||
stopWatch = new StopWatch();
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start("determineElectedCandidates");
|
||||
Election election = electionService.getElectionInternal(electionResult.electionName());
|
||||
SeatResult seatResult = calculateOverallSeatDistribution(election,
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package de.twomartens.wahlrecht.service;
|
||||
|
||||
import de.twomartens.wahlrecht.mapper.v1.ConstituencyMapper;
|
||||
import de.twomartens.wahlrecht.model.db.Constituency;
|
||||
import de.twomartens.wahlrecht.model.internal.ConstituencyId;
|
||||
import de.twomartens.wahlrecht.repository.ConstituencyRepository;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -18,23 +15,9 @@ import org.springframework.stereotype.Service;
|
||||
public class ConstituencyService {
|
||||
|
||||
private final ConstituencyRepository repository;
|
||||
private final ConstituencyMapper mapper = Mappers.getMapper(ConstituencyMapper.class);
|
||||
|
||||
private Map<ConstituencyId, Constituency> constituencies;
|
||||
|
||||
public Collection<Constituency> getConstituencies() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public Constituency getConstituency(ConstituencyId constituencyId) {
|
||||
return constituencies.get(constituencyId);
|
||||
}
|
||||
|
||||
public de.twomartens.wahlrecht.model.internal.Constituency getConstituencyInternal(
|
||||
ConstituencyId constituencyId) {
|
||||
return mapper.mapToInternal(getConstituency(constituencyId));
|
||||
}
|
||||
|
||||
public Constituency storeConstituency(@NonNull Constituency constituency) {
|
||||
if (constituencies == null) {
|
||||
fetchConstituencies();
|
||||
|
||||
@@ -32,20 +32,6 @@ public class PartyService {
|
||||
return parties;
|
||||
}
|
||||
|
||||
public PartyInElection getPartyByElectionNameAndAbbreviation(String electionName,
|
||||
String abbreviation) {
|
||||
if (parties == null) {
|
||||
fetchParties();
|
||||
}
|
||||
PartyId partyId = new PartyId(electionName, abbreviation);
|
||||
PartyInElection party = parties.get(partyId);
|
||||
if (party == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND,
|
||||
"no party found for %s and %s".formatted(electionName, abbreviation));
|
||||
}
|
||||
return party;
|
||||
}
|
||||
|
||||
public boolean storeParty(PartyInElection partyInElection) {
|
||||
if (parties == null) {
|
||||
fetchParties();
|
||||
|
||||
Reference in New Issue
Block a user