class ListNode
{
  Object data;
  ListNode next;
  ListNode(Object o) {this(o,null);}
  ListNode(Object o,ListNode nextNode)
  {
  data=o;
  next=nextNode;
  }
  Object getObject() {return data;}
  ListNode getnext() {return next;}
}


public class Listi
{
//Liste
  private ListNode firstNode;
  private ListNode lastNode;
  private String name;
  public List(String s)
  {
  name=s;
  firstNode=lastNode=null;
  }
  public List(){this("Liste");}
  public synchronized void insertAtFront(Object insertItem)
  {
  if( isEmpty() )
      firstNode = lastNode = new ListNode(insertItem);
  else
     firstNode = new ListNode(insertItem,firstNode);
  }
  public synchronized void insertAtBack(Object insertItem)
  {
  if(isEmpty())
      firstNode=lastNode=new ListNode(insertItem);
  else
     lastNode=lastNode.next=new ListNode(insertItem);
  }

  public synchronized Object removeFromFront()
  throws EmptyListException
  {
  Object removeItem=null;
  if(isEmpty())
     throw new EmptyListException(name);
  removeItem=firstNode.data;
  if(firstNode.equals(lastNode))
     firstNode=lastNode=null;
  else
     firstNode=firstNode.next;
  return removeItem;
  }      
  public synchronized Object removeFromBack() 
  throws EmptyListException
  {
  Object removeItem=null;
  if(isEmpty())
     throw new EmptyListException(name);
  removeItem=lastNode.data;
  if(firstNode.equals(lastNode))
     firstNode=lastNode=null;
  else
  {
     ListNode current=firstNode;
     while(current.next != lastNode)
        current=current.next;
     lastNode=current;
     current.next=null;
  }
  return removeItem;
  }

  public boolean isEmpty() {return firstNode==null; }

  //turkce esdeger metodlar

  public boolean bosmu() {return isEmpty(); }
  public synchronized void oneEkle(Object o) {insertAtFront(o);}
  public synchronized void arkayaEkle(Object o) {insertAtBack(o);}
  public synchronized Object ondenCikar() {return removeFromFront();}
  public synchronized Object arkadanCikar() {return removeFromBack();}

  public void print()
  {
    if(isEmpty())
    {
      System.out.print(" Bos "+name); 
      return;
    }
    System.out.print(" "+name+" : ");
    ListNode current=firstNode;
    while(current!=null)
    {
    System.out.print(current.data.toString()+" ");
    current=current.next;
    }
    System.out.println("\n");
  }  
}
