package mapped;

import java.util.Iterator;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSNode;
import net.runelite.rs.api.RSNodeDeque;

@ObfuscatedName("on")
public class NodeDeque implements RSNodeDeque {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lsh;"
   )
   public Node sentinel;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lsh;"
   )
   Node current;

   public NodeDeque() {
      this.sentinel = new Node();
      this.sentinel.previous = this.sentinel;
      this.sentinel.next = this.sentinel;
   }

   @ObfuscatedName("at")
   public void clear_base() {
      while(true) {
         Node var1 = this.sentinel.previous;
         if(var1 == this.sentinel) {
            this.current = null;
            return;
         }

         var1.remove_base();
      }
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Lsh;)V"
   )
   public void method7233(Node 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("ar")
   @ObfuscatedSignature(
      descriptor = "(Lsh;)V"
   )
   public void method7261(Node var1) {
      if(var1.next != null) {
         var1.remove_base();
      }

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

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method7231() {
      Node var1 = this.sentinel.previous;
      if(var1 == this.sentinel) {
         return null;
      } else {
         var1.remove_base();
         return var1;
      }
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method7232() {
      Node var1 = this.sentinel.next;
      if(var1 == this.sentinel) {
         return null;
      } else {
         var1.remove_base();
         return var1;
      }
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method7265() {
      Node var1 = this.sentinel.previous;
      if(var1 == this.sentinel) {
         this.current = null;
         return null;
      } else {
         this.current = var1.previous;
         return var1;
      }
   }

   @ObfuscatedName("ac")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method7258() {
      Node var1 = this.sentinel.next;
      if(var1 == this.sentinel) {
         this.current = null;
         return null;
      } else {
         this.current = var1.next;
         return var1;
      }
   }

   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method7235() {
      Node var1 = this.current;
      if(var1 == this.sentinel) {
         this.current = null;
         return null;
      } else {
         this.current = var1.previous;
         return var1;
      }
   }

   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method7236() {
      Node var1 = this.current;
      if(var1 == this.sentinel) {
         this.current = null;
         return null;
      } else {
         this.current = var1.next;
         return var1;
      }
   }

   @ObfuscatedName("ap")
   public boolean method7235_base() {
      return this.sentinel.previous == this.sentinel;
   }

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

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

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

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

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

   public void clear() {
      this.clear_base();
   }

   public void addFirst(RSNode var1) {
      this.method7233((Node)var1);
   }

   public void addLast(RSNode var1) {
      this.method7261((Node)var1);
   }

   public RSNode removeLast() {
      return this.method7231();
   }

   public RSNode last() {
      return this.method7265();
   }

   public RSNode previous() {
      return this.method7235();
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Lsh;Lsh;)V"
   )
   public static void method7230(Node var0, Node var1) {
      if(var0.next != null) {
         var0.remove_base();
      }

      var0.next = var1.next;
      var0.previous = var1;
      var0.next.previous = var0;
      var0.previous.next = var0;
   }
}
