Conversation
|
|
||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
| hs_err_pid* | ||
| /.idea/ |
| @@ -0,0 +1,226 @@ | |||
| package Frolov; | |||
There was a problem hiding this comment.
Пакеты обычно не содержат в именах заглавных букв.
|
|
||
| import java.util.*; | ||
|
|
||
| public class GarriksArrayList implements List { |
There was a problem hiding this comment.
На дженерики совсем забил. Есть желание переделать с ними?
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| return elemsCount <= 0; |
| return elemsCount <= 0; | ||
| } | ||
|
|
||
| // тут лучше использовать == или equals? Я понимаю, что equals вернет true в отличии от ==, если экзмепляры разные, но все поля одинаковые. |
There was a problem hiding this comment.
А надо в таких случаях смотреть в джавадоки интерфейсов.
Для List # contains написано следующее:
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).
|
|
||
| @Override | ||
| public void clear() { | ||
| // допускается ли так писать? |
There was a problem hiding this comment.
В целом да, конечно. Но ты можешь просто содержимое конструктора без аргументов утащить в отдельный метод,
Будешь вызывать его из конструктора и из clear.
|
|
||
| public GarriksArrayList() { | ||
| this.elemsCount = 0; | ||
| this.realArr = new Object[10]; |
| return new GarriksListIterator(this); | ||
| } | ||
|
|
||
| // я же правильно понял, что этот метод возвращает итератор, начиная от указанного индекса i? |
There was a problem hiding this comment.
Да, все так.
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.
| // | ||
| @Override | ||
| public Object[] toArray(Object[] objects) { | ||
| return new Object[0]; |
| boolean result = false; | ||
| for (Object elem : collection) { | ||
| if (!this.contains(elem)) { | ||
| this.remove(elem); |
There was a problem hiding this comment.
Удаление элементов в этом методе и следующих неоптимально.
Лучше бы было набрать кандидатов на удаление, и потом разом их удалить, выполнив один сдвиг. Сейчас у тебя на каждый такой удаленный элемент будет по сдвигу.
No description provided.