Skip to content

Java01. ДЗ 2, Кравцун Андрей, подгруппа 2#17

Open
kravtsun wants to merge 22 commits intojava-course-au:02-dictfrom
kravtsun:02-dict
Open

Java01. ДЗ 2, Кравцун Андрей, подгруппа 2#17
kravtsun wants to merge 22 commits intojava-course-au:02-dictfrom
kravtsun:02-dict

Conversation

@kravtsun
Copy link
Copy Markdown

@kravtsun kravtsun commented Mar 4, 2017

Проверяющий: Семен Прошев. @sproshev

Copy link
Copy Markdown

@sproshev sproshev left a comment

Choose a reason for hiding this comment

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

надо исправлять

return oldValue;
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

внутренние и вложенные классы должны располагаться внизу

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@sproshev Т.е. по java code conventions приватные поля должны располагаться вверху, а приватные вложенные и внутренние классы внизу?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

структура, которая была представлена на практике, позволяет быстрее понимать класс:

  1. заходим, видим поля -- то, на чем класс базируется
  2. конструктор -- то, как создаются экземпляры класса
  3. публичные методы -- то, как пользоваться классом
  4. приватные методы -- то, как класс реализован
  5. внутренние и вложенные класс -- то, что помогает классу

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

каждый последующий уровень расширяет знание о классе, и при этом на любом из них можно спокойно прерваться, не вдаваясь в дебри.

}
private int hashCodeBucketIndex(String key) {
return bucketIndex(key, buckets.length);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

приватные методы идут после публичных

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно ли этот метод тоже назвать bucketIndex?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

В Java есть перегрузка? Это новость, честно говоря.
Исправил.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

есть

fullSize = 0;
}

private int bucketIndex(String key, int bucketsNumber) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

статик

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил.

}

public String put(String key, String value) {
// String gotValue = get(key);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

неиспользуемый код надо удалять

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил.

public String put(String key, String value) {
// String gotValue = get(key);
int hashIndex = hashCodeBucketIndex(key);
Bucket bucket = buckets[hashIndex]; // reference or copied value?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а какие аргументы за тот или иной вариант?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

не знаю, в языках в которых нет четкого разделения на ссылки/указатели (Java, Python), я полагаюсь на юнит-тесты. Есть где-то четкие правила?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а есть ли в джаве такое понятие, как конструктор копирования?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Вопрос выглядит риторическим - скорее всего, нет.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Верно, поэтому и копирования никакого не происходит

trueSize = 0;
}

public int index(String key) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

приватный

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил.

}
}

public boolean isFull() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

приватный

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил.

}
fullSize--;
trueSize--;
values[trueSize] = Node.empty();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

= null

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

исправил.

assertTrue(d.size() == size);
}
}
assertTrue(d.size() == size);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

assertEquals и в других местах

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил.

} else {
keys.add(key);
values.add(value);
assertEquals(d.put(key, value), null);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

assertNull

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Исправил.

Copy link
Copy Markdown

@sproshev sproshev left a comment

Choose a reason for hiding this comment

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

10

return bucketIndex(key, buckets.length);
}

private Bucket[] emptyBuckets(int newBucketsNumber) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

static


public String put(String key, String value) {
int i = index(key);
assert (canPut(key));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

assert'ы работают только с флагом -ea, он обычно автоматически подставляется в тестах и дебаге, в остальное время assert'ы отключены

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