@Test public void adjustWeightTest() { 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); adjustSampleData(2, -8, list, data); int i = 0; i = testList(i, data, list); testListEnd(i, list); adjustSampleData(4, 7, list, data); i = 0; i = testList(i, data, list); testListEnd(i, list); adjustSampleData(0, -1, list, data); i = 0; i = testList(i, data, list); testListEnd(i, list); adjustSampleData(7, 4, list, data); i = 0; i = testList(i, data, list); testListEnd(i, list); }
boolean adjustWeight(int key, int adjustment) { 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 { if ((getWeight(key) + adjustment) <= 0) return false; else { List<Integer> indexList = new ArrayList<>(); List<E> elementList = new ArrayList<>(); for (Integer thisKey = map.higherKey(key); thisKey != null; thisKey = map.higherKey(thisKey)) { indexList.add(thisKey + adjustment); elementList.add(map.remove(thisKey)); } for (int i = 0; i < indexList.size(); i++) map.put(indexList.get(i), elementList.get(i)); maxValue += adjustment; return true; } } }
WeightedList implements Cloneable { boolean adjustWeight(int key, int adjustment) { 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 { if ((getWeight(key) + adjustment) <= 0) return false; else { List<Integer> indexList = new ArrayList<>(); List<E> elementList = new ArrayList<>(); for (Integer thisKey = map.higherKey(key); thisKey != null; thisKey = map.higherKey(thisKey)) { indexList.add(thisKey + adjustment); elementList.add(map.remove(thisKey)); } for (int i = 0; i < indexList.size(); i++) map.put(indexList.get(i), elementList.get(i)); maxValue += adjustment; return true; } } } }
WeightedList implements Cloneable { boolean adjustWeight(int key, int adjustment) { 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 { if ((getWeight(key) + adjustment) <= 0) return false; else { List<Integer> indexList = new ArrayList<>(); List<E> elementList = new ArrayList<>(); for (Integer thisKey = map.higherKey(key); thisKey != null; thisKey = map.higherKey(thisKey)) { indexList.add(thisKey + adjustment); elementList.add(map.remove(thisKey)); } for (int i = 0; i < indexList.size(); i++) map.put(indexList.get(i), elementList.get(i)); maxValue += adjustment; return true; } } }  }
WeightedList implements Cloneable { boolean adjustWeight(int key, int adjustment) { 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 { if ((getWeight(key) + adjustment) <= 0) return false; else { List<Integer> indexList = new ArrayList<>(); List<E> elementList = new ArrayList<>(); for (Integer thisKey = map.higherKey(key); thisKey != null; thisKey = map.higherKey(thisKey)) { indexList.add(thisKey + adjustment); elementList.add(map.remove(thisKey)); } for (int i = 0; i < indexList.size(); i++) map.put(indexList.get(i), elementList.get(i)); maxValue += adjustment; return true; } } }  int count(); @SuppressWarnings("unchecked") @Override WeightedList<E> clone(); }
WeightedList implements Cloneable { boolean adjustWeight(int key, int adjustment) { 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 { if ((getWeight(key) + adjustment) <= 0) return false; else { List<Integer> indexList = new ArrayList<>(); List<E> elementList = new ArrayList<>(); for (Integer thisKey = map.higherKey(key); thisKey != null; thisKey = map.higherKey(thisKey)) { indexList.add(thisKey + adjustment); elementList.add(map.remove(thisKey)); } for (int i = 0; i < indexList.size(); i++) map.put(indexList.get(i), elementList.get(i)); maxValue += adjustment; return true; } } }  int count(); @SuppressWarnings("unchecked") @Override WeightedList<E> clone();  }