Почему список из 9 элементов преобразуется в список из 8 элементов (Java)? [закрыто]JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Почему список из 9 элементов преобразуется в список из 8 элементов (Java)? [закрыто]

Сообщение Anonymous »

Это часть кода проекта в Anylogic, где мне нужно обрабатывать запросы и каждый раз, когда я пытаюсь это сделать - один и тот же 1 запрос необработан.

Код: Выделить всё

for (Request curRequest : request) {
System.out.print(curRequest + " ");
}
//where we can find all requests
Collections.sort(request, new Comparator() {
@Override
public int compare(Request r1, Request r2) {
//System.out.println(r1.toString() +" "+ r2.toString());
return Double.compare(r2.pricePriority, r1.pricePriority);
}
});
/*for (Request curRequest : request) {
System.out.print(curRequest + " ");
}*/
//the same, but there is some problem with java.lang.IndexOutOfBoundsException, which not influance on all work of code
Iterator iterator = request.iterator();
while (iterator.hasNext()) {
Request currentRequest = iterator.next();
System.out.println(currentRequest);
//where you can find only 8 items
Clients currentClient = null;
for (Clients client : clients) {
if (client.name.equals(currentRequest.to)) {
currentClient = client;
break;
}
}

Warehouse currentWarehouse = null;
for (Warehouse warehouse : warehouse) {
if (warehouse.codeOfWarehouse == currentRequest.from) {
currentWarehouse = warehouse;
break;
}
}

int distance = 1;
List matchingBatches = new ArrayList();
for (BatchWithDestination batch : currentWarehouse.batchIn) {
if (batch.codeOfProduct == currentRequest.codeOfProduct &&
(batch.remainedValidity-distance) >= currentRequest.requiredValidity) {
matchingBatches.add(batch);
}
}
String status = "не определён";

if (matchingBatches.isEmpty()) {
status = "полностью не реализован";
fatalRequest.add(new Request(currentRequest.pricePriority, currentRequest.to, currentRequest.from, currentRequest.quantity, currentRequest.requiredValidity, currentRequest.codeOfProduct, currentRequest.data, status));
break;}

Collections.sort(matchingBatches, new Comparator() {
@Override
public int compare(BatchWithDestination b1, BatchWithDestination b2) {
return Double.compare(b1.remainedValidity, b2.remainedValidity);
}
});

BatchWithDestination currentBatch = matchingBatches.get(0);
if (currentClient == null) {
System.out.println("Client not found: " + currentRequest.to);
continue;
}

if (currentWarehouse == null) {
System.out.println("Warehouse not found: " + currentRequest.from);
continue;
}

if (currentBatch == null) {
System.out.println("Batch not found in warehouse for the product: " + currentRequest.codeOfProduct);
continue;
}
double realisedQuantity = currentRequest.quantity;

if (currentRequest.quantity >= currentBatch.quantity) {
currentRequest.set_quantity(currentRequest.quantity - currentBatch.quantity);
currentClient.batchIn.add(new Batch(currentBatch.codeOfProduct, currentBatch.remainedValidity, currentBatch.quantity, currentBatch.data));
currentWarehouse.batchIn.remove(currentBatch);
matchingBatches.remove(currentBatch);
int i = 0;
while(currentRequest.quantity>0){
if(matchingBatches.isEmpty() || i >= matchingBatches.size()){
currentBatch.set_quantity(currentBatch.quantity - currentRequest.quantity);
status = "частично выполнен";
fatalRequest.add(new Request(currentRequest.pricePriority, currentRequest.to, currentRequest.from, currentRequest.quantity, currentRequest.requiredValidity, currentRequest.codeOfProduct, currentRequest.data, status));
realisedQuantity -= currentRequest.quantity;
satisfiedRequest.add(new Request(currentRequest.pricePriority, currentRequest.to, currentRequest.from, realisedQuantity, currentRequest.requiredValidity, currentRequest.codeOfProduct,  currentRequest.data, status));
break;
}
currentBatch = matchingBatches.get(i);
if(currentRequest.quantity >  currentBatch.quantity){
currentRequest.set_quantity(currentRequest.quantity - currentBatch.quantity);
currentClient.batchIn.add(new Batch(currentBatch.codeOfProduct, currentBatch.remainedValidity, currentBatch.quantity, currentBatch.data));
currentWarehouse.batchIn.remove(currentBatch);
i++;}
else if(currentRequest.quantity < currentBatch.quantity){
currentClient.batchIn.add(new Batch(currentBatch.codeOfProduct, currentBatch.remainedValidity, currentRequest.quantity, currentBatch.data));
currentBatch.set_quantity(currentBatch.quantity - currentRequest.quantity);
currentRequest.set_quantity(0);}
else {
currentClient.batchIn.add(new Batch(currentBatch.codeOfProduct, currentBatch.remainedValidity, currentBatch.quantity, currentBatch.data));
currentRequest.set_quantity(0);
currentWarehouse.batchIn.remove(currentBatch);}
}
}
else if(currentRequest.quantity < currentBatch.quantity && currentRequest.quantity!=0){
currentClient.batchIn.add(new Batch(currentBatch.codeOfProduct, currentBatch.remainedValidity, currentRequest.quantity, currentBatch.data));
currentBatch.set_quantity(currentBatch.quantity - currentRequest.quantity);
currentRequest.set_quantity(0);
}

if (currentRequest.quantity == 0) {
status = "выполнен";
satisfiedRequest.add(new Request(currentRequest.pricePriority, currentRequest.to, currentRequest.from, realisedQuantity, currentRequest.requiredValidity, currentRequest.codeOfProduct,  currentRequest.data, status));

}
}
подробнее подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно подробно

Подробнее здесь: https://stackoverflow.com/questions/787 ... -itemsjava
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»