Merge the equipment list @param equip the collection of Equipment @param merge The type of merge to perform @return merged list
(final Collection<Equipment> equip, final int merge)
| 343 | * @return merged list |
| 344 | */ |
| 345 | public static List<Equipment> mergeEquipmentList(final Collection<Equipment> equip, final int merge) |
| 346 | { |
| 347 | List<Equipment> workingList = new ArrayList<>(); |
| 348 | for (Equipment e : equip) |
| 349 | { |
| 350 | workingList.add(e.clone()); |
| 351 | } |
| 352 | workingList.sort(EQUIPMENT_COMPARATOR); |
| 353 | |
| 354 | // no merging, just sorting (calling this is really stupid, |
| 355 | // just use the sort above) |
| 356 | if (merge == Constants.MERGE_NONE) |
| 357 | { |
| 358 | return workingList; |
| 359 | } |
| 360 | |
| 361 | int endIndex = workingList.size(); |
| 362 | |
| 363 | for (int i = 0; i < endIndex; i++) |
| 364 | { |
| 365 | final Equipment eq1 = workingList.get(i); |
| 366 | double eQty = eq1.qty(); |
| 367 | |
| 368 | for (int j = i + 1; j < endIndex; j++) |
| 369 | { |
| 370 | final Equipment eq2 = workingList.get(j); |
| 371 | |
| 372 | // no container merge or Temporary Bonus generated equipment |
| 373 | // must not merge |
| 374 | if (eq1.isContainer() || eq1.isType("TEMPORARY") || eq2.isType("TEMPORARY")) |
| 375 | { |
| 376 | continue; |
| 377 | } |
| 378 | |
| 379 | if (eq1.getName().equals(eq2.getName())) |
| 380 | { |
| 381 | // merge all like equipment together |
| 382 | if (merge == Constants.MERGE_ALL |
| 383 | |
| 384 | // merge like equipment within same container |
| 385 | || (merge == Constants.MERGE_LOCATION && (eq1.getLocation() == eq2.getLocation()) |
| 386 | && eq1.getParentName().equals(eq2.getParentName()))) |
| 387 | { |
| 388 | workingList.remove(eq2); |
| 389 | eQty += eq2.qty(); |
| 390 | endIndex--; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | workingList.get(i).setQty(eQty); |
| 396 | } |
| 397 | |
| 398 | return workingList; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Compare the two PCGen versions. |
no test coverage detected