MCPcopy Create free account
hub / github.com/PCGen/pcgen / mergeEquipmentList

Method mergeEquipmentList

code/src/java/pcgen/core/utils/CoreUtility.java:345–399  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

sortEquipmentListMethod · 0.95

Calls 14

qtyMethod · 0.95
isContainerMethod · 0.95
isTypeMethod · 0.95
getNameMethod · 0.95
getLocationMethod · 0.95
getParentNameMethod · 0.95
addMethod · 0.65
sizeMethod · 0.65
getMethod · 0.65
equalsMethod · 0.65
removeMethod · 0.65
cloneMethod · 0.45

Tested by

no test coverage detected