Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
The test task has already been approved.
[CODE: AAP]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
The test task has already been approved.
[CODE: AAP]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
The test task has already been approved.
[CODE: AAP]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
The test task has already been approved.
[CODE: AAP]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
|
|
||
| public class ArrayList<T> implements List<T> { | ||
| private static final int DEFAULT_CAPACITY = 10; | ||
| private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = new Object[0]; |
| import java.util.NoSuchElementException; | ||
|
|
||
| public class ArrayList<T> implements List<T> { | ||
| private static final int DEFAULT_CAPACITY = 10; |
There was a problem hiding this comment.
| private static final int DEFAULT_CAPACITY = 10; | |
| private static final int DEFAULT_CAPACITY = 10; | |
| private static final double CAPACITY_INDEX = 1.5; |
|
|
||
| public ArrayList() { | ||
| size = 0; | ||
| this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA; |
There was a problem hiding this comment.
| this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA; | |
| elements = new Object[DEFAULT_CAPACITY]; |
| @Override | ||
| public void add(T value, int index) { | ||
|
|
||
| if ((index < 0) || (index > size)) { |
There was a problem hiding this comment.
| if ((index < 0) || (index > size)) { | |
| if (index < 0 || index > size) { |
| if (list == null) { | ||
| throw new RuntimeException("Can not add list"); | ||
| } |
There was a problem hiding this comment.
| if (list == null) { | |
| throw new RuntimeException("Can not add list"); | |
| } |
| @Override | ||
| public T get(int index) { | ||
| return null; | ||
| if (index < 0 || index >= size) { |
There was a problem hiding this comment.
avoid duplication of code and create separate method
| @Override | ||
| public T remove(T element) { | ||
| return null; | ||
| int indexOfElement = -1; |
There was a problem hiding this comment.
| int indexOfElement = -1; | |
| int index = index(element); | |
| if (index == -1) { | |
| throw new NoSuchElementException("There is no such element in the list, " + element); | |
| } | |
| return remove(index); |
where
private int index(T element) {
int index = -1;
for (int i = 0; i < size; i++) {
if (elements[i] == element
|| elements[i] != null && elements[i].equals(element)) {
index = i;
}
}
return index;
}
| return size == 0; | ||
| } | ||
|
|
||
| private Object[] grow(int minCapacity) { |
There was a problem hiding this comment.
see the example of resize method
if (elements.length == size) {
int newCapacity = (int) (elements.length * CAPACITY_INDEX);
Object[] newArray = new Object[newCapacity];
System.arraycopy(elements, 0, newArray, 0, size);
elements = newArray;
}
No description provided.