-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
make ArrayList class #1547
Conversation
There was a problem hiding this 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:
-
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 likeIndexOutOfBoundsException
if a custom exception is not necessary. -
Code Duplication: The index checks in methods like
add(T value, int index)
,get(int index)
,set(T value, int index)
, andremove(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.
if (index > size || index < 0) { | ||
throw new ArrayListIndexOutOfBoundsException("Can't add object"); |
There was a problem hiding this comment.
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.
if (index >= size || index < 0) { | ||
throw new ArrayListIndexOutOfBoundsException("Can't get object"); |
There was a problem hiding this comment.
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.
if (index >= size || index < 0) { | ||
throw new ArrayListIndexOutOfBoundsException("Can't set object"); |
There was a problem hiding this comment.
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.
if (index >= size || index < 0) { | ||
throw new ArrayListIndexOutOfBoundsException("Can't remove object"); |
There was a problem hiding this comment.
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.
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"); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
-
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 standardIndexOutOfBoundsException
if a custom exception isn't necessary. -
Code Duplication: The index checks in methods like
add(T value, int index)
,get(int index)
,set(T value, int index)
, andremove(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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
No description provided.