/*
 * Copyright (c) 2008 Chris Pettitt
 */

package com.samsarin.gatu.primitive;

import java.util.BitSet;

/**
 * @author cpettitt@samsarin.com
 */
/* package private */ abstract class AbstractChromosome implements Chromosome {
    
    /**
     * Returns the chromosome as a {@link BitSet}.
     * @return the BitSet view of this chromosome
     */
    abstract BitSet bitSetValue();

    public boolean get(int index) {
        checkBounds(index);
        return bitSetValue().get(index);
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        
        if (!(obj instanceof AbstractChromosome)) return false;
        return bitSetValue().equals(((AbstractChromosome)obj).bitSetValue());
    }

    @Override
    public int hashCode() {
        return bitSetValue().hashCode();
    }
    
    @Override
    public String toString() {
        return bitSetValue().toString();
    }
    
    private void checkBounds(int index) {
        if (index < 0 || index >= length()) {
            throw new IndexOutOfBoundsException("Index out of bounds. Expected 0 <= index < " 
                    + length() + ". Actual: " + index);
        }
    }
}

@@ -893,36 +893,229 @@
         
-return bitSetValue()
+StringBuilder sb = new StringBuilder();%0A        sb.append(%22Chromosome%5B%22);%0A        for (int i = 0; i %3C length(); ++i) %7B%0A            sb.append(get(i) ? '1' : '0');%0A        %7D%0A        sb.append(%22%5D%22);%0A        return sb
 .toStrin

Change Chromosome toString() to show actual bit string