A class mapping String keys to various value types

Introduced properties

fun []=(key: String, value: Serializable): Bundle

android :: Bundle :: []=

Add key-value information by dynamically choosing the appropriate
fun array_of_bool(key: String): nullable Array[Bool]

android :: Bundle :: array_of_bool

Retrieves the Array[Bool] value corresponding to the given key
fun array_of_char(key: String): nullable Array[Char]

android :: Bundle :: array_of_char

Retrieves the Array[Char] value corresponding to the given key
fun array_of_float(key: String): nullable Array[Float]

android :: Bundle :: array_of_float

Retrieves the Array[Float] value corresponding to the given key
fun array_of_int(key: String): nullable Array[Int]

android :: Bundle :: array_of_int

Retrieves the Array[Int] value corresponding to the given key
fun array_of_string(key: String): nullable Array[String]

android :: Bundle :: array_of_string

Retrieves the Array[String] value corresponding to the given key
fun bool(key: String, def_value: Bool): Bool

android :: Bundle :: bool

Retrieves the Bool value corresponding to the given key
fun char(key: String, def_value: Char): Char

android :: Bundle :: char

Retrieves the Char value corresponding to the given key
fun clear

android :: Bundle :: clear

Clears all entries
fun deserialize(key: String): nullable Object

android :: Bundle :: deserialize

Retrieve an Object serialized via []= function
fun deserialize_array(key: String): nullable Array[nullable Object]

android :: Bundle :: deserialize_array

Retrieve an Array of Object serialized via []= function
fun float(key: String, def_value: Float): Float

android :: Bundle :: float

Retrieves the Float value corresponding to the given key
init from(native_bundle: NativeBundle)

android :: Bundle :: from

Get a new Bundle wrapping native_bundle
fun has(key: String): Bool

android :: Bundle :: has

Returns true if the Bundle contains this key
fun int(key: String, def_value: Int): Int

android :: Bundle :: int

Retrieves the Int value corresponding to the given key
fun is_empty: Bool

android :: Bundle :: is_empty

Returns true if the current Bundle is empty
fun keys: HashSet[String]

android :: Bundle :: keys

Returns a HashSet[String] containing every mapping keys in the current
fun remove(key: String)

android :: Bundle :: remove

Removes the entry associated with the given key
fun size: Int

android :: Bundle :: size

Returns the number of entries in the current Bundle
fun string(key: String): nullable String

android :: Bundle :: string

Retrieves the String value corresponding to the given key

Redefined properties

redef type SELF: Bundle

android $ Bundle :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun []=(key: String, value: Serializable): Bundle

android :: Bundle :: []=

Add key-value information by dynamically choosing the appropriate
fun array_of_bool(key: String): nullable Array[Bool]

android :: Bundle :: array_of_bool

Retrieves the Array[Bool] value corresponding to the given key
fun array_of_char(key: String): nullable Array[Char]

android :: Bundle :: array_of_char

Retrieves the Array[Char] value corresponding to the given key
fun array_of_float(key: String): nullable Array[Float]

android :: Bundle :: array_of_float

Retrieves the Array[Float] value corresponding to the given key
fun array_of_int(key: String): nullable Array[Int]

android :: Bundle :: array_of_int

Retrieves the Array[Int] value corresponding to the given key
fun array_of_string(key: String): nullable Array[String]

android :: Bundle :: array_of_string

Retrieves the Array[String] value corresponding to the given key
fun bool(key: String, def_value: Bool): Bool

android :: Bundle :: bool

Retrieves the Bool value corresponding to the given key
fun char(key: String, def_value: Char): Char

android :: Bundle :: char

Retrieves the Char value corresponding to the given key
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun clear

android :: Bundle :: clear

Clears all entries
fun deserialize(key: String): nullable Object

android :: Bundle :: deserialize

Retrieve an Object serialized via []= function
fun deserialize_array(key: String): nullable Array[nullable Object]

android :: Bundle :: deserialize_array

Retrieve an Array of Object serialized via []= function
fun float(key: String, def_value: Float): Float

android :: Bundle :: float

Retrieves the Float value corresponding to the given key
init from(native_bundle: NativeBundle)

android :: Bundle :: from

Get a new Bundle wrapping native_bundle
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has(key: String): Bool

android :: Bundle :: has

Returns true if the Bundle contains this key
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun int(key: String, def_value: Int): Int

android :: Bundle :: int

Retrieves the Int value corresponding to the given key
fun is_empty: Bool

android :: Bundle :: is_empty

Returns true if the current Bundle is empty
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun keys: HashSet[String]

android :: Bundle :: keys

Returns a HashSet[String] containing every mapping keys in the current
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun remove(key: String)

android :: Bundle :: remove

Removes the entry associated with the given key
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun size: Int

android :: Bundle :: size

Returns the number of entries in the current Bundle
fun string(key: String): nullable String

android :: Bundle :: string

Retrieves the String value corresponding to the given key
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram android::Bundle Bundle core::Object Object android::Bundle->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

android $ Bundle
# A class mapping `String` keys to various value types
class Bundle
	private var native_bundle: NativeBundle = (new NativeBundle).new_global_ref is lazy

	# Get a new `Bundle` wrapping `native_bundle`
	init from(native_bundle: NativeBundle) do self.native_bundle = native_bundle

	# Returns `true` if the Bundle contains this key
	fun has(key: String): Bool
	do
		sys.jni_env.push_local_frame(1)
		var return_value = native_bundle.contains_key(key.to_java_string)
		sys.jni_env.pop_local_frame
		return return_value
	end

	# Returns the number of entries in the current `Bundle`
	fun size: Int do return native_bundle.size

	# Returns true if the current `Bundle` is empty
	fun is_empty: Bool do return native_bundle.is_empty

	# Clears all entries
	fun clear do native_bundle.clear

	# Removes the entry associated with the given key
	fun remove(key: String)
	do
		sys.jni_env.push_local_frame(1)
		native_bundle.remove(key.to_java_string)
		sys.jni_env.pop_local_frame
	end

	# Returns a `HashSet[String]` containing every mapping keys in the current
	# `Bundle`
	fun keys: HashSet[String]
	do
		var javastring_set = native_bundle.key_set
		var string_set = new HashSet[String]

		for element in javastring_set do
			string_set.add(element.to_s)
		end

		return string_set
	end

	# Add key-value information by dynamically choosing the appropriate
	# java method according to value type
	# If there's already a value associated with this key, the new value
	# overwrites it
	#
	# To retrieve entries, you'll have to call the type corresponding method
	# conforming to these rules:
	#
	# | Nit type              | corresponding getter            |
	# |:----------------------|:--------------------------------|
	# | `Int`                 | `long`                          |
	# | `Float`               | `double`                        |
	# | `Bool`                | `bool`                          |
	# | `Char`                | `char`                          |
	# | `String`              | `string`                        |
	# | `Serializable`        | `deserialize`                   |
	# | `Array[Int]`          | `array_of_long`                 |
	# | `Array[Float]`        | `array_of_double`               |
	# | `Array[Bool]`         | `array_of_bool`                 |
	# | `Array[Char]`         | `array_of_char`                 |
	# | `Array[String]`       | `array_of_string`               |
	# | `Array[Serializable]` | `deserialize_array`             |
	fun []=(key: String, value: Serializable): Bundle
	do
		sys.jni_env.push_local_frame(1)
		value.add_to_bundle(self.native_bundle, key.to_java_string)
		sys.jni_env.pop_local_frame
		return self
	end

	# Retrieve an `Object` serialized via `[]=` function
	# Returns `null` if there's no serialized object corresponding to the given key
	# or if it's the wrong value type
	# Make sure that the serialized object is `serialize` or that it
	# redefines the appropriate methods. Refer to `Serializable` documentation
	# for further details
	fun deserialize(key: String): nullable Object
	do
		var serialized_string = self.string(key)

		if serialized_string == null then return null

		var deserializer = new JsonDeserializer(serialized_string)

		return deserializer.deserialize
	end

	# Retrieve an `Array` of `Object` serialized via `[]=` function
	# Returns `null` if there's no serialized `Array` corresponding to the given key
	# or if it's the wrong value type
	# Make sure that the serialized objects are `serialize` or that they
	# redefine the appropriate methods. Refer to `Serializable` documentation
	# for further details
	fun deserialize_array(key: String): nullable Array[nullable Object]
	do
		var serialized_array = self.array_of_string(key)

		if serialized_array == null then return null

		var deserialized_array = new Array[nullable Object]

		for serialized_element in serialized_array do
			var deserializer = new JsonDeserializer(serialized_element)
			deserialized_array.add(deserializer.deserialize)
		end

		return deserialized_array
	end

	# Retrieves the `String` value corresponding to the given key
	# Returns `null` if none or if it's the wrong value type
	fun string(key: String): nullable String
	do
		sys.jni_env.push_local_frame(2)

		var jstr = native_bundle.get_string(key.to_java_string)
		var str = null
		if not jstr.is_java_null then str = jstr.to_s

		sys.jni_env.pop_local_frame

		return str
	end

	# Retrieves the `Bool` value corresponding to the given key
	# Returns the `def_value` if none or if it's the wrong value type
	fun bool(key: String, def_value: Bool): Bool
	do
		sys.jni_env.push_local_frame(1)
		var return_value =
			native_bundle.get_boolean_with_def_value(key.to_java_string, def_value)
		sys.jni_env.pop_local_frame
		return return_value
	end

	# Retrieves the `Char` value corresponding to the given key
	# Returns the `def_value` if none or if it's the wrong value type
	# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
	fun char(key: String, def_value: Char): Char
	do
		sys.jni_env.push_local_frame(1)
		var return_value =
			native_bundle.get_char_with_def_value(key.to_java_string, def_value)
		sys.jni_env.pop_local_frame
		return return_value
	end

	# Retrieves the `Int` value corresponding to the given key
	# Returns the `def_value` if none or if it's the wrong value type
	fun int(key: String, def_value: Int): Int
	do
		sys.jni_env.push_local_frame(1)
		var return_value =
			native_bundle.get_long_with_def_value(key.to_java_string, def_value)
		sys.jni_env.pop_local_frame
		return return_value
	end

	# Retrieves the `Float` value corresponding to the given key
	# Returns the `def_value` if none or if it's the wrong value type
	fun float(key: String, def_value: Float): Float
	do
		sys.jni_env.push_local_frame(1)
		var return_value =
			native_bundle.get_double_with_def_value(key.to_java_string, def_value)
		sys.jni_env.pop_local_frame
		return return_value
	end

	# Retrieves the `Array[Float]` value corresponding to the given key
	# Returns the `null` if none or if it's the wrong value type
	fun array_of_float(key: String): nullable Array[Float]
	do
		sys.jni_env.push_local_frame(1)
		var return_value = native_bundle.get_double_array(key.to_java_string)
		sys.jni_env.pop_local_frame

		if return_value.is_empty then return null

		return return_value
	end

	# Retrieves the `Array[Char]` value corresponding to the given key
	# Returns the `null` if none or if it's the wrong value type
	# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
	fun array_of_char(key: String): nullable Array[Char]
	do
		sys.jni_env.push_local_frame(1)
		var return_value = native_bundle.get_char_array(key.to_java_string)
		sys.jni_env.pop_local_frame

		if return_value.is_empty then return null

		return return_value
	end
	# Retrieves the `Array[Int]` value corresponding to the given key
	# Returns the `null` if none or if it's the wrong value type
	fun array_of_int(key: String): nullable Array[Int]
	do
		sys.jni_env.push_local_frame(1)
		var return_value = native_bundle.get_long_array(key.to_java_string)
		sys.jni_env.pop_local_frame

		if return_value.is_empty then return null

		return return_value
	end

	# Retrieves the `Array[Bool]` value corresponding to the given key
	# Returns the `null` if none or if it's the wrong value type
	fun array_of_bool(key: String): nullable Array[Bool]
	do
		sys.jni_env.push_local_frame(1)
		var return_value = native_bundle.get_boolean_array(key.to_java_string)
		sys.jni_env.pop_local_frame

		if return_value.is_empty then return null

		return return_value
	end

	# Retrieves the `Array[String]` value corresponding to the given key
	# Returns the `null` if none or if it's the wrong value type
	fun array_of_string(key: String): nullable Array[String]
	do
		sys.jni_env.push_local_frame(1)

		var return_value = native_bundle.get_string_array(key.to_java_string)
		sys.jni_env.pop_local_frame

		if return_value.is_empty then return null

		return return_value
	end
end
lib/android/bundle/bundle.nit:427,1--668,3