package mapped;

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

@ObfuscatedName("tp")
public class IterableNodeHashTableIterator implements Iterator, RSIterableNodeHashTableIterator {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Ltz;"
   )
   IterableNodeHashTable hashTable;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lsh;"
   )
   Node head;
   @ObfuscatedName("ar")
   int index;
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Lsh;"
   )
   Node last;

   @ObfuscatedSignature(
      descriptor = "(Ltz;)V"
   )
   public IterableNodeHashTableIterator(IterableNodeHashTable var1) {
      this.last = null;
      this.hashTable = var1;
      this.start_base();
   }

   @ObfuscatedName("at")
   void start_base() {
      this.head = this.hashTable.buckets[0].previous;
      this.index = 1;
      this.last = null;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "()Lsh;"
   )
   public Node method8939() {
      this.start_base();
      return (Node)this.next();
   }

   public Object next() {
      Node var1;
      if(this.hashTable.buckets[this.index - 1] != this.head) {
         var1 = this.head;
         this.head = var1.previous;
         this.last = var1;
         return var1;
      } else {
         do {
            if(this.index >= this.hashTable.size) {
               return null;
            }

            var1 = this.hashTable.buckets[this.index++].previous;
         } while(var1 == this.hashTable.buckets[this.index - 1]);

         this.head = var1.previous;
         this.last = var1;
         return var1;
      }
   }

   public boolean hasNext() {
      if(this.hashTable.buckets[this.index - 1] != this.head) {
         return true;
      } else {
         while(this.index < this.hashTable.size) {
            if(this.hashTable.buckets[this.index++].previous != this.hashTable.buckets[this.index - 1]) {
               this.head = this.hashTable.buckets[this.index - 1].previous;
               return true;
            }

            this.head = this.hashTable.buckets[this.index - 1];
         }

         return false;
      }
   }

   public void remove() {
      this.last.remove_base();
      this.last = null;
   }
}
