package mapped;

import java.util.Iterator;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSLink;
import net.runelite.rs.api.RSLinkDeque;

@ObfuscatedName("pu")
public class LinkDeque implements RSLinkDeque {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lse;"
   )
   Link sentinel;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lse;"
   )
   Link current;

   public LinkDeque() {
      this.sentinel = new Link();
      this.sentinel.previous = this.sentinel;
      this.sentinel.next = this.sentinel;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(Lse;)V"
   )
   public void method7365(Link var1) {
      if(var1.next != null) {
         var1.remove_base();
      }

      var1.next = this.sentinel.next;
      var1.previous = this.sentinel;
      var1.next.previous = var1;
      var1.previous.next = var1;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "()Lse;"
   )
   public Link method7364() {
      Link var1 = this.sentinel.previous;
      if(var1 == this.sentinel) {
         this.current = null;
         return null;
      } else {
         this.current = var1.previous;
         return var1;
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "()Lse;"
   )
   public Link method7362() {
      Link var1 = this.current;
      if(var1 == this.sentinel) {
         this.current = null;
         return null;
      } else {
         this.current = var1.previous;
         return var1;
      }
   }

   public RSLink getSentinel() {
      return this.sentinel;
   }

   public void setCurrent(RSLink var1) {
      this.current = (Link)var1;
   }

   public Iterator iterator() {
      return new RuneLiteIterableLinkDeque(this);
   }

   public void addLast(Object var1) {
      RSLink var2 = (RSLink)var1;
      if(var2.getNext() != null) {
         var2.remove();
      }

      var2.setNext(this.getSentinel());
      var2.setPrevious(this.getSentinel().getPrevious());
      var2.getNext().setPrevious(var2);
      var2.getPrevious().setNext(var2);
   }

   public void clear() {
      while(true) {
         RSLink var1 = this.getSentinel().getPrevious();
         if(var1 == this.getSentinel()) {
            this.setCurrent((RSLink)null);
            return;
         }

         var1.remove();
      }
   }

   public RSLink getCurrent() {
      return this.current;
   }

   public void addFirst(RSLink var1) {
      this.method7365((Link)var1);
   }

   public RSLink last() {
      return this.method7364();
   }

   public RSLink previous() {
      return this.method7362();
   }
}
