package s3.core.services.memory;

import ovm.core.domain.Oop;
import ovm.core.services.memory.VM_Address;
import s3.util.queues.SingleLinkElement;
import s3.util.queues.SingleLinkQueue;

public class S3AddressQueue extends SingleLinkQueue{
    public void insert(VM_Address addr){
	AddressLink alnk = new AddressLink(addr.asOop());
	super.add(alnk);
    }

    public boolean isEmpty(){
	return super.isEmpty();
    }

    public boolean isNonEmpty(){
	return !super.isEmpty();
    }

    public VM_Address pop(){
	Oop o = ((AddressLink)super.take()).getAddress();
	return VM_Address.fromObject(o);
    }

    public void push(VM_Address addr){
	insert(addr);
    }

    class AddressLink implements SingleLinkElement{
	private SingleLinkElement next;
	private Oop addr;
	
	private AddressLink(Oop data){
	    next = null;
	    addr = data;
	}
	
	private Oop getAddress(){
	    return addr;
	}
	
	public SingleLinkElement getNext(){
	    return next;
	}
	
	public void setNext(SingleLinkElement next){
	    this.next = next;
	}
    }
}
