ReplacementOperation implements Operation { public void setProperties(Properties p) { String key; int size; int popSize; double valueD = 1.0; key = Constants.POPULATION_SIZE; popSize = Integer.parseInt(p.getProperty(key, Constants.DEFAULT_POPULATION_SIZE)); key = Constants.REPLACEMENT_TYPE; if(p.getProperty(key)!=null) { if(p.getProperty(key).equals(Constants.STEADY_STATE)) { valueD = 1.0/popSize; } else { if(p.getProperty(key).equals(Constants.GENERATIONAL)) { valueD = 1.0; } } } else { key = Constants.GENERATION_GAP; try { if(p.getProperty(key)!=null) { valueD = Double.parseDouble(p.getProperty(key)); if(valueD < 0.0 || valueD > 1.0) { throw new BadParameterException(key); } } } catch(Exception e) { valueD = 1.0; logger.warn(e+" using default: "+valueD); } } size = (int)(popSize*valueD); this.replacementSize = size; } ReplacementOperation(int size);  ReplacementOperation(Properties p); void setProperties(Properties p); void doOperation(Individual operand); void doOperation(List<Individual> operand); void doOperation(List<Individual> operand, int size); void setReplacementSize(int i); int getReplacementSize();  }
@Test public void testSetProperties() { System.out.println("* ReplacementOperation: setProperties"); Properties p = GrammarCreator.getProperties(); p.setProperty(Constants.POPULATION_SIZE, "10"); p.setProperty(Constants.REPLACEMENT_TYPE, Constants.STEADY_STATE); ReplacementOperation instance = new ReplacementOperation(0); instance.setProperties(p); assertEquals(instance.replacementSize, 1); p = GrammarCreator.getProperties(); p.setProperty(Constants.POPULATION_SIZE, "10"); p.setProperty(Constants.REPLACEMENT_TYPE, Constants.GENERATIONAL); instance = new ReplacementOperation(0); instance.setProperties(p); assertEquals(instance.replacementSize, Integer.parseInt(p.getProperty(Constants.POPULATION_SIZE))); p = GrammarCreator.getProperties(); p.setProperty(Constants.POPULATION_SIZE, "10"); p.setProperty(Constants.GENERATION_GAP, "0.5"); p.remove(Constants.REPLACEMENT_TYPE); instance = new ReplacementOperation(0); instance.setProperties(p); assertEquals(instance.replacementSize, 5); p = GrammarCreator.getProperties(); p.setProperty(Constants.POPULATION_SIZE, "10"); p.setProperty(Constants.GENERATION_GAP, "-0.5"); p.remove(Constants.REPLACEMENT_TYPE); instance = new ReplacementOperation(0); instance.setProperties(p); assertEquals(instance.replacementSize, 10); }