-
Notifications
You must be signed in to change notification settings - Fork 14
Java05. ДЗ 03, Кравцун Андрей, подгруппа 2 #37
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
base: 03-serializable-string-set
Are you sure you want to change the base?
Java05. ДЗ 03, Кравцун Андрей, подгруппа 2 #37
Conversation
…en tests (where it does not affect performance much).
sproshev
left a comment
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.
10
| * @throws SerializationException in case of IOException during deserialization | ||
| */ | ||
| void deserialize(InputStream in); | ||
| void deserialize(InputStream in) throws SerializationException; |
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.
особого смысла в отдельном исключении нет, по желанию -- можно делать своё, можно IO
|
|
||
| public StringSetImpl() { | ||
| root = null; | ||
| } |
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.
этот конструктор можно убрать:
- если поле ссылочного типа нигде не инициализируется (ни в конструкторе, ни в объявлении), то ему автоматически присвоится null
- если в классе нет конструкторов, то будет создан конструктор по умолчанию (public, без параметров)
но можно и оставить, это по желанию
| out.write(1); | ||
| } else { | ||
| out.write(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.
можно тернарный оператор использовать out.write(b ? 1 : 0);
| throw new SerializationException(); | ||
| } | ||
| } | ||
|
|
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.
про примитивы:
- в этих методах можно было бросать IO например, а потом выше преобразовывать или оборачивать в SerializationException
- можно было заиспользовать DataInput/DataOutputStream, тогда этих методов бы не было, но оборачивать в SerializationException всё равно пришлось бы
| private static final int EMPTY_VERTEX_MAGIC = 0xDDCCBBAA; | ||
| private final Vertex[] next; | ||
| private boolean isTerminal; | ||
| private Vertex parent; |
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.
final
| private static class Vertex implements StreamSerializable { | ||
| private static final int CHAR_POWER = 2 * 26; | ||
| private static final int VERTEX_MAGIC = 0xAABBCCDD; | ||
| private static final int EMPTY_VERTEX_MAGIC = 0xDDCCBBAA; |
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.
появление слова magic вносит неразбериху, и другому разработчику может показаться, что автор не очень понимает то, что сам написал)) в данном случае лучше использовать EMPTY_VERTEX_FLAG, NON_EMPTY_VERTEX_FLAG. Значения не очень важны, хоть 0 и 1.
| } | ||
| } | ||
|
|
||
| // Question: constructor would be better? |
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.
отсылаю к практике, когда обсуждались конструкторы и статик методы. мне текущий вариант больше нравится, он симметричен к методу выше
| @@ -0,0 +1,74 @@ | |||
| package ru.spbau.mit; | |||
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.
тесты сильно усложнять не всегда имеет смысл, лучше написать побольше простых случаев, включая какие-то крайние
@sproshev