ConstructiveIndividual extends Individual implements Iterable<T> { @Override public boolean equals(final Object ind) { if (ind == this) return true; if (!(ind instanceof ConstructiveIndividual)) return false; final ConstructiveIndividual<T> ref = (ConstructiveIndividual<T>)ind; return components.equals(ref.components); }  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; }
@Test public void testEquals() { final ConstructiveIndividual instance1 = new ConstructiveIndividual(); instance1.add(state, new KnapsackComponent(5, 5)); instance1.add(state, new KnapsackComponent(6, 6)); instance1.add(state, new KnapsackComponent(7, 7)); final ConstructiveIndividual instance2 = new ConstructiveIndividual(); instance2.add(state, new KnapsackComponent(5, 5)); instance2.add(state, new KnapsackComponent(6, 6)); instance2.add(state, new KnapsackComponent(7, 7)); final ConstructiveIndividual instance3 = new ConstructiveIndividual(); instance3.add(state, new KnapsackComponent(5, 5)); assertEquals(instance1, instance2); assertEquals(instance2, instance1); assertEquals(instance1.hashCode(), instance2.hashCode()); assertNotEquals(instance1, instance3); assertNotEquals(instance3, instance1); assertTrue(instance1.repOK()); assertTrue(instance2.repOK()); assertTrue(instance3.repOK()); }