-
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
initial commit #1532
base: master
Are you sure you want to change the base?
initial commit #1532
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 the ArrayList
implementation! 😊 There are a couple of critical issues that need to be addressed before we can approve the pull request.
-
Array Growth Logic: The current logic doubles the array size instead of increasing it by 1.5 times as required. Please adjust the logic to multiply the current length by 1.5 to meet the task specifications.
-
Custom Exception: The
ArrayListIndexOutOfBoundsException
class is missing. You need to define this custom exception to handle invalid indices as per the task requirements.
Once these issues are resolved, your implementation should 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.
public class ArrayList<T> implements List<T> { | ||
public static final int DEFAULT_CAPACITY = 10; | ||
public static final int ARRAY_GROWTH_VALUE = 1; |
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 ARRAY_GROWTH_VALUE
constant is set to 1, but the task requires the array to grow by 1.5 times when it is full. Consider changing the logic in growIfArrayIsFull
to multiply the current capacity by 1.5 instead of using a bitwise shift.
throw new ArrayListIndexOutOfBoundsException("Can't add value to index " + index | ||
+ ". Index is invalid."); |
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
class is not defined in the provided files. You need to create this custom exception class to meet the task requirements.
private void growIfArrayIsFull() { | ||
if (size == elementData.length) { | ||
Object[] grownElementData = new Object[elementData.length | ||
+ (elementData.length >> ARRAY_GROWTH_VALUE)]; |
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 array growth logic is incorrect. The task requires the array to grow by 1.5 times, but the current implementation uses a bitwise shift which effectively doubles the size. Adjust the logic to multiply the current length by 1.5.
…ty by 1.5 instead of using a bitwise shift.
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.
Review Summary
Great job on addressing the issues from the previous review! 🎉 Your implementation of the ArrayList
has improved significantly:
-
Array Growth Logic: You've successfully updated the array growth logic to multiply the current length by 1.5, aligning with the task specifications. This ensures efficient memory usage and performance.
-
Custom Exception: The inclusion of the
ArrayListIndexOutOfBoundsException
for handling invalid indices is a crucial addition, enhancing the robustness of your code.
Your solution now meets the task requirements and constraints. While there were initial issues with the array growth logic and the missing custom exception, you've effectively resolved them.
Remember, addressing such issues is a valuable learning experience. Keep up the good work, and continue to refine your coding skills! If you encounter similar challenges in the future, refer back to this solution as a guide. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
Object[] grownElementData = new Object[(int) (elementData.length | ||
+ (elementData.length * 1.5))]; |
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 logic for growing the array is incorrect. According to the task requirements, the array size should be increased by multiplying the current length by 1.5. The current implementation adds 1.5 times the length to itself, which is not correct. Please adjust this logic.
throw new ArrayListIndexOutOfBoundsException("Can't add value to index " + index | ||
+ ". Index is invalid."); |
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
class is missing. You need to define this custom exception to handle invalid indices as per the task requirements.
|
||
private void checkIndexValidation(int index) { | ||
if (index < 0 || index >= size) { | ||
throw new ArrayListIndexOutOfBoundsException("Index is invalid."); |
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
class is missing. You need to define this custom exception to handle invalid indices as per the task requirements.
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.
Good job!
public class ArrayList<T> implements List<T> { | ||
public static final int DEFAULT_CAPACITY = 10; | ||
public static final double ARRAY_GROWTH_VALUE = 1.5; | ||
private Object[] elementData; |
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.
use your class type parameter T (you'll have to cast in constructor)
size++; | ||
} | ||
|
||
private void checkIndexForAdd(int index) { |
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.
put private methods after public ones
} | ||
} | ||
} | ||
throw new NoSuchElementException("Element not found"); |
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.
include element in the message
return remove(i); | ||
} | ||
} | ||
} else { | ||
for (int i = 0; i < size; i++) { | ||
if (element.equals(elementData[i])) { | ||
return remove(i); |
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.
lines 85, 91 - actual action is the same in both clauses - it means you just have to merge two conditions into one
use the same code as in Java's objects.equals (which you can't use directly)
…, included element name to exception message, created new method for checking for equality of elements
No description provided.