Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 72 additions & 9 deletions src/main/java/core/basesyntax/ArrayList.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,111 @@
package core.basesyntax;

import java.util.NoSuchElementException;

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.'

public class ArrayList<T> implements List<T> {
Comment on lines +4 to 5
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.'

private static final int MIN_CAPACITY = 10;
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.'

public ArrayList() {
Comment on lines +10 to +11
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.

this.data = new Object[MIN_CAPACITY];
currentCapacity = MIN_CAPACITY;
this.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.'

@Override
public void add(T value) {
Comment on lines +16 to 18
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.


grow();
data[size] = value;
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.'

@Override
public void add(T value, int index) {
Comment on lines 23 to 25
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.


if (index == size) {
add(value);
return;
}
checkIndex(index);
grow();
System.arraycopy(data, index, data, index + 1, size - index);
data[index] = value;
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.'


@Override
public void addAll(List<T> list) {
Comment on lines 36 to 38
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.


for (int i = 0; i < list.size(); i++) {
add(list.get(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.

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


@Override
public T get(int index) {
Comment on lines 43 to 45
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.

return null;
checkIndex(index);
return (T) data[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.'


@Override
public void set(T value, int index) {
Comment on lines 49 to 51
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.


checkIndex(index);
data[index] = value;
}
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.'


@Override
public T remove(int index) {
Comment on lines 55 to 57
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.

return null;
T value = get(index);
System.arraycopy(data, index + 1, data, index, size - index - 1);
data[--size] = null;
return value;
}
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.'


@Override
public T remove(T element) {
Comment on lines 63 to 65
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.

return null;
int index = -1;
for (int i = 0; i < size; i++) {
if (compareElements((T) data[i], element)) {
index = i;
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);

throw new NoSuchElementException("Element not found: " + element);
}
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.'


@Override
public int size() {
Comment on lines 78 to 80
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.

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.'

@Override
public boolean isEmpty() {
Comment on lines 83 to 85
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.

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.'


private void grow() {
Comment on lines +88 to +89
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.

if (size + 1 > currentCapacity) {
int newCapacity = currentCapacity + (currentCapacity >> 1);
Object[] newData = new Object[newCapacity];
System.arraycopy(data, 0, newData, 0, data.length);
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) {
Comment on lines +98 to +99
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.

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.'

}

private boolean compareElements(T currentEl, T searchedEl) {
if (currentEl == null) {
return null == searchedEl;
}
return currentEl.equals(searchedEl);
}
}
Loading