-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
done #1215
base: main
Are you sure you want to change the base?
done #1215
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this pull request! 😊 While your code meets most of the task requirements, there are a few critical issues that need to be addressed before we can approve it:
-
Age Comparison Logic: In the
selectMenByAge
method, ensure that the age comparison is inclusive for bothfromAge
andtoAge
. Changep.getAge() > fromAge
top.getAge() >= fromAge
to correctly include the lower bound as specified in the task description. -
Exception Message Formatting: The exception message in the
findMinEvenNumber
method should include a space after the colon, as specified in the checklist:"Can't get min value from list: " + numbers
. -
Use of Constants: In the
CandidateValidator
class, replace magic numbers and strings with constants to enhance readability and maintainability. Specifically, consider using constants for:- The minimum years lived in Ukraine (10).
- The nationality string ('Ukrainian').
- The age requirement (35).
Addressing these issues will help ensure your code is both functional and maintainable. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
|
||
@Override | ||
public boolean test(Candidate candidate) { | ||
if (candidate.getAge() < 35) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a constant for the age requirement (35) to improve code readability and maintainability. This aligns with the checklist item: 'Use constants. Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator.'
if (candidate.getAge() < 35) { | ||
return false; | ||
} | ||
if (!(candidate.getNationality().equals("Ukrainian"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a constant for the nationality string 'Ukrainian' to improve code readability and maintainability. This aligns with the checklist item: 'Use constants. Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator.'
} | ||
int start = Integer.parseInt(periods[0]); | ||
int finish = Integer.parseInt(periods[1]); | ||
return (finish - start) >= 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a constant for the minimum years lived in Ukraine (10) to improve code readability and maintainability. This aligns with the checklist item: 'Use constants. Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator.'
.sorted() | ||
.mapToInt(Integer::intValue) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException("Can't get min value from list:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception message should include a space after the colon, as specified in the checklist: "Can't get min value from list: " + numbers.
return Collections.emptyList(); | ||
return peopleList.stream() | ||
.filter(p -> p.getSex() == Person.Sex.MAN | ||
&& p.getAge() > fromAge && p.getAge() <= toAge) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The age comparison should be inclusive for both fromAge
and toAge
. Change p.getAge() > fromAge
to p.getAge() >= fromAge
to include the lower bound as specified in the task description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on addressing the previous issues! 🎉 The CandidateValidator
class now uses constants, enhancing readability and maintainability. The StreamPractice
class has been improved with correct age comparison logic and exception message formatting. All critical issues have been resolved, and the code meets the task requirements. Keep up the good work and continue learning from the feedback to further improve your coding skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Let’s improve your solution ;)
private final String nationality = "Ukrainian"; | ||
private final int age = 35; | ||
private final int minYearsInUkraine = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static missed. And use the correct name format: NATIONALITY...
if (candidate.getAge() < age) { | ||
return false; | ||
} | ||
if (!(candidate.getNationality().equals(nationality))) { | ||
return false; | ||
} | ||
if (!candidate.isAllowedToVote()) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you combine these conditionals?
if (!candidate.isAllowedToVote()) { | ||
return false; | ||
} | ||
String[]periods = candidate.getPeriodsInUkr().split("-"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make separator constant field
int start = Integer.parseInt(periods[0]); | ||
int finish = Integer.parseInt(periods[1]); | ||
return (finish - start) >= minYearsInUkraine; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
return numbers.stream() | ||
.flatMap(number -> Arrays.stream(number.split(","))) | ||
.map(String::trim) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(String::trim) |
.sorted() | ||
.mapToInt(Integer::intValue) | ||
.findFirst() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the min
function
.map(i -> (i % 2 != 0) ? numbers.get(i) - 1 : numbers.get(i)) | ||
.filter(n -> n % 2 != 0) | ||
.average() | ||
.orElseThrow(() -> new NoSuchElementException()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add informative message
return peopleList.stream() | ||
.filter(p -> p.getSex() == Person.Sex.MAN | ||
&& p.getAge() >= fromAge && p.getAge() <= toAge) | ||
.collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collect(Collectors.toList()); | |
.toList(); |
fix it everywhere
.filter(p -> (p.getSex() == Person.Sex.MAN | ||
&& p.getAge() >= fromAge && p.getAge() <= maleToAge) | ||
|| (p.getSex() == Person.Sex.WOMAN && p.getAge() >= fromAge | ||
&& p.getAge() <= femaleToAge)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for complicated conditional better use Predicate
No description provided.