package ga050426;

class PAddresses{
	enum addressKinds{absent, numeric, alphameric, star};
	PAddresses(addressKinds kin, short vel, String nam){
		kind=kin;
		value=vel;
		name=nam;
	}
	addressKinds kind;
	short value=0;
	String name="";
	public String toString(){
		if(kind==addressKinds.numeric){return "" + value;}
		else if(kind==addressKinds.alphameric)return name;
		else if(kind==addressKinds.star) return "*"; 
		else return"";
	}
	PAddresses(){}
}

class ULEntries{
	boolean labelled;
	String labField;
	String mnemonic;
	PAddresses address;
	ULEntries prec, next;
	
	ULEntries(boolean lab, String labF, String mne,
			PAddresses add, ULEntries pre, ULEntries nex){
			labelled=lab;
			labField=labF;
			mnemonic=mne;
			address=add;
			prec=pre;
			next=nex;
	}
	ULEntries(){
		this(false,"","", new PAddresses(),null,null);
	}
	
	public String toString(){
		StringBuffer buf = new StringBuffer();
		buf.append(String.format(" %s\t%s\t%s\t%s", labelled,
				labField, mnemonic, address));
		return new String(buf);		
	}
	
}

public class UnpackedLines {
	public static UnpackedLines instance= new UnpackedLines();
	private ULEntries head = null, tail = null, cur=null;
	public static int numOfLinesUnpacked=0;
	public void enter(boolean labelled, String labField, String mnemonic,
			PAddresses address){
		if (tail != null)
			tail = tail.next = new ULEntries(labelled, labField, mnemonic,
					address, tail, null);
		else
			cur=tail = head = new ULEntries(labelled, labField, mnemonic,
					address, tail, null);
		numOfLinesUnpacked++;
	}
	
	public ULEntries getNextEntrie(){
		ULEntries temp=cur;
		if(cur==null)return null;
		cur=cur.next;
		return temp;
	}
	
	private UnpackedLines(){}	
	public String toString() {
		StringBuffer buf = new StringBuffer(String.format("Unpacked lines %n"));
		for (ULEntries cur = head; cur != null; cur = cur.next) {
			
				buf.append(String.format(" %s\t%s\t%s\t%s%n", cur.labelled,
						cur.labField, cur.mnemonic, cur.address));
			
		}
		return new String(buf);
	}
}
