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

make ArrayList class #1547

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

Conversation

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


Thank you for your hard work on this implementation! 😊 There are a couple of critical issues that need to be addressed before we can approve this pull request:

  1. Custom Exception Definition: The ArrayListIndexOutOfBoundsException is used in your code, but it hasn't been defined in the provided files. This will lead to compilation errors. Please ensure that this exception class is implemented, or consider using a standard exception like IndexOutOfBoundsException if a custom exception is not necessary.

  2. Code Duplication: The index checks in methods like add(T value, int index), get(int index), set(T value, int index), and remove(int index) are repeated. Moving this logic to a separate private method will help adhere to the DRY (Don't Repeat Yourself) principle and improve code maintainability.

Once these issues are resolved, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you need any help. 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

Comment on lines +25 to +26
if (index > size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't add object");

Choose a reason for hiding this comment

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

The custom exception ArrayListIndexOutOfBoundsException is used here, but it is not defined in the provided files. Ensure that this exception class is implemented, or replace it with a standard exception if custom exceptions are not required.

Comment on lines +45 to +46
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't get object");

Choose a reason for hiding this comment

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

The custom exception ArrayListIndexOutOfBoundsException is used here, but it is not defined in the provided files. Ensure that this exception class is implemented, or replace it with a standard exception if custom exceptions are not required.

Comment on lines +53 to +54
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't set object");

Choose a reason for hiding this comment

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

The custom exception ArrayListIndexOutOfBoundsException is used here, but it is not defined in the provided files. Ensure that this exception class is implemented, or replace it with a standard exception if custom exceptions are not required.

Comment on lines +61 to +62
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't remove object");

Choose a reason for hiding this comment

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

The custom exception ArrayListIndexOutOfBoundsException is used here, but it is not defined in the provided files. Ensure that this exception class is implemented, or replace it with a standard exception if custom exceptions are not required.

Comment on lines +25 to +63
if (index > size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't add object");
}
if (size == dataStorage.length) {
grow();
}
System.arraycopy(dataStorage, index, dataStorage, index + 1, size - index);
dataStorage[index] = value;
size++;
}

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

for (int i = 0; i < list.size(); i++) {
this.add(list.get(i));
}
}

@Override
public T get(int index) {
return null;
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't get object");
}
return (T) this.dataStorage[index];
}

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

if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't set object");
}
this.dataStorage[index] = value;
}

@Override
public T remove(int index) {
return null;
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't remove object");
}

Choose a reason for hiding this comment

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

The index checks in the methods add(T value, int index), get(int index), set(T value, int index), and remove(int index) are repeated. According to the checklist, you should move this logic to a separate private method to avoid code duplication and adhere to the DRY principle.

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.

Great job on implementing the ArrayList class! 🎉 While your code is mostly correct, there are a couple of critical issues that need attention:

  1. Custom Exception Definition: The ArrayListIndexOutOfBoundsException is referenced but not defined in your files, which will lead to compilation errors. Please ensure this exception class is implemented, or consider using the standard IndexOutOfBoundsException if a custom exception isn't necessary.

  2. Code Duplication: The index checks in methods like add(T value, int index), get(int index), set(T value, int index), and remove(int index) are repeated. Extracting this logic into a private method will help you adhere to the DRY (Don't Repeat Yourself) principle and improve code maintainability.

These issues are important for the functionality and maintainability of your code, so please address them in future iterations. Keep up the great work, and use this feedback to enhance your coding skills! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

}

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

if (index > size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't add object");

Choose a reason for hiding this comment

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

The ArrayListIndexOutOfBoundsException is not defined in the provided files. This will cause a compilation error. Consider defining this exception class or using IndexOutOfBoundsException.

}

@Override
public T get(int index) {
return null;
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't get object");

Choose a reason for hiding this comment

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

The ArrayListIndexOutOfBoundsException is not defined in the provided files. This will cause a compilation error. Consider defining this exception class or using IndexOutOfBoundsException.

}

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

if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't set object");

Choose a reason for hiding this comment

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

The ArrayListIndexOutOfBoundsException is not defined in the provided files. This will cause a compilation error. Consider defining this exception class or using IndexOutOfBoundsException.

}

@Override
public T remove(int index) {
return null;
if (index >= size || index < 0) {
throw new ArrayListIndexOutOfBoundsException("Can't remove object");

Choose a reason for hiding this comment

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

The ArrayListIndexOutOfBoundsException is not defined in the provided files. This will cause a compilation error. Consider defining this exception class or using IndexOutOfBoundsException.

}

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

if (index > size || index < 0) {

Choose a reason for hiding this comment

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

Consider extracting the index check logic into a private method to avoid code duplication and adhere to the DRY principle.

}

@Override
public T get(int index) {
return null;
if (index >= size || index < 0) {

Choose a reason for hiding this comment

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

Consider extracting the index check logic into a private method to avoid code duplication and adhere to the DRY principle.

}

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

if (index >= size || index < 0) {

Choose a reason for hiding this comment

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

Consider extracting the index check logic into a private method to avoid code duplication and adhere to the DRY principle.

}

@Override
public T remove(int index) {
return null;
if (index >= size || index < 0) {

Choose a reason for hiding this comment

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

Consider extracting the index check logic into a private method to avoid code duplication and adhere to the DRY principle.

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