Universe::JavaMapOfString class

The JavaMapOfString class is a wrapper allowing to easily handle Java objects that are instances of Map (and in particular of HashMap), using strings as keys.

Public static functions

static auto newInstance() -> Universe::JavaMapOfString
static auto of(easyjni::JavaObject jMap) -> Universe::JavaMapOfString
template<typename V>
static auto from(const std::map<std::string, V>& map, std::function<easyjni::JavaObject(V)> fct) -> Universe::JavaMapOfString

Public functions

auto operator*() -> easyjni::JavaObject
auto size() -> int
void put(const std::string& key, easyjni::JavaObject value)
auto get(const std::string& key) -> easyjni::JavaObject
void clear()
template<typename V>
auto asMap(std::function<V(easyjni::JavaObject)> fct) -> std::map<std::string, V>

Function documentation

static Universe::JavaMapOfString Universe::JavaMapOfString::newInstance()

Returns The created object.

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

static Universe::JavaMapOfString Universe::JavaMapOfString::of(easyjni::JavaObject jMap)

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

Creates a new JavaMapOfString from an existing Java object that is an instance of Map.

template<typename V>
static Universe::JavaMapOfString Universe::JavaMapOfString::from(const std::map<std::string, V>& map, std::function<easyjni::JavaObject(V)> fct)

Template parameters
V The type of the values in the map.
Parameters
map The map to create a Java map from.
fct The function to apply to transform each value in the map to a JavaObject.
Returns The created object.

Creates a new JavaMapOfString from a C++ map.

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

Returns The wrapped Java object.

Gives the Java object that is wrapped in this JavaMapOfString.

int Universe::JavaMapOfString::size()

Returns The size of this map.

Gives the size of this map, measured as its number of key-value pairs.

void Universe::JavaMapOfString::put(const std::string& key, easyjni::JavaObject value)

Parameters
key The key to put in this map.
value The value associated with the key.

Puts a key-value pair in this map.

easyjni::JavaObject Universe::JavaMapOfString::get(const std::string& key)

Parameters
key The key of the value to get.
Returns The value associated with the given key.

Gives the value associated with the given key in this map.

void Universe::JavaMapOfString::clear()

Removes all the elements from this map.

template<typename V>
std::map<std::string, V> Universe::JavaMapOfString::asMap(std::function<V(easyjni::JavaObject)> fct)

Template parameters
V The type of the values in the output map.
Parameters
fct The function to apply to transform each Java object in this map to an instance of V.
Returns The map representation of this Java object.

Gives the representation of this JavaMapOfString as a C++ map.