package mapped;

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

@ObfuscatedName("pm")
public class IterableNodeDeque implements Iterable, Collection, RSIterableNodeDeque {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lsh;"
   )
   Node sentinel;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lsh;"
   )
   Node field4441;

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

   @ObfuscatedName("at")
   public void rsClear_base() {
      while(this.sentinel.previous != this.sentinel) {
         this.sentinel.previous.remove_base();
      }

   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Lsh;)V"
   )
   public void method7287(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 method7288(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 method7290() {
      return this.method7291((Node)null);
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(Lsh;)Lsh;"
   )
   Node method7291(Node var1) {
      Node var2;
      if(var1 == null) {
         var2 = this.sentinel.previous;
      } else {
         var2 = var1;
      }

      if(var2 == this.sentinel) {
         this.field4441 = null;
         return null;
      } else {
         this.field4441 = var2.previous;
         return var2;
      }
   }

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

   @ObfuscatedName("ac")
   int method7291_base() {
      int var1 = 0;

      for(Node var2 = this.sentinel.previous; var2 != this.sentinel; var2 = var2.previous) {
         ++var1;
      }

      return var1;
   }

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

   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "()[Lsh;"
   )
   Node[] method7295() {
      Node[] var1 = new Node[this.method7291_base()];
      int var2 = 0;

      for(Node var3 = this.sentinel.previous; var3 != this.sentinel; var3 = var3.previous) {
         var1[var2++] = var3;
      }

      return var1;
   }

   @ObfuscatedName("ap")
   @ObfuscatedSignature(
      descriptor = "(Lsh;)Z"
   )
   boolean method7297(Node var1) {
      this.method7287(var1);
      return true;
   }

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

   public int size() {
      return this.method7291_base();
   }

   public boolean isEmpty() {
      return this.method7350_base();
   }

   public boolean contains(Object var1) {
      throw new RuntimeException();
   }

   public Object[] toArray(Object[] var1) {
      int var2 = 0;

      for(Node var3 = this.sentinel.previous; var3 != this.sentinel; var3 = var3.previous) {
         var1[var2++] = var3;
      }

      return var1;
   }

   public boolean containsAll(Collection var1) {
      throw new RuntimeException();
   }

   public boolean addAll(Collection var1) {
      throw new RuntimeException();
   }

   public boolean retainAll(Collection var1) {
      throw new RuntimeException();
   }

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

   public boolean equals(Object var1) {
      return super.equals(var1);
   }

   public int hashCode() {
      return super.hashCode();
   }

   public Object[] toArray() {
      return this.method7295();
   }

   public boolean add(Object var1) {
      return this.method7297((Node)var1);
   }

   public boolean removeAll(Collection var1) {
      throw new RuntimeException();
   }

   public boolean remove(Object var1) {
      throw new RuntimeException();
   }

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

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

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