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

package com.nanotec.nanolib;

public class ProfinetDeviceVector extends java.util.AbstractList<ProfinetDevice> implements java.util.RandomAccess {
  private transient long swigCPtr;
  protected transient boolean swigCMemOwn;

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

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

  protected static long swigRelease(ProfinetDeviceVector 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;
  }

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

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

  public ProfinetDeviceVector(ProfinetDevice[] initialElements) {
    this();
    reserve(initialElements.length);

    for (ProfinetDevice element : initialElements) {
      add(element);
    }
  }

  public ProfinetDeviceVector(Iterable<ProfinetDevice> initialElements) {
    this();
    for (ProfinetDevice element : initialElements) {
      add(element);
    }
  }

  public ProfinetDevice get(int index) {
    return doGet(index);
  }

  public ProfinetDevice set(int index, ProfinetDevice e) {
    return doSet(index, e);
  }

  public boolean add(ProfinetDevice e) {
    modCount++;
    doAdd(e);
    return true;
  }

  public void add(int index, ProfinetDevice e) {
    modCount++;
    doAdd(index, e);
  }

  public ProfinetDevice remove(int index) {
    modCount++;
    return doRemove(index);
  }

  protected void removeRange(int fromIndex, int toIndex) {
    modCount++;
    doRemoveRange(fromIndex, toIndex);
  }

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

  public ProfinetDeviceVector() {
    this(NanolibJNI.new_ProfinetDeviceVector__SWIG_0(), true);
  }

  public ProfinetDeviceVector(ProfinetDeviceVector other) {
    this(NanolibJNI.new_ProfinetDeviceVector__SWIG_1(ProfinetDeviceVector.getCPtr(other), other), true);
  }

  public long capacity() {
    return NanolibJNI.ProfinetDeviceVector_capacity(swigCPtr, this);
  }

  public void reserve(long n) {
    NanolibJNI.ProfinetDeviceVector_reserve(swigCPtr, this, n);
  }

  public boolean isEmpty() {
    return NanolibJNI.ProfinetDeviceVector_isEmpty(swigCPtr, this);
  }

  public void clear() {
    NanolibJNI.ProfinetDeviceVector_clear(swigCPtr, this);
  }

  public ProfinetDeviceVector(int count, ProfinetDevice value) {
    this(NanolibJNI.new_ProfinetDeviceVector__SWIG_2(count, ProfinetDevice.getCPtr(value), value), true);
  }

  private int doSize() {
    return NanolibJNI.ProfinetDeviceVector_doSize(swigCPtr, this);
  }

  private void doAdd(ProfinetDevice x) {
    NanolibJNI.ProfinetDeviceVector_doAdd__SWIG_0(swigCPtr, this, ProfinetDevice.getCPtr(x), x);
  }

  private void doAdd(int index, ProfinetDevice x) {
    NanolibJNI.ProfinetDeviceVector_doAdd__SWIG_1(swigCPtr, this, index, ProfinetDevice.getCPtr(x), x);
  }

  private ProfinetDevice doRemove(int index) {
    return new ProfinetDevice(NanolibJNI.ProfinetDeviceVector_doRemove(swigCPtr, this, index), true);
  }

  private ProfinetDevice doGet(int index) {
    return new ProfinetDevice(NanolibJNI.ProfinetDeviceVector_doGet(swigCPtr, this, index), false);
  }

  private ProfinetDevice doSet(int index, ProfinetDevice val) {
    return new ProfinetDevice(NanolibJNI.ProfinetDeviceVector_doSet(swigCPtr, this, index, ProfinetDevice.getCPtr(val), val), true);
  }

  private void doRemoveRange(int fromIndex, int toIndex) {
    NanolibJNI.ProfinetDeviceVector_doRemoveRange(swigCPtr, this, fromIndex, toIndex);
  }

}
