-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4ac2e1
commit 03ea37f
Showing
2 changed files
with
24 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
package practice; | ||
|
||
import model.Candidate; | ||
import java.util.Arrays; | ||
import java.util.function.Predicate; | ||
import model.Candidate; | ||
|
||
public class CandidateValidator implements Predicate<Candidate> { | ||
private static final int MIN_AGE = 35; | ||
private static final String REQUIRED_NATIONALITY = "Ukrainian"; | ||
private static final String PERIOD_SEPARATOR = ","; | ||
private static final String YEAR_SEPARATOR = "-"; | ||
private static final int MIN_YEARS_IN_UKRAINE = 10; | ||
|
||
@Override | ||
public boolean test(Candidate candidate) { | ||
return candidate.getAge() >= 35 | ||
return candidate.getAge() >= MIN_AGE | ||
&& candidate.isAllowedToVote() | ||
&& "Ukrainian".equals(candidate.getNationality()) | ||
&& REQUIRED_NATIONALITY.equals(candidate.getNationality()) | ||
&& Arrays.stream(candidate.getPeriodsInUkr() | ||
.split(",")) | ||
.split(PERIOD_SEPARATOR)) | ||
.anyMatch(period -> { | ||
String[] years = period.split("-"); | ||
String[] years = period.split(YEAR_SEPARATOR); | ||
int startYear = Integer.parseInt(years[0]); | ||
int endYear = Integer.parseInt(years[1]); | ||
return endYear - startYear >= 10; | ||
return endYear - startYear >= MIN_YEARS_IN_UKRAINE; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters