/*PLEASE DO NOT EDIT THIS CODE*/
/*This code was generated using the UMPLE @UMPLE_VERSION@ modeling language!*/

package distributed.rmi5;
import java.applet.*;
import java.util.*;
import java.io.Serializable;

// line 6 "../../Class_DistributableRMI5.ump"
// line 28 "../../Class_DistributableRMI5.ump"
public class Client implements java.io.Serializable, IClientImpl
{

  //------------------------
  // MEMBER VARIABLES
  //------------------------

  //Client Attributes
  private  transient String id;

  //Client Associations
  private transient  List<Microwave> microwaves;

  //------------------------
  // CONSTRUCTOR
  //------------------------

  public Client(UmpleRuntime.UmpleComponent umpleComponent)
  {
    if(umpleComponent.getNode().getId()!=UmpleRuntime.getThisNodeId())
    {
      if(this.getClass()== Client.class)
        UmpleRuntime.getInstance().newClient( umpleComponent, this);

      return;
    }
    else
    {
      UmpleRuntime.getInstance().newClient(this);
    }

    id = "s";
    microwaves = new ArrayList<Microwave>();
  }
  //------------------------
  // Returning the Hashcode
  //------------------------
  public int getHashCodeImpl()
  {
    return hashCode();
  }

  //------------------------
  // INTERFACE
  //------------------------

  public boolean setIdImpl(String aId)
  {
    boolean wasSet = false;
    id = aId;
    wasSet = true;
    return wasSet;
  }

  /**
   * isA ClientI;
   */
  public String getIdImpl()
  {
    return id;
  }

  public Microwave getMicrowaveImpl(int index)
  {
    Microwave aMicrowave = microwaves.get(index);
    return aMicrowave;
  }

  public List<Microwave> getMicrowavesImpl()
  {
    List<Microwave> newMicrowaves = Collections.unmodifiableList(microwaves);
    return newMicrowaves;
  }

  public int numberOfMicrowavesImpl()
  {
    int number = microwaves.size();
    return number;
  }

  public boolean hasMicrowavesImpl()
  {
    boolean has = microwaves.size() > 0;
    return has;
  }

  public int indexOfMicrowaveImpl(Microwave aMicrowave)
  {
    int index = microwaves.indexOf(aMicrowave);
    return index;
  }

  public static int minimumNumberOfMicrowaves()
  {
    return 0;
  }

  public boolean addMicrowaveImpl(Microwave aMicrowave)
  {
    boolean wasAdded = false;
    if (microwaves.contains(aMicrowave)) { return false; }
    microwaves.add(aMicrowave);
    if (aMicrowave.indexOfClient(this) != -1)
    {
      wasAdded = true;
    }
    else
    {
      wasAdded = aMicrowave.addClient(this);
      if (!wasAdded)
      {
        microwaves.remove(aMicrowave);
      }
    }
    return wasAdded;
  }

  public boolean removeMicrowaveImpl(Microwave aMicrowave)
  {
    boolean wasRemoved = false;
    if (!microwaves.contains(aMicrowave))
    {
      return wasRemoved;
    }

    int oldIndex = microwaves.indexOf(aMicrowave);
    microwaves.remove(oldIndex);
    if (aMicrowave.indexOfClient(this) == -1)
    {
      wasRemoved = true;
    }
    else
    {
      wasRemoved = aMicrowave.removeClient(this);
      if (!wasRemoved)
      {
        microwaves.add(oldIndex,aMicrowave);
      }
    }
    return wasRemoved;
  }

  public boolean addMicrowaveAtImpl(Microwave aMicrowave, int index)
  {  
    boolean wasAdded = false;
    if(addMicrowave(aMicrowave))
    {
      if(index < 0 ) { index = 0; }
      if(index > numberOfMicrowaves()) { index = numberOfMicrowaves() - 1; }
      microwaves.remove(aMicrowave);
      microwaves.add(index, aMicrowave);
      wasAdded = true;
    }
    return wasAdded;
  }

  public boolean addOrMoveMicrowaveAtImpl(Microwave aMicrowave, int index)
  {
    boolean wasAdded = false;
    if(microwaves.contains(aMicrowave))
    {
      if(index < 0 ) { index = 0; }
      if(index > numberOfMicrowaves()) { index = numberOfMicrowaves() - 1; }
      microwaves.remove(aMicrowave);
      microwaves.add(index, aMicrowave);
      wasAdded = true;
    } 
    else 
    {
      wasAdded = addMicrowaveAt(aMicrowave, index);
    }
    return wasAdded;
  }

  public void deleteImpl()
  {
    ArrayList<Microwave> copyOfMicrowaves = new ArrayList<Microwave>(microwaves);
    microwaves.clear();
    for(Microwave aMicrowave : copyOfMicrowaves)
    {
      aMicrowave.removeClient(this);
    }
  }


  /**
   * key{id}
   * isA CC;
   */
  // line 16 "../../Class_DistributableRMI5.ump"
   public static  void method2(){
    
  }

  // line 19 "../../Class_DistributableRMI5.ump"
   static  int method3(){
    return 12;
  }


  public String toString()
  {
    return super.toString() + "["+
            "id" + ":" + getId()+ "]";
  }
  public void setRealObject(IClientImpl aObject)
  {
    realObject=aObject;
  }

  transient IClientImpl realObject=this;
  public Client()
  {

this(UmpleRuntime.getComponent("Client"));
  }
  public int getHashCode()
  {
    while(true)
      try{
        return realObject.getHashCodeImpl();
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public boolean setId(String aId)
  {
    while(true)
      try{
        return realObject.setIdImpl(aId);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public String getId()
  {
    while(true)
      try{
        return realObject.getIdImpl();
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public Microwave getMicrowave(int index)
  {
    while(true)
      try{
        return realObject.getMicrowaveImpl(index);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public List<Microwave> getMicrowaves()
  {
    while(true)
      try{
        return realObject.getMicrowavesImpl();
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public int numberOfMicrowaves()
  {
    while(true)
      try{
        return realObject.numberOfMicrowavesImpl();
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public boolean hasMicrowaves()
  {
    while(true)
      try{
        return realObject.hasMicrowavesImpl();
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public int indexOfMicrowave(Microwave aMicrowave)
  {
    while(true)
      try{
        return realObject.indexOfMicrowaveImpl(aMicrowave);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public boolean addMicrowave(Microwave aMicrowave)
  {
    while(true)
      try{
        return realObject.addMicrowaveImpl(aMicrowave);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public boolean removeMicrowave(Microwave aMicrowave)
  {
    while(true)
      try{
        return realObject.removeMicrowaveImpl(aMicrowave);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public boolean addMicrowaveAt(Microwave aMicrowave, int index)
  {
    while(true)
      try{
        return realObject.addMicrowaveAtImpl(aMicrowave,index);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public boolean addOrMoveMicrowaveAt(Microwave aMicrowave, int index)
  {
    while(true)
      try{
        return realObject.addOrMoveMicrowaveAtImpl(aMicrowave,index);
        }
    catch(Exception e) {System.err.println(e.toString());}
  }
  public void delete()
  {
    while(true)
      try{
        realObject.deleteImpl();
        break;
        }
    catch(Exception e) {System.err.println(e.toString());}
  }

  protected  IClientImpl remoteObject;  
  public void setRemoteObject(IClientImpl aRemoteObject)
  {
    remoteObject=aRemoteObject;
  }
  public IClientImpl getRemoteObject()
  {
    return (IClientImpl)remoteObject;
  }
  private void readObject(java.io.ObjectInputStream in) throws Exception
  {
    try
    {
      in.defaultReadObject();
      realObject=(IClientImpl)remoteObject;
    }
    catch(Exception e)
    {
      throw e;
    }
    
  }
 
  public boolean equals(Object obj)
  {    if(obj.getClass()!=this.getClass())
      return false;
    return (getHashCode()==((Client)obj).getHashCode());
  }
}