/* ----------------------------------------------------------------------------
 * 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 com.robotraconteur;

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

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

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

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

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        RobotRaconteurJavaJNI.delete_map_strstr(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 String 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 String put(String key, String value) {
    Iterator itr = find((String) 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 String)) {
      return null;
    }

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

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

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

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

        public String 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 map_strstr() {
    this(RobotRaconteurJavaJNI.new_map_strstr__SWIG_0(), true);
  }

  public map_strstr(map_strstr other) {
    this(RobotRaconteurJavaJNI.new_map_strstr__SWIG_1(map_strstr.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;
          RobotRaconteurJavaJNI.delete_map_strstr_Iterator(swigCPtr);
        }
        swigCPtr = 0;
      }
    }
  
    private map_strstr.Iterator getNextUnchecked() {
      return new map_strstr.Iterator(RobotRaconteurJavaJNI.map_strstr_Iterator_getNextUnchecked(swigCPtr, this), true);
    }
  
    private boolean isNot(map_strstr.Iterator other) {
      return RobotRaconteurJavaJNI.map_strstr_Iterator_isNot(swigCPtr, this, map_strstr.Iterator.getCPtr(other), other);
    }
  
    private String getKey() {
      return RobotRaconteurJavaJNI.map_strstr_Iterator_getKey(swigCPtr, this);
    }
  
    private String getValue() {
      return RobotRaconteurJavaJNI.map_strstr_Iterator_getValue(swigCPtr, this);
    }
  
    private void setValue(String newValue) {
      RobotRaconteurJavaJNI.map_strstr_Iterator_setValue(swigCPtr, this, newValue);
    }
  
  }

  public boolean isEmpty() {
    return RobotRaconteurJavaJNI.map_strstr_isEmpty(swigCPtr, this);
  }

  public void clear() {
    RobotRaconteurJavaJNI.map_strstr_clear(swigCPtr, this);
  }

  private map_strstr.Iterator find(String key) {
    return new map_strstr.Iterator(RobotRaconteurJavaJNI.map_strstr_find(swigCPtr, this, key), true);
  }

  private map_strstr.Iterator begin() {
    return new map_strstr.Iterator(RobotRaconteurJavaJNI.map_strstr_begin(swigCPtr, this), true);
  }

  private map_strstr.Iterator end() {
    return new map_strstr.Iterator(RobotRaconteurJavaJNI.map_strstr_end(swigCPtr, this), true);
  }

  private int sizeImpl() {
    return RobotRaconteurJavaJNI.map_strstr_sizeImpl(swigCPtr, this);
  }

  private boolean containsImpl(String key) {
    return RobotRaconteurJavaJNI.map_strstr_containsImpl(swigCPtr, this, key);
  }

  private void putUnchecked(String key, String value) {
    RobotRaconteurJavaJNI.map_strstr_putUnchecked(swigCPtr, this, key, value);
  }

  private void removeUnchecked(map_strstr.Iterator itr) {
    RobotRaconteurJavaJNI.map_strstr_removeUnchecked(swigCPtr, this, map_strstr.Iterator.getCPtr(itr), itr);
  }

}
