-
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.
added 3 predicates and new class, reworked existing person predicate
- Loading branch information
1 parent
9e6e0fd
commit a827107
Showing
3 changed files
with
56 additions
and
18 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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package practice; | ||
|
||
import java.util.function.Predicate; | ||
import model.Person; | ||
|
||
public class PersonValidator { | ||
public static Predicate<Person> isManBetweenAges(int fromAge, int toAge) { | ||
return p -> p.getSex() == Person.Sex.MAN | ||
&& p.getAge() >= fromAge | ||
&& p.getAge() <= toAge; | ||
} | ||
|
||
public static Predicate<Person> selectPeopleByAge(int fromAge, int maleToAge, int femaleToAge) { | ||
Predicate<Person> isManBetweenAges = PersonValidator.isManBetweenAges(fromAge, maleToAge); | ||
|
||
return p -> { | ||
int ageLimit = (p.getSex() == Person.Sex.MAN) ? maleToAge : femaleToAge; | ||
return p.getAge() >= fromAge && p.getAge() <= ageLimit; | ||
}; | ||
} | ||
|
||
public static Predicate<Person> isElderlyWoman(int femaleAge) { | ||
return p -> p.getSex() == Person.Sex.WOMAN && p.getAge() >= femaleAge; | ||
} | ||
} | ||
|
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