-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
solution #1554
base: master
Are you sure you want to change the base?
solution #1554
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 ArrayList
implementation! 😊 There are a couple of critical issues that need to be addressed before we can approve the pull request:
-
Array Growth Factor: The task specifies that the internal array should grow by 1.5 times when full, but currently, it doubles in size. Please adjust this to meet the requirement.
-
Custom Exception Definition: The
ArrayListIndexOutOfBoundsException
is used but not defined in the provided code. Make sure to implement or import this exception class to avoid runtime errors.
Once these issues are resolved, your implementation will be in great shape! Keep up the great work, and feel free to reach out if you have any questions. 🚀
✨ 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.
private void ensureCapacity(int minCapacity) { | ||
if (minCapacity > elements.length) { | ||
int newCapacity = Math.max(elements.length * 2, minCapacity); | ||
elements = Arrays.copyOf(elements, newCapacity); | ||
} | ||
} |
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 ensureCapacity(int minCapacity)
method is defined but not used anywhere in the class. Consider removing it if it's not needed, or ensure it's used appropriately if intended for future functionality.
|
||
private void validateIndex(int index) { | ||
if (index < 0 || index >= size) { | ||
throw new ArrayListIndexOutOfBoundsException("Index out of bounds: " + index); |
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 ArrayListIndexOutOfBoundsException
is used here, but it is not defined in the provided code. Ensure that this exception class is implemented or imported correctly to avoid runtime errors.
|
||
private void validateIndexForAdd(int index) { | ||
if (index < 0 || index > size) { | ||
throw new ArrayListIndexOutOfBoundsException("Index out of bounds for add: " + index); |
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.
Similar to the previous comment, ensure that ArrayListIndexOutOfBoundsException
is defined or imported correctly, as it is used here as well.
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.
Review Summary
Great effort on implementing the ArrayList
! 🎉 You've made significant progress, especially with defining and using the ArrayListIndexOutOfBoundsException
correctly. However, there are a couple of critical issues that need your attention:
-
Array Growth Factor: The
ensureCapacity
method currently doubles the array size when it's full. According to the task requirements, the array should grow by 1.5 times its current size. Please adjust this logic to meet the specified requirement. -
Custom Exception: You've successfully implemented the
ArrayListIndexOutOfBoundsException
, which resolves the previous issue regarding the missing exception definition. Well done!
While the decision is to APPROVE this Pull Request to help you move forward with your learning, it's crucial to address the array growth logic in future iterations to ensure the functionality aligns with the task requirements. Keep up the good work, and continue to learn and improve from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
private void ensureCapacity() { | ||
if (size == elements.length) { | ||
elements = Arrays.copyOf(elements, elements.length * 2); |
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 ensureCapacity
method currently doubles the array size. According to the task requirements, the array should grow by 1.5 times when it's full. Please adjust the growth factor to meet the requirement.
@@ -0,0 +1,95 @@ | |||
package core.basesyntax; | |||
|
|||
import core.basesyntax.ArrayListIndexOutOfBoundsException; |
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 ArrayListIndexOutOfBoundsException
is imported but not defined in the provided code. Ensure that this exception class is implemented or correctly imported to avoid runtime errors.
No description provided.