Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created own ArrayList collection which implements our List interface … #1216

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maxymmusiienko
Copy link

…and uses custom exeption

Copy link
Contributor

@Rommelua Rommelua left a comment

Choose a reason for hiding this comment

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

Before you create PR with your homework, you need to go through the checklist under the task and correct all the points described there. The mentor will not check the work until the checklist points are corrected

this.elements = new Object[DEFAULT_CAPACITY];
}

private void ensureCapacity() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Private ones (methods, classes) should be after public ones.

private void ensureCapacity() {
if (size == elements.length) {
int newCapacity = (int) (elements.length * 1.5);
elements = Arrays.copyOf(elements, newCapacity);
Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Author

Choose a reason for hiding this comment

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

sorry for my inattention

Copy link

@Ivan95kos Ivan95kos left a comment

Choose a reason for hiding this comment

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

Good job overall!

public class ArrayList<T> implements List<T> {
private static final int DEFAULT_CAPACITY = 10;
private static final double RESIZE_COEFFICIENT = 1.5;
private Object[] elements;

Choose a reason for hiding this comment

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

use the parameterized type

Suggested change
private Object[] elements;
private T [] elements;

Comment on lines 43 to 47
if (index < 0 || index >= size) {
throw new ArrayListIndexOutOfBoundsException("Index outed of bounds, Index: " + index
+ ", Size: "
+ size);
}

Choose a reason for hiding this comment

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

move this check to the private method
you use it several times

Comment on lines 76 to 90
if (element == null) {
for (int i = 0; i < size; i++) {
if (elements[i] == null) {
return remove(i);
}
}
throw new NoSuchElementException("Element not found");
}

for (int i = 0; i < size; i++) {
if (element.equals(elements[i])) {
return remove(i);
}
}
throw new NoSuchElementException("Element not found");

Choose a reason for hiding this comment

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

use the one loop here

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.

4 participants