MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / removeAll

Method removeAll

src/main/java/wycc/util/ArrayUtils.java:434–459  ·  view source on GitHub ↗

Remove any occurrence of a given value from an array. The resulting array may be shorter in length, but the relative position of all other items will remain unchanged. This algorithm is robust to null . The items array may contain null values and the item<

(T[] items, T item)

Source from the content-addressed store, hash-verified

432 * @return
433 */
434 public static <T> T[] removeAll(T[] items, T item) {
435 int count = 0;
436 // First, determine the number of elements which will be removed
437 for (int i = 0; i != items.length; ++i) {
438 T ith = items[i];
439 if (ith == item || (item != null && item.equals(ith))) {
440 count++;
441 }
442 }
443 // Second, eliminate duplicates (if any)
444 if (count == 0) {
445 // nothing actually needs to be removed
446 return items;
447 } else {
448 T[] nItems = Arrays.copyOf(items, items.length - count);
449 for(int i=0, j = 0;i!=items.length;++i) {
450 T ith = items[i];
451 if (ith == item || (item != null && item.equals(ith))) {
452 // skip item
453 } else {
454 nItems[j++] = ith;
455 }
456 }
457 return nItems;
458 }
459 }
460
461 /**
462 * A default operator for comparing arrays

Callers 13

createMethod · 0.95
applyMethod · 0.95
filterParametersMethod · 0.95
foldMethod · 0.95
mapMethod · 0.95
subtractMethod · 0.95
forkMethod · 0.95
filterMethod · 0.95
mapMethod · 0.95
foldMethod · 0.95
removeAllMethod · 0.95
replaceMethod · 0.45

Calls 1

equalsMethod · 0.45

Tested by

no test coverage detected