Skip to content

Comments

did everything you asked for#1741

Open
OleksandrYurkin wants to merge 3 commits intomate-academy:masterfrom
OleksandrYurkin:hm-1-solution
Open

did everything you asked for#1741
OleksandrYurkin wants to merge 3 commits intomate-academy:masterfrom
OleksandrYurkin:hm-1-solution

Conversation

@OleksandrYurkin
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This is a good start on your custom ArrayList, but it requires changes because several key requirements from the task checklist have not been met. Specifically, your code has repeating logic for resizing the array and for checking index bounds; this logic must be extracted into separate private helper methods [CHECKLIST ITEM #5, #9]. Additionally, the task requires using System.arraycopy() for shifting array elements, but your implementation uses for loops [CHECKLIST ITEM #8]. Please also define the growth factor 1.5 as a constant [CHECKLIST ITEM #3] and add an informative message to the NoSuchElementException [CHECKLIST ITEM #10]. Addressing these points will bring your solution in line with the requirements.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 10 to 14
if (size == objects.length) {
Object[] copy = new Object[(int) (objects.length * 1.5)];
System.arraycopy(objects, 0, copy, 0, objects.length);
objects = copy;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic for resizing the array is also present in the add(T value, int index) method. This violates checklist item #5: 'Don't create repeating code' and #9: 'Resize the array in a separate method'. This logic should be extracted into a private helper method to avoid duplication.

public void add(T value) {

if (size == objects.length) {
Object[] copy = new Object[(int) (objects.length * 1.5)];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The growth factor 1.5 is a magic number. This violates checklist item #3: 'Any magic numbers should be constants'. Please declare it as a private static final constant with a descriptive name, for example, GROWTH_FACTOR.

Comment on lines 21 to 22
if (index < 0 || index > size) {
throw new ArrayListIndexOutOfBoundsException("Index out of bound");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for checking the index is repeated in get(), set(), and remove(int). This violates checklist item #5, which states: 'the index checks for the get(), set(), and remove() methods should be moved to a separate method.' Please extract this validation into a private helper method.

Comment on lines 29 to 31
for (int i = size; i > index; i--) {
objects[i] = objects[i - 1];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for loop is used to shift elements to make space for the new one. However, this violates checklist item #8: 'Use System.arraycopy() to move your array elements.' You should use System.arraycopy() here for shifting.

Comment on lines 69 to 71
for (int i = index; i < size - 1; i++) {
objects[i] = objects[i + 1];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for loop is used to shift elements after a removal. This violates checklist item #8: 'Use System.arraycopy() to move your array elements.' Please use System.arraycopy() to perform this operation.

Comment on lines 94 to 96
for (int j = i; j < size - 1; j++) {
objects[j] = objects[j + 1];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the remove(int index) method, this for loop should be replaced with a System.arraycopy() call to adhere to checklist item #8: 'Use System.arraycopy() to move your array elements.'

return removed;
}
}
throw new java.util.NoSuchElementException();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception is thrown without a message. This violates checklist item #10: 'Make your exceptions informative'. Please provide a descriptive message, such as "Element not found in the list".

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this iteration! You've successfully addressed almost all the points from the previous review, and the code is much more robust. I am requesting one small change before approving.

In your ensureCapacity() method within ArrayList.java, the line int newCapacity = (int) (objects.length * GROWTH_FACTOR) + 1; contains a magic number (1). According to the project requirements, all magic numbers should be moved to constant fields with informative names [CHECKLIST ITEM #3].

Please extract this value into a constant, for example, private static final int MINIMUM_GROWTH_AMOUNT = 1;. This will make the code more readable and maintainable. Once you've made this change, the solution will be perfect!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


private void ensureCapacity() {
if (size == objects.length) {
int newCapacity = (int) (objects.length * GROWTH_FACTOR) + 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line uses a magic number 1. According to checklist item #3, all magic numbers should be moved to constant fields with informative names. This will improve code readability and maintainability. For example, you could create a constant like private static final int MINIMUM_GROWTH_AMOUNT = 1;.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work! You've successfully addressed the feedback from the previous review by extracting the magic number into a constant. The code is now clean, easy to read, and fully compliant with all task requirements. I'm happy to approve your solution. Well done!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants