Skip to content

Comments

done#1755

Open
chupa-ilona wants to merge 5 commits intomate-academy:masterfrom
chupa-ilona:master
Open

done#1755
chupa-ilona wants to merge 5 commits intomate-academy:masterfrom
chupa-ilona:master

Conversation

@chupa-ilona
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

I am requesting changes because several core requirements of the custom ArrayList are not yet met and these will cause tests to fail or runtime errors. The backing array never grows when full, so methods like add(T value) and add(T value, int index) can throw ArrayIndexOutOfBoundsException instead of automatically resizing by 1.5× via a dedicated private resize/ensureCapacity method. Index-based methods get, set, and remove(int index) do not use a shared index-check helper and therefore can throw low-level array exceptions instead of the required ArrayListIndexOutOfBoundsException with clear messages. The addAll(List<T> list) method currently replaces the internal storage and uses an uninitialized capacity field, instead of appending the new elements to the end after calling the resize helper to ensure enough space. In remove(T element), comparing with elements[i].equals(element) is not null-safe and will throw NullPointerException for stored nulls, which is not consistent with java.util.ArrayList behavior. Please also replace all manual element-shifting loops (in add(index), addAll, remove(index)) with System.arraycopy(), remove unused fields like capacity and loadFactor, and simplify isEmpty() to directly return size == 0. Once these functional and checklist-related issues are addressed, your implementation will be much closer to a correct, robust ArrayList clone.


✨ 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 21 to 22
@Override
public void add(T value) {

Choose a reason for hiding this comment

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

The add(T value) method inserts without ensuring capacity or resizing. The task requires the internal array to grow 1.5× and that resizing be placed in a separate method ("Resize the array in a separate method."). Implement a resize helper and call it before inserting.

Comment on lines 30 to 31
}
for (int i = size - 1; i >= index; i--) {

Choose a reason for hiding this comment

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

add(T value, int index) shifts elements using a manual loop instead of System.arraycopy(). The checklist requires: "Use System.arraycopy() to move your array elements." Replace the loop with System.arraycopy() and ensure capacity before shifting.

Comment on lines 26 to 34
@Override
public void add(T value, int index) {

if (index < 0 || index > size) {
throw new ArrayListIndexOutOfBoundsException(String.format("Index %d is out of bounds for ArrayList with size %d", index, size));
}
for (int i = size - 1; i >= index; i--) {
elements[i + 1] = elements[i];
}
elements[index] = value;

Choose a reason for hiding this comment

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

add(T value, int index) does not ensure capacity before insertion. The implementation must resize when full (see description: internal array should grow 1.5 times when it is full) and resizing logic must be in a separate method ("Resize the array in a separate method.").

Comment on lines 38 to 43
@Override
public void addAll(List<T> list) {

elements = (T[]) new Object[list.size() + capacity];
for (int i = 0; i < list.size(); i++) {
elements[i] = list.get(i);
}

Choose a reason for hiding this comment

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

addAll(List list) replaces the internal storage and sets size to list.size(), discarding existing elements; it also uses the field capacity which is never initialized. This is incorrect — addAll should append elements (or clearly replace), and you must not rely on an uninitialized/unused field. Also follow: "Resize the array in a separate method."

Comment on lines 47 to 48
@Override
public T get(int index) {

Choose a reason for hiding this comment

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

get(int index) returns elements[index] without any index validation or throwing the required custom exception. The checklist advises centralizing repeated checks: "If the logic of your code repeats - move it to a separate private method. For example, the index checks for the get(), set(), and remove() methods should be moved to a separate method." Implement a shared index-check helper that throws informative ArrayListIndexOutOfBoundsException when index is invalid.

Comment on lines 68 to 71
@Override
public T remove(T element) {
return null;
for (int i = 0; i < size; i++) {
if (elements[i].equals(element)) {

Choose a reason for hiding this comment

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

remove(T element) compares via elements[i].equals(element) which will throw NullPointerException for stored null elements; java.util.ArrayList supports null elements. Make comparisons null-safe (e.g., elements[i] == null ? element == null : elements[i].equals(element)) so your behavior matches the description's expectation to behave like java.util.ArrayList. The method correctly throws NoSuchElementException when not found.

Comment on lines 10 to 11
private int capacity;
private int loadFactor;

Choose a reason for hiding this comment

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

Two fields are declared but never initialized/used: private int capacity; and private int loadFactor;. This violates the checklist: "Don't create redundant variables." Remove or properly use these fields.

Comment on lines 30 to 41
}
for (int i = size - 1; i >= index; i--) {
elements[i + 1] = elements[i];
}
elements[index] = value;
size++;
}

@Override
public void addAll(List<T> list) {

elements = (T[]) new Object[list.size() + capacity];
for (int i = 0; i < list.size(); i++) {

Choose a reason for hiding this comment

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

There are multiple manual loops used to move/copy elements (add(index), addAll, remove(index)). The checklist requires: "Use System.arraycopy() to move your array elements." Replace the manual loops at these places with System.arraycopy() for correctness and performance.

Comment on lines 83 to 87

@Override
public boolean isEmpty() {
return false;
if (size == 0) {
return true;

Choose a reason for hiding this comment

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

isEmpty() uses an unnecessary if-else where a single boolean return would suffice; this violates: "Don't complicate if-else construction." Simplify to return size == 0;.

Comment on lines 47 to 63
@Override
public T get(int index) {
return null;
return elements[index];
}

@Override
public void set(T value, int index) {

elements[index] = value;
}

@Override
public T remove(int index) {
return null;
T removedElement = elements[index];
for (int i = index; i < size - 1; i++) {
elements[i] = elements[i + 1];
}
elements[--size] = null;

Choose a reason for hiding this comment

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

Some index-related methods currently can throw low-level ArrayIndexOutOfBoundsException rather than the required custom ArrayListIndexOutOfBoundsException with an informative message. The description mandates: "Throw custom ArrayListIndexOutOfBoundsException in case the index passed to any of the methods is invalid." Ensure all index checks throw that custom exception with clear messages.

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