import java.util.*;
import java.io.*;

/**
 * @author Scott Douglas ( scott@scottdouglas.net )
 */
public class HuffmanBitList implements Serializable {
	LinkedList bits;
	
	public HuffmanBitList() {
		bits = new LinkedList();
	}
	
	public List getBits() {
		return bits;
	}
	
	public void appendBit( boolean bit ) {
		bits.add( new Boolean( bit ) );
	}
	
	public Boolean getBitAt( int location ) {
		Boolean bit = null;
		
		if ( location >= 0 && location < bits.size() ) {
			bit = ( Boolean ) bits.get( location );
		}
		
		return bit;
	}
	
	public void appendBitList( HuffmanBitList toAppend ) {
		bits.addAll( toAppend.getBits() );
	}
	
	public int size() {
		return bits.size();	
	}
	
	public String toString() {
		String representation = "";
		
		if ( bits.size() > 0 ) {
			for ( int i = 0; i < bits.size(); i++ ) {
				if ( getBitAt( i ).booleanValue() == true ) {
					representation += "1";		
				} else {
					representation += "0";
				}
			}
		}
			
		return representation;
	}
}

