Skip to content

lab-02 pull request Belous Artem#38

Open
BelArtem wants to merge 8 commits into
Rrenkens:mainfrom
BelArtem:lab_02
Open

lab-02 pull request Belous Artem#38
BelArtem wants to merge 8 commits into
Rrenkens:mainfrom
BelArtem:lab_02

Conversation

@BelArtem

Copy link
Copy Markdown

No description provided.

Comment on lines +44 to +60
public void updateTunnel () {
if (tunnel.isFull()){
while (ships.size() > tunnel.getMaxShips()) {
ships.remove(ships.size() - 1);
}
} else {
if (ships.size() <= tunnel.getMaxShips()){
tunnel.setShipsInTunnel(ships.size());
} else {
tunnel.setShipsInTunnel(tunnel.getMaxShips());
while (ships.size() > tunnel.getMaxShips()) {
ships.remove(ships.size() - 1);
}
}

}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Какое0то странное взаимодействие. Кажется массив кораблей должен лежать в тунеле и все, а не в генераторе и потом как-то с этим взаиомдействовать.

public void updateTunnel () {
if (tunnel.isFull()){
while (ships.size() > tunnel.getMaxShips()) {
ships.remove(ships.size() - 1);

Copy link
Copy Markdown
Owner

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.

Функция updateTunnel всегда используется в блоке synchronized(ships)

ship_capacity_min = jsonObject.get("ship_capacity_min").getAsInt();
ship_capacity_max = jsonObject.get("ship_capacity_max").getAsInt();

String[] cargoTypes = new Gson().fromJson(jsonObject.get("cargo_types"), String[].class);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Зачем здесь gson.

Comment on lines +68 to +69
while (necessaryIngredients.get(index) > 0 && currentStock.get(index) > 0){
int itemsLeft = currentStock.decrementAndGet(index);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Между этими двумя стрчоками может произойти событие и тогда currentStock.get(index) == 0 и после этого уйдет в минус.


int itemsToPut = Math.min(ship.getCargoLeft(), this.unloadingSpeed);
this.stock.set(index, Math.min(this.dockCapacity,
this.stock.get(index) + itemsToPut));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

тут гонка с действиями в hobos.

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.

Не совсем понимаю, при каких условиях тут может возникнуть проблема

Comment on lines +70 to +73
if (itemsLeft < 0){
currentStock.incrementAndGet(index);
break;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Это не совсем поможет исправить ситуацию, надо делать через CAS.


private void readFromJsonFile() {
try {
String filePath = "src\\by\\BelArtem\\docks_and_hobos\\config.json";

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Путь до этого файла передается аргументов в вашу программу.

@Rrenkens

Copy link
Copy Markdown
Owner

Основная оценка:

  • -0.5 за путь до файла.
  • -1 за архитектуру с туннелями.
  • -2 за гонки и неверное использование AtomicArray.

В итоге:
Основная оценка – 6.5.

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