@Test public void testReadGenotype() throws Exception { final ByteArrayOutputStream arrayStream = new ByteArrayOutputStream(); final DataOutput dataOutput = new DataOutputStream(arrayStream); final ConstructiveIndividual instance = new ConstructiveIndividual(); instance.add(state, new KnapsackComponent(5, 5)); instance.add(state, new KnapsackComponent(6, 6)); instance.add(state, new KnapsackComponent(7, 7)); instance.writeGenotype(state, dataOutput); final DataInput dataInput = new DataInputStream(new ByteArrayInputStream(arrayStream.toByteArray())); final ConstructiveIndividual result = new ConstructiveIndividual(); result.add(state, new KnapsackComponent(10, 10)); result.add(state, new KnapsackComponent(11, 11)); result.readGenotype(state, dataInput); assertEquals(instance, result); assertEquals(3, result.size()); assertFalse(result.contains(new KnapsackComponent(10, 10))); assertFalse(result.contains(new KnapsackComponent(11, 11))); assertTrue(instance.repOK()); assertTrue(result.repOK()); }
@Override public void readGenotype(final EvolutionState state, final DataInput dataInput) throws IOException { components = new ArrayList<T>(); componentsSet = new HashSet<T>(); final int numComponents = dataInput.readInt(); final ConstructiveProblemForm<T> problem = (ConstructiveProblemForm<T>) state.evaluator.p_problem; final T p_component = problem.getArbitraryComponent(state, 0); for (int i = 0; i < numComponents; i++) add(state, (T) p_component.readComponent(state, dataInput)); assert(repOK()); }
ConstructiveIndividual extends Individual implements Iterable<T> { @Override public void readGenotype(final EvolutionState state, final DataInput dataInput) throws IOException { components = new ArrayList<T>(); componentsSet = new HashSet<T>(); final int numComponents = dataInput.readInt(); final ConstructiveProblemForm<T> problem = (ConstructiveProblemForm<T>) state.evaluator.p_problem; final T p_component = problem.getArbitraryComponent(state, 0); for (int i = 0; i < numComponents; i++) add(state, (T) p_component.readComponent(state, dataInput)); assert(repOK()); } }
ConstructiveIndividual extends Individual implements Iterable<T> { @Override public void readGenotype(final EvolutionState state, final DataInput dataInput) throws IOException { components = new ArrayList<T>(); componentsSet = new HashSet<T>(); final int numComponents = dataInput.readInt(); final ConstructiveProblemForm<T> problem = (ConstructiveProblemForm<T>) state.evaluator.p_problem; final T p_component = problem.getArbitraryComponent(state, 0); for (int i = 0; i < numComponents; i++) add(state, (T) p_component.readComponent(state, dataInput)); assert(repOK()); }  }
ConstructiveIndividual extends Individual implements Iterable<T> { @Override public void readGenotype(final EvolutionState state, final DataInput dataInput) throws IOException { components = new ArrayList<T>(); componentsSet = new HashSet<T>(); final int numComponents = dataInput.readInt(); final ConstructiveProblemForm<T> problem = (ConstructiveProblemForm<T>) state.evaluator.p_problem; final T p_component = problem.getArbitraryComponent(state, 0); for (int i = 0; i < numComponents; i++) add(state, (T) p_component.readComponent(state, dataInput)); assert(repOK()); }  T get(final int i); @Override Parameter defaultBase(); @Override Object clone(); List<T> getComponents(); void setComponents(final EvolutionState state, final Collection<T> newComponents); void add(final EvolutionState state, final T component); boolean contains(final T component); @Override Iterator<T> iterator(); boolean isEmpty(); @Override long size(); @Override boolean equals(final Object ind); @Override int hashCode(); @Override String toString(); @Override void writeGenotype(final EvolutionState state, final DataOutput dataOutput); @Override void readGenotype(final EvolutionState state, final DataInput dataInput); boolean repOK(); }
ConstructiveIndividual extends Individual implements Iterable<T> { @Override public void readGenotype(final EvolutionState state, final DataInput dataInput) throws IOException { components = new ArrayList<T>(); componentsSet = new HashSet<T>(); final int numComponents = dataInput.readInt(); final ConstructiveProblemForm<T> problem = (ConstructiveProblemForm<T>) state.evaluator.p_problem; final T p_component = problem.getArbitraryComponent(state, 0); for (int i = 0; i < numComponents; i++) add(state, (T) p_component.readComponent(state, dataInput)); assert(repOK()); }  T get(final int i); @Override Parameter defaultBase(); @Override Object clone(); List<T> getComponents(); void setComponents(final EvolutionState state, final Collection<T> newComponents); void add(final EvolutionState state, final T component); boolean contains(final T component); @Override Iterator<T> iterator(); boolean isEmpty(); @Override long size(); @Override boolean equals(final Object ind); @Override int hashCode(); @Override String toString(); @Override void writeGenotype(final EvolutionState state, final DataOutput dataOutput); @Override void readGenotype(final EvolutionState state, final DataInput dataInput); boolean repOK(); static final String P_DEFAULTBASE; }