/* ----------------------------------------------------------------------------
 * 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 BusHWIdVector extends java.util.AbstractList<BusHardwareId> implements java.util.RandomAccess {
  private transient long swigCPtr;
  protected transient boolean swigCMemOwn;

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

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

  protected static long swigRelease(BusHWIdVector 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_BusHWIdVector(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public BusHWIdVector(BusHardwareId[] initialElements) {
    this();
    reserve(initialElements.length);

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

  public BusHWIdVector(Iterable<BusHardwareId> initialElements) {
    this();
    for (BusHardwareId element : initialElements) {
      add(element);
    }
  }

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

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

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

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

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

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

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

  public BusHWIdVector() {
    this(NanolibJNI.new_BusHWIdVector__SWIG_0(), true);
  }

  public BusHWIdVector(BusHWIdVector other) {
    this(NanolibJNI.new_BusHWIdVector__SWIG_1(BusHWIdVector.getCPtr(other), other), true);
  }

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

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

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

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

  public BusHWIdVector(int count, BusHardwareId value) {
    this(NanolibJNI.new_BusHWIdVector__SWIG_2(count, BusHardwareId.getCPtr(value), value), true);
  }

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

  private void doAdd(BusHardwareId x) {
    NanolibJNI.BusHWIdVector_doAdd__SWIG_0(swigCPtr, this, BusHardwareId.getCPtr(x), x);
  }

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

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

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

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

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

}
