-
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
9eea730
commit c7bdc3d
Showing
2 changed files
with
60 additions
and
10 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,5 +1,22 @@ | ||
package practice; | ||
|
||
public class CandidateValidator { | ||
//write your code here | ||
import java.util.function.Predicate; | ||
import model.Candidate; | ||
|
||
public class CandidateValidator implements Predicate<Candidate> { | ||
private static final int MIN_AGE = 35; | ||
private static final int MIN_YEARS_IN_UKRAINE = 10; | ||
private static final String NATIONALITY = "Ukrainian"; | ||
private static final int FROM_YEAR_INDEX = 0; | ||
private static final int TO_YEAR_INDEX = 1; | ||
private static final String LINE_SEPARATOR = "-"; | ||
|
||
public boolean test (Candidate candidate) { | ||
String[] period = candidate.getPeriodsInUkr().split(LINE_SEPARATOR); | ||
int yearsInUkraine = Integer.parseInt(period[TO_YEAR_INDEX]) | ||
- Integer.parseInt(period[FROM_YEAR_INDEX]); | ||
return candidate.getAge() >= MIN_AGE && candidate.isAllowedToVote() | ||
&& candidate.getNationality().equals(NATIONALITY) | ||
&& yearsInUkraine >= 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