-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port to Kotlin Multiplatform #25
Conversation
Locale.kt: WIP
# Conflicts: # library/src/main/java/de/westnordost/osmfeatures/CollectionUtils.kt # library/src/main/java/de/westnordost/osmfeatures/FeatureDictionnary.kt # library/src/main/java/de/westnordost/osmfeatures/StartsWithStringTree.kt
# Conflicts: # library/src/main/java/de/westnordost/osmfeatures/ContainedMapTree.kt
# Conflicts: # library/src/commonMain/kotlin/de.westnordost.osmfeatures/BaseFeature.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/CollectionUtils.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/ContainedMapTree.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/Feature.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/FeatureDictionnary.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/FeatureTagsIndex.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/FeatureTermIndex.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/FileAccessAdapter.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/FileSystemAccess.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/GeometryType.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDBrandPresetsFeatureCollection.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDLocalizedFeatureCollection.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDPresetsJsonParser.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDPresetsTranslationJsonParser.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/JsonUtils.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/Locale.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/LocalizedFeature.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/LocalizedFeatureCollection.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/PerCountryFeatureCollection.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/StartsWithStringTree.kt # library/src/commonMain/kotlin/de.westnordost.osmfeatures/StringUtils.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/CollectionUtilsTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/FeatureDictionaryTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/FeatureTagsIndexTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/FeatureTermIndexTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDBrandPresetsFeatureCollectionTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDLocalizedFeatureCollectionTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDPresetsJsonParserTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDPresetsTranslationJsonParserTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/JsonUtilsTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/LivePresetDataAccessAdapter.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/StartsWithStringTreeTest.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/TestLocalizedFeatureCollection.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/TestPerCountryFeatureCollection.kt # library/src/commonTest/kotlin/de.westnordost.osmfeatures/TestUtils.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very incomplete review while in the train. I think when home I'll rather check out the branch and correct all the small issues I find myself and only note the bigger ones (if any) here on github, more efficient that way.
It's a good idea to have the Android-specific stuff in the Android-part of the library itself, makes sense.
Four general comments:
-
The directory name looks suspect:library/src/commonMain/kotlin/de.westnordost.osmfeatures/...
- i.e. why are there dots in the name instead of subdirectories? It's the first time that I see this. I checked the Kotlin coding conventions and didn't see that mentioned. -
Regarding the build.gradle.kts: I recently created another kotlin multiplatform library, maybe you could copy it from there: https://github.com/westnordost/osm-opening-hours
-
Some fields, parameters and variables you made nullable even though this looks like an oversight. In case it is not, comments should be added to the source to explain / document it. -
With kotlinx-serialization-json it is not necessary (nor recommended, as far as I know) to do JSON parsing by hand. You can simply annotate the data model how it should be (de)serialized. See https://kotlinlang.org/docs/serialization.html#serialize-and-deserialize-json . Did you not know this, or is there some reason why you chose to parse it by hand?
library/src/commonMain/kotlin/de.westnordost.osmfeatures/Feature.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/BaseFeature.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/Feature.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/LocalizedFeature.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/LocalizedFeature.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/StartsWithStringTree.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/StringUtils.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/ContainedMapTree.kt
Outdated
Show resolved
Hide resolved
library/src/commonMain/kotlin/de.westnordost.osmfeatures/BaseFeature.kt
Outdated
Show resolved
Hide resolved
Alright, merged. In the end, the line of code count is only 72% of what we had for Java. 🎉 Since we made breaking changes to the API anyway (Locale -> String), I also changed a few more things that were bothering me. For the time being, the initialization of the multiplatform version is about 15% slower than before. I think this is mainly due to whole file read into a string first, then into a DOM and then only in the final data structure. At least the first step should be solvable once kotlinx-serialization-json supports directly reading |
Wow, 72% reduction is impressive 🎉 |
Nono, reduction TO 72% |
Work still need to be done:
library-android
has been moved toandroidMain
FileSystem.SYSTEM
is not available in commonMain.