-
Notifications
You must be signed in to change notification settings - Fork 12
#04 выполнено домашнее задание #5
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| package homework; | ||
|
|
||
|
|
||
| import java.util.LinkedList; | ||
|
|
||
| public class CustomerReverseOrder { | ||
|
|
||
| //todo: 2. надо реализовать методы этого класса | ||
| //надо подобрать подходящую структуру данных, тогда решение будет в "две строчки" | ||
| private final LinkedList<Customer> customers = new LinkedList<>(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. только LinkedList подойдет? Из поля непонятна решаемая им задача. Если бы объявили как Deque, а уже имплементировали LinkedList - то было бы понятно зачем и отвязано от конкретной реализации |
||
|
|
||
| public void add(Customer customer) { | ||
|
|
||
| customers.add(customer); | ||
| } | ||
|
|
||
| public Customer take() { | ||
| return null; // это "заглушка, чтобы скомилировать" | ||
| return customers.removeLast(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,25 @@ | ||
| package homework; | ||
|
|
||
|
|
||
| import java.util.Map; | ||
| import java.util.*; | ||
|
|
||
| public class CustomerService { | ||
|
|
||
| //todo: 3. надо реализовать методы этого класса | ||
| //важно подобрать подходящую Map-у, посмотрите на редко используемые методы, они тут полезны | ||
| private final TreeMap<Customer, String> map = new TreeMap<>(Comparator.comparingLong(Customer::getScores)); | ||
|
|
||
| public Map.Entry<Customer, String> getSmallest() { | ||
| //Возможно, чтобы реализовать этот метод, потребуется посмотреть как Map.Entry сделан в jdk | ||
| return null; // это "заглушка, чтобы скомилировать" | ||
| return cloneKey(map.firstEntry()); | ||
| } | ||
|
|
||
| public Map.Entry<Customer, String> getNext(Customer customer) { | ||
| return null; // это "заглушка, чтобы скомилировать" | ||
| return map.higherEntry(customer) != null ? cloneKey(map.higherEntry(customer)) : null; | ||
| } | ||
|
|
||
| public void add(Customer customer, String data) { | ||
| private Map.Entry<Customer, String> cloneKey(Map.Entry<Customer, String> entry) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Принят следующий порядок методов в классе: конструкторы, public, protected, private. Мотивация - общение с внешним миром видим сразу, а за внутренними деталями можно и проскролить класс. При такой привычке просто не ожидаешь публичные методы после приватны |
||
| return Map.entry(new Customer(entry.getKey()), entry.getValue()); | ||
| } | ||
|
|
||
| public void add(Customer customer, String data) { | ||
| map.put(customer, data); | ||
| } | ||
| } | ||
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.
не надо пытаться мержить в petrelevich :)