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

package net.jami.daemon;

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

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

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

  @SuppressWarnings("deprecation")
  protected void finalize() {
    delete();
  }

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


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

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

    return containsImpl((String)key);
  }

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

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

    return null;
  }

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

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

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

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

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

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

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

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

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

    return setToReturn;
  }

  public IntegerMap() {
    this(JamiServiceJNI.new_IntegerMap__SWIG_0(), true);
  }

  public IntegerMap(IntegerMap other) {
    this(JamiServiceJNI.new_IntegerMap__SWIG_1(IntegerMap.getCPtr(other), other), true);
  }

  static protected 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;
    }
  
    @SuppressWarnings("deprecation")
    protected void finalize() {
      delete();
    }
  
    public synchronized void delete() {
      if (swigCPtr != 0) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          JamiServiceJNI.delete_IntegerMap_Iterator(swigCPtr);
        }
        swigCPtr = 0;
      }
    }
  
    private IntegerMap.Iterator getNextUnchecked() {
      return new IntegerMap.Iterator(JamiServiceJNI.IntegerMap_Iterator_getNextUnchecked(swigCPtr, this), true);
    }
  
    private boolean isNot(IntegerMap.Iterator other) {
      return JamiServiceJNI.IntegerMap_Iterator_isNot(swigCPtr, this, IntegerMap.Iterator.getCPtr(other), other);
    }
  
    private String getKey() {
      return JamiServiceJNI.IntegerMap_Iterator_getKey(swigCPtr, this);
    }
  
    private int getValue() {
      return JamiServiceJNI.IntegerMap_Iterator_getValue(swigCPtr, this);
    }
  
    private void setValue(int newValue) {
      JamiServiceJNI.IntegerMap_Iterator_setValue(swigCPtr, this, newValue);
    }
  
  }

  public boolean isEmpty() {
    return JamiServiceJNI.IntegerMap_isEmpty(swigCPtr, this);
  }

  public void clear() {
    JamiServiceJNI.IntegerMap_clear(swigCPtr, this);
  }

  private IntegerMap.Iterator find(String key) {
    return new IntegerMap.Iterator(JamiServiceJNI.IntegerMap_find(swigCPtr, this, key), true);
  }

  private IntegerMap.Iterator begin() {
    return new IntegerMap.Iterator(JamiServiceJNI.IntegerMap_begin(swigCPtr, this), true);
  }

  private IntegerMap.Iterator end() {
    return new IntegerMap.Iterator(JamiServiceJNI.IntegerMap_end(swigCPtr, this), true);
  }

  private int sizeImpl() {
    return JamiServiceJNI.IntegerMap_sizeImpl(swigCPtr, this);
  }

  private boolean containsImpl(String key) {
    return JamiServiceJNI.IntegerMap_containsImpl(swigCPtr, this, key);
  }

  private void putUnchecked(String key, int value) {
    JamiServiceJNI.IntegerMap_putUnchecked(swigCPtr, this, key, value);
  }

  private void removeUnchecked(IntegerMap.Iterator itr) {
    JamiServiceJNI.IntegerMap_removeUnchecked(swigCPtr, this, IntegerMap.Iterator.getCPtr(itr), itr);
  }

}