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

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

Open
wants to merge 22 commits into
base: 02-dict
Choose a base branch
from

Conversation

kravtsun
Copy link

@kravtsun kravtsun commented Mar 4, 2017

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

Copy link

@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;
}
}
}

Choose a reason for hiding this comment

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

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

Copy link
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 приватные поля должны располагаться вверху, а приватные вложенные и внутренние классы внизу?

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. внутренние и вложенные класс -- то, что помогает классу

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);
}

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

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) {

Choose a reason for hiding this comment

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

статик

Copy link
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);

Choose a reason for hiding this comment

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

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

Copy link
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?

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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

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) {

Choose a reason for hiding this comment

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

приватный

Copy link
Author

Choose a reason for hiding this comment

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

Исправил.

}
}

public boolean isFull() {

Choose a reason for hiding this comment

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

приватный

Copy link
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();

Choose a reason for hiding this comment

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

= null

Copy link
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);

Choose a reason for hiding this comment

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

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

Copy link
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);

Choose a reason for hiding this comment

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

assertNull

Copy link
Author

Choose a reason for hiding this comment

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

Исправил.

Copy link

@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) {

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));

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