package utils;

import java.util.*;

/* The delayed return class is a callback used for getting 
   responses from calls that don't return immediately.
 */

public abstract class DelayedReturn extends Observable{
  // dummy functions, to allow call-throughs
  abstract public boolean done();
  abstract public void send(java.lang.Object o);

  static public class Boolean extends DelayedReturn {
  java.lang.Object retObj = null;
  boolean retDone = false;
  private void subsend(java.lang.Object o) { // exists to allow calls from inner
    retObj=o;retDone=true;
    setChanged(); notifyObservers(o);
  }
  public boolean done() { return retDone; }
    public boolean get() { return ((java.lang.Boolean)retObj).booleanValue(); }
    public void send(java.lang.Object o) 
    { if(o instanceof java.lang.Boolean) subsend(o); }
  }

  static public class Integer extends DelayedReturn {
  java.lang.Object retObj = null;
  boolean retDone = false;
  private void subsend(java.lang.Object o) { // exists to allow calls from inner
    retObj=o;retDone=true;
    setChanged(); notifyObservers(o);
  }
  public boolean done() { return retDone; }
    public int get() { return ((java.lang.Integer)retObj).intValue(); }
    public void send(java.lang.Object o) 
    { if(o instanceof java.lang.Integer) subsend(o); }
  }

  static public class Double extends DelayedReturn {
  java.lang.Object retObj = null;
  boolean retDone = false;
  private void subsend(java.lang.Object o) { // exists to allow calls from inner
    retObj=o;retDone=true;
    setChanged(); notifyObservers(o);
  }
  public boolean done() { return retDone; }
    public double get() { return ((java.lang.Double)retObj).doubleValue(); }
    public void send(java.lang.Object o) 
    { if(o instanceof java.lang.Double) subsend(o); }
  }

  static public class Object extends DelayedReturn {
  java.lang.Object retObj = null;
  boolean retDone = false;
  private void subsend(java.lang.Object o) { // exists to allow calls from inner
    retObj=o;retDone=true;
    setChanged(); notifyObservers(o);
  }
  public boolean done() { return retDone; }
    public java.lang.Object get() { return retObj; }
    public void send(java.lang.Object o) 
    { subsend(o); }
  }

}
