Skip to content

pr#2

Open
teSGreat wants to merge 2 commits intoPetrShchukin:masterfrom
teSGreat:master
Open

pr#2
teSGreat wants to merge 2 commits intoPetrShchukin:masterfrom
teSGreat:master

Conversation

@teSGreat
Copy link
Copy Markdown

No description provided.

}

@Override
public boolean equals(Object o) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical: Если пришла сначала пара посетителей, а потом ещё одна пара - то это две разные группы, а не одна и та же.

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.

одно другому не мешает. это будут разные группы, но при этом равны. можно конечно ввести id, но не хотелось усложнять и на реализацию equals они бы не повлияли

}

@Override
public boolean equals(Object o) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical: Два столика одинакового размера - это два разных столика, а не один и тот же.

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.

то же самое что и с группами. ошиюбка в том, что использовал set для столиков, почему то упустил этот момент, но на реализацию equals опять же, не влияет

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Set - не ошибка, это допустимая коллекция. А ваш метод equals просто не имеет смысла.

"Равенства" столиков не существует в предметной области как понятия, все столики - разные сущности. Да, можно было бы для сравнения использовать id, но в отсутствии id самое лучшее что можно сделать - вообще не писать методы equals и hashCode.


// return table where a given client group is seated,
// or null if it is still queuing or has already left
public Table lookup(ClientsGroup group) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: Θ(N) на пустом месте. Впрочем, для ресторана сойдёт.

groupTable.leaveGroup(group);
}

for (int i = clients.size() - 1; i >= 0; i--) {
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.

затупил. на очередях сразу делал, вот в голове и засело что надо с конца идти


// client(s) leave, either served or simply abandoning the queue
public void onLeave(ClientsGroup group) {
if (!clients.remove(group)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: лишний уровень вложенности усложняет чтение кода.

Table groupTable = lookup(group);
if (groupTable != null) {
groupTable.leaveGroup(group);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor: А что если groupTable == 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.

или просто цикл внести в скобки

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