Universe::JavaList class

The JavaList class is a wrapper allowing to easily handle Java objects that are instances of List (and in particular of ArrayList).

Public static functions

static auto newInstance() -> Universe::JavaList
static auto newInstance(int size) -> Universe::JavaList
static auto of(easyjni::JavaObject list) -> Universe::JavaList
template<typename T>
static auto from(const std::vector<T>& vector, std::function<easyjni::JavaObject(T)> fct) -> Universe::JavaList

Public functions

auto operator*() -> easyjni::JavaObject
auto size() -> int
void add(easyjni::JavaObject elt)
auto get(int index) -> easyjni::JavaObject
void clear()
template<typename T>
auto asVector(std::function<T(easyjni::JavaObject)> fct) -> std::vector<T>

Function documentation

static Universe::JavaList Universe::JavaList::newInstance()

Returns The created object.

Creates a new Java object that is an instance of ArrayList.

static Universe::JavaList Universe::JavaList::newInstance(int size)

Parameters
size The initial size of the list to create.
Returns The created object.

Creates a new Java object that is an instance of ArrayList, with the given initial size.

static Universe::JavaList Universe::JavaList::of(easyjni::JavaObject list)

Parameters
list The existing Java object.
Returns The wrapper for the object.

Creates a new JavaList from an existing Java object that is an instance of List.

template<typename T>
static Universe::JavaList Universe::JavaList::from(const std::vector<T>& vector, std::function<easyjni::JavaObject(T)> fct)

Template parameters
T The type of the elements in the vector.
Parameters
vector The vector to create a list from.
fct The function to apply to transform each element in the vector to a JavaObject.
Returns The created object.

Creates a new JavaList from a C++ vector.

easyjni::JavaObject Universe::JavaList::operator*()

Returns The wrapped Java object.

Gives the Java object that is wrapped in this JavaList.

int Universe::JavaList::size()

Returns The size of this list.

Gives the size of this list, measured as its number of elements.

void Universe::JavaList::add(easyjni::JavaObject elt)

Parameters
elt The element to add to this list.

Adds an element to this list.

easyjni::JavaObject Universe::JavaList::get(int index)

Parameters
index The index of the element.
Returns The element at the given index.

Gives the element in this list at the specified index.

void Universe::JavaList::clear()

Removes all the elements from this list.

template<typename T>
std::vector<T> Universe::JavaList::asVector(std::function<T(easyjni::JavaObject)> fct)

Template parameters
T The type of the elements in the output vector.
Parameters
fct The function to apply to transform each Java object in this list to an instance of T.
Returns The vector representation of this Java object.

Gives the representation of this JavaList as a vector.