@Test public void removeTest() { SampleData data = new SampleData(); data.weights = new int[]{3, 8, 27, 6, 8, 2, 9, 21}; data.strings = new String[]{"Bleh", "Foo", "Snide", "Mesh", "Gree", "Fnex", "Moose", "Twa"}; WeightedList<String> list = demoList(data); removeFromSampleData(1, list, data); data.weights = Arrays.copyOf(data.weights, data.weights.length - 1); data.strings = Arrays.copyOf(data.strings, data.strings.length - 1); int j = 0; j = testList(j, data, list); testListEnd(j, list); removeFromSampleData(3, list, data); data.weights = Arrays.copyOf(data.weights, data.weights.length - 1); data.strings = Arrays.copyOf(data.strings, data.strings.length - 1); j = 0; j = testList(j, data, list); testListEnd(j, list); removeFromSampleData(5, list, data); data.weights = Arrays.copyOf(data.weights, data.weights.length - 1); data.strings = Arrays.copyOf(data.strings, data.strings.length - 1); j = 0; j = testList(j, data, list); testListEnd(j, list); }
E remove(int key) { if ((key >= maxValue) || (key < 0)) throw new IndexOutOfBoundsException( "(" + Integer.toString(key) + ") is an invalid key. The key must be between 0 and " + Integer.toString(maxValue) + "."); else { key = map.floorKey(key); E returnValue = map.remove(key); if (map.higherKey(key) == null) maxValue = key; else { Integer thisKey = map.higherKey(key); int gap = thisKey - key; while (thisKey != null) { E currentElement = map.remove(thisKey); map.put(thisKey - gap, currentElement); thisKey = map.higherKey(thisKey); } maxValue -= gap; } return returnValue; } }
WeightedList implements Cloneable { E remove(int key) { if ((key >= maxValue) || (key < 0)) throw new IndexOutOfBoundsException( "(" + Integer.toString(key) + ") is an invalid key. The key must be between 0 and " + Integer.toString(maxValue) + "."); else { key = map.floorKey(key); E returnValue = map.remove(key); if (map.higherKey(key) == null) maxValue = key; else { Integer thisKey = map.higherKey(key); int gap = thisKey - key; while (thisKey != null) { E currentElement = map.remove(thisKey); map.put(thisKey - gap, currentElement); thisKey = map.higherKey(thisKey); } maxValue -= gap; } return returnValue; } } }
WeightedList implements Cloneable { E remove(int key) { if ((key >= maxValue) || (key < 0)) throw new IndexOutOfBoundsException( "(" + Integer.toString(key) + ") is an invalid key. The key must be between 0 and " + Integer.toString(maxValue) + "."); else { key = map.floorKey(key); E returnValue = map.remove(key); if (map.higherKey(key) == null) maxValue = key; else { Integer thisKey = map.higherKey(key); int gap = thisKey - key; while (thisKey != null) { E currentElement = map.remove(thisKey); map.put(thisKey - gap, currentElement); thisKey = map.higherKey(thisKey); } maxValue -= gap; } return returnValue; } }  }
WeightedList implements Cloneable { E remove(int key) { if ((key >= maxValue) || (key < 0)) throw new IndexOutOfBoundsException( "(" + Integer.toString(key) + ") is an invalid key. The key must be between 0 and " + Integer.toString(maxValue) + "."); else { key = map.floorKey(key); E returnValue = map.remove(key); if (map.higherKey(key) == null) maxValue = key; else { Integer thisKey = map.higherKey(key); int gap = thisKey - key; while (thisKey != null) { E currentElement = map.remove(thisKey); map.put(thisKey - gap, currentElement); thisKey = map.higherKey(thisKey); } maxValue -= gap; } return returnValue; } }  int count(); @SuppressWarnings("unchecked") @Override WeightedList<E> clone(); }
WeightedList implements Cloneable { E remove(int key) { if ((key >= maxValue) || (key < 0)) throw new IndexOutOfBoundsException( "(" + Integer.toString(key) + ") is an invalid key. The key must be between 0 and " + Integer.toString(maxValue) + "."); else { key = map.floorKey(key); E returnValue = map.remove(key); if (map.higherKey(key) == null) maxValue = key; else { Integer thisKey = map.higherKey(key); int gap = thisKey - key; while (thisKey != null) { E currentElement = map.remove(thisKey); map.put(thisKey - gap, currentElement); thisKey = map.higherKey(thisKey); } maxValue -= gap; } return returnValue; } }  int count(); @SuppressWarnings("unchecked") @Override WeightedList<E> clone();  }