@Test(expected = IllegalArgumentException.class) public void testSetInvalidKey() { int[] lowerBounds = { 1, 2, 3 }; int[] upperBounds = { 2, 3, 4 }; Bounds<Integer> bounds = new IntegerBounds(lowerBounds, upperBounds); MockObject mockup1 = new MockObject(1.0, 1); MockObject mockup2 = new MockObject(2.0, 2); MockObject mockup3 = new MockObject(3.0, 3); MockObject mockup4 = new MockObject(4.0, 4); List<MockObject> inputList = new ArrayList<>(); inputList.add(mockup1); inputList.add(mockup2); inputList.add(mockup3); IntegerMapGenotype<MockObject> integerMapGenotype = new IntegerMapGenotype<>(inputList, bounds); integerMapGenotype.setValue(mockup4, 1); }
@Override public void setValue(K key, Integer value) { if (!containsKey(key)) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_INVALID_KEY); } int i = list.indexOf(key); while (size() <= i) { add(bounds.getLowerBound(size())); } if (bounds.getLowerBound(i) > value || bounds.getUpperBound(i) < value) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_OUT_OF_BOUNDS); } set(i, value); }
IntegerMapGenotype extends IntegerGenotype implements MapGenotype<K, Integer> { @Override public void setValue(K key, Integer value) { if (!containsKey(key)) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_INVALID_KEY); } int i = list.indexOf(key); while (size() <= i) { add(bounds.getLowerBound(size())); } if (bounds.getLowerBound(i) > value || bounds.getUpperBound(i) < value) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_OUT_OF_BOUNDS); } set(i, value); } }
IntegerMapGenotype extends IntegerGenotype implements MapGenotype<K, Integer> { @Override public void setValue(K key, Integer value) { if (!containsKey(key)) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_INVALID_KEY); } int i = list.indexOf(key); while (size() <= i) { add(bounds.getLowerBound(size())); } if (bounds.getLowerBound(i) > value || bounds.getUpperBound(i) < value) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_OUT_OF_BOUNDS); } set(i, value); } IntegerMapGenotype(List<K> list, Bounds<Integer> bounds);  IntegerMapGenotype(List<K> list, int lowerBound, int upperBound); }
IntegerMapGenotype extends IntegerGenotype implements MapGenotype<K, Integer> { @Override public void setValue(K key, Integer value) { if (!containsKey(key)) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_INVALID_KEY); } int i = list.indexOf(key); while (size() <= i) { add(bounds.getLowerBound(size())); } if (bounds.getLowerBound(i) > value || bounds.getUpperBound(i) < value) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_OUT_OF_BOUNDS); } set(i, value); } IntegerMapGenotype(List<K> list, Bounds<Integer> bounds);  IntegerMapGenotype(List<K> list, int lowerBound, int upperBound); void init(Random random); @Override void init(Random random, int n); @Override boolean containsKey(K key); @Override Integer getValue(K key); @Override void setValue(K key, Integer value); @Override @SuppressWarnings({ "unchecked", "rawtypes" }) G newInstance(); @Override String toString(); @Override int getIndexOf(K key); @Override Collection<K> getKeys(); }
IntegerMapGenotype extends IntegerGenotype implements MapGenotype<K, Integer> { @Override public void setValue(K key, Integer value) { if (!containsKey(key)) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_INVALID_KEY); } int i = list.indexOf(key); while (size() <= i) { add(bounds.getLowerBound(size())); } if (bounds.getLowerBound(i) > value || bounds.getUpperBound(i) < value) { throw new IllegalArgumentException(MapGenotype.ERROR_MESSAGE_OUT_OF_BOUNDS); } set(i, value); } IntegerMapGenotype(List<K> list, Bounds<Integer> bounds);  IntegerMapGenotype(List<K> list, int lowerBound, int upperBound); void init(Random random); @Override void init(Random random, int n); @Override boolean containsKey(K key); @Override Integer getValue(K key); @Override void setValue(K key, Integer value); @Override @SuppressWarnings({ "unchecked", "rawtypes" }) G newInstance(); @Override String toString(); @Override int getIndexOf(K key); @Override Collection<K> getKeys();  }