Skip to content

Implement ArrayList logic#1790

Open
Eugen2510 wants to merge 6 commits into
mate-academy:masterfrom
Eugen2510:master
Open

Implement ArrayList logic#1790
Eugen2510 wants to merge 6 commits into
mate-academy:masterfrom
Eugen2510:master

Conversation

@Eugen2510
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

Your implementation has several critical violations that must be fixed:

  1. Uses java.util.Objects - The checklist explicitly prohibits using Objects, Arrays, or any other util classes. You must replace Objects.equals() with a manual null-safe comparison.

  2. remove(T element) returns null instead of throwing NoSuchElementException - When the element is not found, the method should throw NoSuchElementException with an informative message, not return null.

  3. Empty lines before class and method implementations - Multiple empty lines before constructors and methods violate the formatting rule "Don't begin class or method implementation with an empty line."

  4. Modifier order violation - The static final on line 6 should be final static to comply with JLS modifier order.

Please fix these issues and resubmit. Focus on removing the Objects import and implementing proper exception throwing for the remove method.


✨ 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

@@ -1,48 +1,101 @@
package core.basesyntax;

import java.util.Objects;
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 imports java.util.Objects which is explicitly prohibited by the checklist: 'Don't use Objects, Arrays, or any other util class.'

return null;
int index = -1;
for (int i = 0; i < size; i++) {
if (Objects.equals(data[i], element)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Uses Objects.equals() which violates the checklist prohibition on using Objects class.

Comment on lines +72 to +73
}
return index == -1 ? null : remove(index);
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 method returns null when element is not found, but the task requires throwing NoSuchElementException in this case. The return type should be changed from T to T with exception thrown: throw new NoSuchElementException("Element not found: " + element).

Comment on lines +4 to 5

public class ArrayList<T> implements List<T> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before class implementation - violates checklist: 'Don't begin class or method implementation with an empty line.'

Comment on lines +10 to +11

public ArrayList() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before constructor - violates checklist rule about empty lines before implementations.

Comment on lines 63 to 65

@Override
public T remove(T element) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before method - violates checklist rule.

Comment on lines 75 to 77

@Override
public int 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.

Empty line before method - violates checklist rule.

Comment on lines 80 to 82

@Override
public boolean isEmpty() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before method - violates checklist rule.

Comment on lines +85 to +86

private void grow() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before private method - violates checklist rule.

Comment on lines +95 to +96

private void checkIndex(int index) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before private method - violates checklist rule.

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

Your implementation has two critical checklist violations that must be addressed:

1. Still using java.util.Objects class (CHECKLIST VIOLATION)

  • The import java.util.Objects and usage of Objects.equals(data[i], element) on line 71 directly violates the checklist requirement: "Don't use Objects, Arrays, or any other util class."
  • Replace with a manual null-safe comparison, for example:
(element == null) ? (data[i] == null) : element.equals(data[i])

2. NoSuchElementException lacks informative message

  • The exception on line 76 should include the element that wasn't found, e.g.
throw new NoSuchElementException("Element not found: " + element);

These are explicit checklist requirements that must be met. Once these issues are resolved, your implementation should be ready for approval.


✨ 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

package core.basesyntax;

import java.util.NoSuchElementException;
import java.util.Objects;
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 checklist explicitly states 'Don't use Objects, Arrays, or any other util class.' Remove this import and replace Objects.equals() with a manual null-safe comparison. For example: (data[i] == null) ? (element == null) : data[i].equals(element)

return null;
int index = -1;
for (int i = 0; i < size; i++) {
if (Objects.equals(data[i], element)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace with manual null-safe comparison instead of Objects.equals()

break;
}
}
if (index == -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.

The exception should have an informative message as required by the checklist. Include the element that was not found, e.g.: throw new NoSuchElementException("Element not found: " + element);


import java.util.NoSuchElementException;
import java.util.Objects;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the empty line before the class declaration. The checklist states 'Don't begin class or method implementation with an empty line.'

private int currentCapacity;
private Object[] data;
private int 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.

Remove the empty line before the constructor. The checklist states 'Don't begin class or method implementation with an empty line.'

throw new NoSuchElementException();
}
return remove(index);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the empty line before this method. The checklist states 'Don't begin class or method implementation with an empty line.'

return 0;
return 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.

Remove the empty line before this method. The checklist states 'Don't begin class or method implementation with an empty line.'

public boolean isEmpty() {
return false;
return size == 0;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the empty line before this method. The checklist states 'Don't begin class or method implementation with an empty line.'

currentCapacity = newCapacity;
data = newData;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the empty line before this method. The checklist states 'Don't begin class or method implementation with an empty line.'

private void checkIndex(int index) {
if (index < 0 || index > size - 1) {
throw new ArrayListIndexOutOfBoundsException("Index: " + index + ", 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.

Remove the empty line before this method. The checklist states 'Don't begin class or method implementation with an empty line.'

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

Your ArrayList implementation has successfully resolved all previous issues and meets every requirement. The custom compareElements method properly replaces the prohibited java.util.Objects usage, and the NoSuchElementException now includes an informative message. Your code demonstrates excellent understanding of single responsibility principles with well-separated grow(), checkIndex(), and compareElements() methods. The 1.5x capacity growth using bitwise shift, custom exception handling with messages, and proper use of System.arraycopy() all show solid Java fundamentals. Great work on extracting magic numbers to constants as well — this makes the code maintainable and professional.


✨ 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