Skip to content

task competed#1770

Open
IvanKlever wants to merge 3 commits into
mate-academy:masterfrom
IvanKlever:ivan-task
Open

task competed#1770
IvanKlever wants to merge 3 commits into
mate-academy:masterfrom
IvanKlever:ivan-task

Conversation

@IvanKlever
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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 requires changes. While you've correctly implemented the core logic for capacity and growth, your solution violates several critical requirements from the task checklist.

Here are the main points to address:

  1. Use of System.arraycopy(): The task explicitly requires using System.arraycopy() for moving elements within the array. Your implementation uses for loops in the grow(), add(T value, int index), and remove(int index) methods, which needs to be corrected. [CHECKLIST ITEM #8]
  2. Forbidden Utility Class: The use of Math.max() is not allowed, as Math is a utility class forbidden by the task rules. You should replace this with your own logic. [CHECKLIST ITEM #2]
  3. Duplicated Code: The index validation logic is repeated in the get(), set(), and remove(int) methods. Please extract this into a separate private method to adhere to the DRY (Don't Repeat Yourself) principle. [CHECKLIST ITEM #5]

Please revise your code to meet these 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

if (elements == null) {
throw new IllegalArgumentException("Array cannot be null");
}
this.elements = new Object[Math.max(DEFAULT_CAPACITY, elements.length)];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #2: 'Don't use Objects, Arrays, or any other util class'. The Math class is considered a utility class. You should implement this logic without using external library methods.

Comment on lines +32 to +35
for (Object newArray : this.elements) {
newElements[i] = newArray;
i++;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #8: 'Use System.arraycopy() to move your array elements'. A for loop is used to copy the elements to the new array, but the task requires you to use System.arraycopy() for this operation.

Comment on lines +50 to +53
if (index < 0 || index > size) {
throw new ArrayListIndexOutOfBoundsException("Index "
+ index + " out of bounds for size " + size);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #5: 'Don't create repeating code'. The logic for checking if an index is out of bounds is repeated in the get(), set(), and remove(int) methods. This should be extracted into a separate private method to avoid duplication.

Comment on lines +57 to +59
for (int i = size - 1; i >= index; i--) {
elements[i + 1] = elements[i];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #8: 'Use System.arraycopy() to move your array elements'. Instead of manually shifting elements in a loop, you should use a single call to System.arraycopy().

Comment on lines +99 to +100
for (int i = index; i < size - 1; i++) {
this.elements[i] = this.elements[i + 1];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #8: 'Use System.arraycopy() to move your array elements'. This loop to shift elements after removal should be replaced with System.arraycopy() as required by the task.

Copy link
Copy Markdown

@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

Great job addressing most of the feedback from the last review! Your use of System.arraycopy() and the refactored index validation method have really improved the code.

However, changes are still needed because your solution uses a forbidden utility class. The ArrayList(T[] elements) constructor still uses Math.max(), which violates the task requirements [CHECKLIST ITEM #2]. You can easily replace this with a ternary operator or a simple if-else statement.

I also noticed a small issue: the variable resoul in the arrayListIndexOutOfBoundException method is declared but never used and should be removed.

Please fix the use of Math.max(), and your solution will be ready. Keep up the great work!


✨ 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

if (elements == null) {
throw new IllegalArgumentException("Array cannot be null");
}
this.elements = new Object[Math.max(DEFAULT_CAPACITY, elements.length)];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The use of Math.max() is not allowed, as Math is a forbidden utility class according to checklist item #2. You should replace this with your own logic, for example, by using a ternary operator or an if-else statement.

}

private void arrayListIndexOutOfBoundException(int index) {
boolean resoul = true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This variable resoul is declared and initialized but is never used. It should be removed to make the code cleaner. This violates the checklist recommendation against creating redundant variables.

Copy link
Copy Markdown

@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 task! You've done a great job addressing the previous feedback. I am approving your solution as an educational override so you can continue to the next topic. Just keep a couple of things in mind for the future: the ArrayList(T[] elements) constructor could be more efficient using System.arraycopy() instead of a loop [CHECKLIST ITEM #8], and the nested if-else in the remove(T element) method can be simplified for better readability [CHECKLIST ITEM #4]. These are small points in an otherwise strong submission. Keep up the great momentum!


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

Footnotes

  1. Rate AI review example

Comment on lines +22 to +25
for (T elem : elements) {
this.elements[i] = elem;
i++;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While this loop works correctly, the checklist recommends using System.arraycopy() to move array elements. Applying it here would be more efficient and consistent with the implementation of your other methods. [CHECKLIST ITEM #8]

Comment on lines +117 to +127
if (element == null) {
if (this.elements[i] == null) {
index = i;
break;
}
} else {
if (element.equals(this.elements[i])) {
index = i;
break;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This nested if-else structure can be simplified into a single if statement with a compound condition. This would make the code more concise and easier to read, in line with the guideline to avoid complicated if-else constructions. [CHECKLIST ITEM #4]

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