diff --git a/src/main/java/practice/CandidateValidator.java b/src/main/java/practice/CandidateValidator.java index 0313eb98..92a7d030 100644 --- a/src/main/java/practice/CandidateValidator.java +++ b/src/main/java/practice/CandidateValidator.java @@ -6,18 +6,15 @@ import model.Candidate; public class CandidateValidator implements Predicate { - // National for being candidate - private static final String neededNational = "Ukrainian"; - // Minimum required age for being candidate - private static final int neededAge = 35; - // Minimum required years for being candidate - private static final int neededPeriod = 10; + private static final String requirementNationality = "Ukrainian"; + private static final int requirementAge = 35; + private static final int requirementPeriodInUkr = 10; @Override public boolean test(Candidate candidate) { if (candidate == null - || !candidate.getNationality().equals(neededNational) - || candidate.getAge() < neededAge + || !candidate.getNationality().equals(requirementNationality) + || candidate.getAge() < requirementAge || !candidate.isAllowedToVote()) { return false; } @@ -27,7 +24,7 @@ public boolean test(Candidate candidate) { .map(Integer::valueOf) .toList(); if (periodInUkraine.size() != 2 - || periodInUkraine.get(1) - periodInUkraine.get(0) < neededPeriod) { + || periodInUkraine.get(1) - periodInUkraine.get(0) < requirementPeriodInUkr) { return false; } } catch (NumberFormatException | IndexOutOfBoundsException e) { diff --git a/src/main/java/practice/StreamPractice.java b/src/main/java/practice/StreamPractice.java index 5551dc41..cb1832f0 100644 --- a/src/main/java/practice/StreamPractice.java +++ b/src/main/java/practice/StreamPractice.java @@ -73,10 +73,11 @@ public List getWorkablePeople(int fromAge, int femaleToAge, int maleToAge, List peopleList) { return peopleList.stream() - .filter(p -> p.getAge() >= fromAge) - .filter((p -> (p.getSex() == Person.Sex.WOMAN && p.getAge() <= femaleToAge) - || (p.getSex() == Person.Sex.MAN && p.getAge() <= maleToAge))) - .collect(Collectors.toList()); + .filter(person -> person.getAge() >= fromAge) + .filter(person -> (person.getSex() == Person.Sex.WOMAN + && person.getAge() <= femaleToAge + || person.getSex() == Person.Sex.MAN && person.getAge() <= maleToAge)) + .toList(); } /** @@ -87,14 +88,14 @@ public List getWorkablePeople(int fromAge, int femaleToAge, public List getCatsNames(List peopleList, int femaleAge) { return peopleList.stream() - .filter(p -> p.getSex() == Person.Sex.WOMAN) - .filter(p -> p.getAge() >= femaleAge) - .flatMap(c -> c.getCats().stream()) + .filter(person -> person.getSex() == Person.Sex.WOMAN) + .filter(person -> person.getAge() >= femaleAge) + .flatMap(cat -> cat.getCats().stream()) .map(Cat::getName) - .collect(Collectors.toList()); + .toList(); } - /** V - wtf MA, wrong article + /** * Your help with a election is needed. Given list of candidates, where each element * has Candidate.class type. * Check which candidates are eligible to apply for president position and return their @@ -112,6 +113,6 @@ public List validateCandidates(List candidates) { .filter(new CandidateValidator()) .map(Candidate::getName) .sorted() - .collect(Collectors.toList()); + .toList(); } }