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

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

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

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

  public ByteVector(short[] initialElements) {
    this();
    reserve(initialElements.length);

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

  public ByteVector(Iterable<Short> initialElements) {
    this();
    for (short element : initialElements) {
      add(element);
    }
  }

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

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

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

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

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

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

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

  public ByteVector() {
    this(NanolibJNI.new_ByteVector__SWIG_0(), true);
  }

  public ByteVector(ByteVector other) {
    this(NanolibJNI.new_ByteVector__SWIG_1(ByteVector.getCPtr(other), other), true);
  }

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

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

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

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

  public ByteVector(int count, short value) {
    this(NanolibJNI.new_ByteVector__SWIG_2(count, value), true);
  }

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

  private void doAdd(short x) {
    NanolibJNI.ByteVector_doAdd__SWIG_0(swigCPtr, this, x);
  }

  private void doAdd(int index, short x) {
    NanolibJNI.ByteVector_doAdd__SWIG_1(swigCPtr, this, index, x);
  }

  private short doRemove(int index) {
    return NanolibJNI.ByteVector_doRemove(swigCPtr, this, index);
  }

  private short doGet(int index) {
    return NanolibJNI.ByteVector_doGet(swigCPtr, this, index);
  }

  private short doSet(int index, short val) {
    return NanolibJNI.ByteVector_doSet(swigCPtr, this, index, val);
  }

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

}
