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

package org.equeim.libtremotesf;

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

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

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

  protected static long swigRelease(TorrentPeersVector 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;
        libtremotesfJNI.delete_TorrentPeersVector(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public TorrentPeersVector(Peer[] initialElements) {
    this();
    reserve(initialElements.length);

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

  public TorrentPeersVector(Iterable<Peer> initialElements) {
    this();
    for (Peer element : initialElements) {
      add(element);
    }
  }

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

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

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

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

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

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

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

  public TorrentPeersVector() {
    this(libtremotesfJNI.new_TorrentPeersVector__SWIG_0(), true);
  }

  public TorrentPeersVector(TorrentPeersVector other) {
    this(libtremotesfJNI.new_TorrentPeersVector__SWIG_1(TorrentPeersVector.getCPtr(other), other), true);
  }

  public long capacity() {
    return libtremotesfJNI.TorrentPeersVector_capacity(swigCPtr, this);
  }

  public void reserve(long n) {
    libtremotesfJNI.TorrentPeersVector_reserve(swigCPtr, this, n);
  }

  public boolean isEmpty() {
    return libtremotesfJNI.TorrentPeersVector_isEmpty(swigCPtr, this);
  }

  public void clear() {
    libtremotesfJNI.TorrentPeersVector_clear(swigCPtr, this);
  }

  public TorrentPeersVector(int count, Peer value) {
    this(libtremotesfJNI.new_TorrentPeersVector__SWIG_2(count, Peer.getCPtr(value), value), true);
  }

  private int doSize() {
    return libtremotesfJNI.TorrentPeersVector_doSize(swigCPtr, this);
  }

  private void doAdd(Peer x) {
    libtremotesfJNI.TorrentPeersVector_doAdd__SWIG_0(swigCPtr, this, Peer.getCPtr(x), x);
  }

  private void doAdd(int index, Peer x) {
    libtremotesfJNI.TorrentPeersVector_doAdd__SWIG_1(swigCPtr, this, index, Peer.getCPtr(x), x);
  }

  private Peer doRemove(int index) {
    return new Peer(libtremotesfJNI.TorrentPeersVector_doRemove(swigCPtr, this, index), true);
  }

  private Peer doGet(int index) {
    return new Peer(libtremotesfJNI.TorrentPeersVector_doGet(swigCPtr, this, index), false);
  }

  private Peer doSet(int index, Peer val) {
    return new Peer(libtremotesfJNI.TorrentPeersVector_doSet(swigCPtr, this, index, Peer.getCPtr(val), val), true);
  }

  private void doRemoveRange(int fromIndex, int toIndex) {
    libtremotesfJNI.TorrentPeersVector_doRemoveRange(swigCPtr, this, fromIndex, toIndex);
  }

}
