A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/6c0033075 below:

Add SerializableType to PropertyMap, closes #1250 · AlmasB/FXGL@6c00330 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+46

-1

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+46

-1

lines changed Original file line number Diff line number Diff line change

@@ -9,6 +9,8 @@ package com.almasb.fxgl.core.collection

9 9

import javafx.beans.property.*

10 10

import javafx.beans.value.ChangeListener

11 11

import javafx.beans.value.ObservableValue

12 +

import com.almasb.fxgl.core.serialization.SerializableType

13 +

import com.almasb.fxgl.core.serialization.Bundle

12 14

import java.util.*

13 15 14 16

@@ -23,10 +25,11 @@ import java.util.*

23 25

* SimpleObjectProperty.

24 26

*

25 27

* Null values are not allowed.

28 +

* Object Properties are not supported for Serialization.

26 29

*

27 30

* @author Almas Baimagambetov (almaslvl@gmail.com)

28 31

*/

29 -

class PropertyMap {

32 +

class PropertyMap : SerializableType {

30 33 31 34

companion object {

32 35

@JvmStatic fun fromStringMap(map: Map<String, String>): PropertyMap {

@@ -309,6 +312,20 @@ class PropertyMap {

309 312

}

310 313

}

311 314 315 +

override fun write(bundle: Bundle) {

316 +

// Convert to string map

317 +

this.toStringMap().forEach { (key, value) ->

318 +

// write to bundle

319 +

bundle.put(key, value)

320 +

}

321 +

}

322 + 323 +

override fun read(bundle: Bundle) {

324 +

bundle.data.forEach { (key, value) ->

325 +

this.setValue(key, toValue(value.toString()))

326 +

}

327 +

}

328 + 312 329

override fun toString(): String {

313 330

return properties.toMap().toString()

314 331

}

Original file line number Diff line number Diff line change

@@ -7,6 +7,7 @@

7 7

package com.almasb.fxgl.core.collection

8 8 9 9

import com.almasb.fxgl.core.math.Vec2

10 +

import com.almasb.fxgl.core.serialization.Bundle

10 11

import javafx.beans.property.SimpleIntegerProperty

11 12

import javafx.beans.property.StringProperty

12 13

import org.hamcrest.MatcherAssert.assertThat

@@ -412,6 +413,33 @@ class PropertyMapTest {

412 413

assertThat(map2.getBoolean("key5"), `is`(true))

413 414

}

414 415 416 +

@Test

417 +

fun `Serialize Property Map`() {

418 +

// Set test values

419 +

map.setValue("key1", "ABC")

420 +

map.setValue("key2", 100)

421 +

map.setValue("key3", 10.0)

422 +

map.setValue("key4", true)

423 + 424 +

// Create a bundle

425 +

val testBundle = Bundle("propertyMap")

426 + 427 +

// Write to bundle

428 +

map.write(testBundle)

429 + 430 +

// Create a new PropertyMap to test

431 +

val map2 = PropertyMap()

432 + 433 +

// Read from bundle

434 +

map2.read(testBundle)

435 + 436 +

// Check test values

437 +

assertThat(map2.getString("key1"), `is`("ABC"))

438 +

assertThat(map2.getInt("key2"), `is`(100))

439 +

assertThat(map2.getDouble("key3"), `is`(10.0))

440 +

assertThat(map2.getBoolean("key4"), `is`(true))

441 +

}

442 + 415 443

private class MyClass(val i: Int)

416 444 417 445

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4