/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (https://www.swig.org).
 * Version 4.4.1
 *
 * Do not make changes to this file unless you know what you are doing - modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package com.frostwire.jlibtorrent.swig;

public class file_index_string_map extends java.util.AbstractMap<SWIGTYPE_p_libtorrent__file_index_t, String> {
  private transient long swigCPtr;
  protected transient boolean swigCMemOwn;

  protected file_index_string_map(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  protected static long getCPtr(file_index_string_map obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected static long swigRelease(file_index_string_map obj) {
    long ptr = 0;
    if (obj != null) {
      if (!obj.swigCMemOwn)
        throw new RuntimeException("Cannot release ownership as memory is not owned");
      ptr = obj.swigCPtr;
      obj.swigCMemOwn = false;
      obj.delete();
    }
    return ptr;
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        libtorrent_jni.delete_file_index_string_map(swigCPtr);
      }
      swigCPtr = 0;
    }
  }


  public int size() {
    return sizeImpl();
  }

  public boolean containsKey(java.lang.Object key) {
    if (!(key instanceof SWIGTYPE_p_libtorrent__file_index_t)) {
      return false;
    }

    return containsImpl((SWIGTYPE_p_libtorrent__file_index_t)key);
  }

  public String get(java.lang.Object key) {
    if (!(key instanceof SWIGTYPE_p_libtorrent__file_index_t)) {
      return null;
    }

    Iterator itr = find((SWIGTYPE_p_libtorrent__file_index_t) key);
    if (itr.isNot(end())) {
      return itr.getValue();
    }

    return null;
  }

  public String put(SWIGTYPE_p_libtorrent__file_index_t key, String value) {
    Iterator itr = find(key);
    if (itr.isNot(end())) {
      String oldValue = itr.getValue();
      itr.setValue(value);
      return oldValue;
    } else {
      putUnchecked(key, value);
      return null;
    }
  }

  public String remove(java.lang.Object key) {
    if (!(key instanceof SWIGTYPE_p_libtorrent__file_index_t)) {
      return null;
    }

    Iterator itr = find((SWIGTYPE_p_libtorrent__file_index_t) key);
    if (itr.isNot(end())) {
      String oldValue = itr.getValue();
      removeUnchecked(itr);
      return oldValue;
    } else {
      return null;
    }
  }

  public java.util.Set<Entry<SWIGTYPE_p_libtorrent__file_index_t, String>> entrySet() {
    java.util.Set<Entry<SWIGTYPE_p_libtorrent__file_index_t, String>> setToReturn =
        new java.util.HashSet<Entry<SWIGTYPE_p_libtorrent__file_index_t, String>>();

    Iterator itr = begin();
    final Iterator end = end();
    while (itr.isNot(end)) {
      setToReturn.add(new Entry<SWIGTYPE_p_libtorrent__file_index_t, String>() {
        private Iterator iterator;

        private Entry<SWIGTYPE_p_libtorrent__file_index_t, String> init(Iterator iterator) {
          this.iterator = iterator;
          return this;
        }

        public SWIGTYPE_p_libtorrent__file_index_t getKey() {
          return iterator.getKey();
        }

        public String getValue() {
          return iterator.getValue();
        }

        public String setValue(String newValue) {
          String oldValue = iterator.getValue();
          iterator.setValue(newValue);
          return oldValue;
        }
      }.init(itr));
      itr = itr.getNextUnchecked();
    }

    return setToReturn;
  }

  public file_index_string_map() {
    this(libtorrent_jni.new_file_index_string_map__SWIG_0(), true);
  }

  public file_index_string_map(file_index_string_map other) {
    this(libtorrent_jni.new_file_index_string_map__SWIG_1(file_index_string_map.getCPtr(other), other), true);
  }

  static public class Iterator {
    private transient long swigCPtr;
    protected transient boolean swigCMemOwn;
  
    protected Iterator(long cPtr, boolean cMemoryOwn) {
      swigCMemOwn = cMemoryOwn;
      swigCPtr = cPtr;
    }
  
    protected static long getCPtr(Iterator obj) {
      return (obj == null) ? 0 : obj.swigCPtr;
    }
  
    protected static long swigRelease(Iterator obj) {
      long ptr = 0;
      if (obj != null) {
        if (!obj.swigCMemOwn)
          throw new RuntimeException("Cannot release ownership as memory is not owned");
        ptr = obj.swigCPtr;
        obj.swigCMemOwn = false;
        obj.delete();
      }
      return ptr;
    }
  
    public synchronized void delete() {
      if (swigCPtr != 0) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          libtorrent_jni.delete_file_index_string_map_Iterator(swigCPtr);
        }
        swigCPtr = 0;
      }
    }
  
    private file_index_string_map.Iterator getNextUnchecked() {
      return new file_index_string_map.Iterator(libtorrent_jni.file_index_string_map_Iterator_getNextUnchecked(swigCPtr, this), true);
    }
  
    private boolean isNot(file_index_string_map.Iterator other) {
      return libtorrent_jni.file_index_string_map_Iterator_isNot(swigCPtr, this, file_index_string_map.Iterator.getCPtr(other), other);
    }
  
    private SWIGTYPE_p_libtorrent__file_index_t getKey() {
      return new SWIGTYPE_p_libtorrent__file_index_t(libtorrent_jni.file_index_string_map_Iterator_getKey(swigCPtr, this), true);
    }
  
    private String getValue() {
      return libtorrent_jni.file_index_string_map_Iterator_getValue(swigCPtr, this);
    }
  
    private void setValue(String newValue) {
      libtorrent_jni.file_index_string_map_Iterator_setValue(swigCPtr, this, newValue);
    }
  
  }

  public boolean isEmpty() {
    return libtorrent_jni.file_index_string_map_isEmpty(swigCPtr, this);
  }

  public void clear() {
    libtorrent_jni.file_index_string_map_clear(swigCPtr, this);
  }

  private file_index_string_map.Iterator find(SWIGTYPE_p_libtorrent__file_index_t key) {
    return new file_index_string_map.Iterator(libtorrent_jni.file_index_string_map_find(swigCPtr, this, SWIGTYPE_p_libtorrent__file_index_t.getCPtr(key)), true);
  }

  private file_index_string_map.Iterator begin() {
    return new file_index_string_map.Iterator(libtorrent_jni.file_index_string_map_begin(swigCPtr, this), true);
  }

  private file_index_string_map.Iterator end() {
    return new file_index_string_map.Iterator(libtorrent_jni.file_index_string_map_end(swigCPtr, this), true);
  }

  private int sizeImpl() {
    return libtorrent_jni.file_index_string_map_sizeImpl(swigCPtr, this);
  }

  private boolean containsImpl(SWIGTYPE_p_libtorrent__file_index_t key) {
    return libtorrent_jni.file_index_string_map_containsImpl(swigCPtr, this, SWIGTYPE_p_libtorrent__file_index_t.getCPtr(key));
  }

  private void putUnchecked(SWIGTYPE_p_libtorrent__file_index_t key, String value) {
    libtorrent_jni.file_index_string_map_putUnchecked(swigCPtr, this, SWIGTYPE_p_libtorrent__file_index_t.getCPtr(key), value);
  }

  private void removeUnchecked(file_index_string_map.Iterator itr) {
    libtorrent_jni.file_index_string_map_removeUnchecked(swigCPtr, this, file_index_string_map.Iterator.getCPtr(itr), itr);
  }

}
