-
Notifications
You must be signed in to change notification settings - Fork 8
Convert more files from java to kotlin #94
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
Open
lucianbc
wants to merge
1
commit into
main
Choose a base branch
from
more-java-to-kt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 0 additions & 112 deletions
112
...ns/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/SizedIterator.java
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
...ions/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/SizedIterator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright 2023 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.wear.watchface.dfx.memory | ||
|
|
||
| /** | ||
| * A lazy iterator, allowing to generate all combinations of a set without getting into stack | ||
| * overflows. | ||
| */ | ||
| internal interface SizedIterator<T> : Iterator<T> { | ||
| /** The size of the collection of elements that is generated */ | ||
| fun getSize(): Long | ||
|
|
||
| companion object { | ||
| /** Constructs a sized iterator from a plain java iterator and a size. */ | ||
| fun <T> fromIterator(iterator: Iterator<T>, size: Long): SizedIterator<T> { | ||
| return object : SizedIterator<T> { | ||
| override fun getSize(): Long { | ||
| return size | ||
| } | ||
|
|
||
| override fun hasNext(): Boolean { | ||
| return iterator.hasNext() | ||
| } | ||
|
|
||
| override fun next(): T { | ||
| return iterator.next() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Lazily combines an existing iterator with a new collection of elements by taking every | ||
| * element of the new collection and combining it with every element of the existing | ||
| * iterator. The resulting iterator will have a size of iterator.size() * elements.size(). | ||
| * | ||
| * @param iterator the existing iterator | ||
| * @param elements the collection providing the new elements that are combined with the | ||
| * already generated ones. | ||
| * @param combineFn the function used to combine each element of the elements argument with | ||
| * each element of the existing iterator. | ||
| * @param mapFn the function used to map a single element of the elements collection to | ||
| * elements of the iterator, used when the existing iterator is empty and combineFn cannot | ||
| * be called. | ||
| * @return a new iterator with the combined elements. | ||
| * @param <T> the elements of the iterator | ||
| * @param <U> the elements of the collection | ||
| */ | ||
| fun <T, U> combine( | ||
| iterator: SizedIterator<T>, | ||
| elements: Collection<U>, | ||
| combineFn: (T, U) -> T, | ||
| mapFn: (U) -> T | ||
| ): SizedIterator<T> { | ||
| // if the current key does not have any configuration values, then ignore it | ||
| // and return the next iterator. | ||
| if (elements.isEmpty()) { | ||
| return iterator | ||
| } | ||
|
|
||
| // if the rest iterator has no configuration values, then start a new iterator | ||
| // from the current keys. | ||
| if (!iterator.hasNext()) { | ||
| return fromIterator(elements.stream().map(mapFn).iterator(), elements.size.toLong()) | ||
| } | ||
|
|
||
| // lazily consume each partial config from the rest iterator and append each value for | ||
| // the | ||
| // current key, producing new partial configs. | ||
| return object : SizedIterator<T> { | ||
| private val _size = elements.size * iterator.getSize() | ||
| private var crtValuesIter = elements.iterator() | ||
| private var currentFromTail = iterator.next() | ||
| override fun getSize(): Long { | ||
| return _size | ||
| } | ||
|
|
||
| override fun hasNext(): Boolean { | ||
| return crtValuesIter.hasNext() || iterator.hasNext() | ||
| } | ||
|
|
||
| override fun next(): T { | ||
| if (!crtValuesIter.hasNext()) { | ||
| crtValuesIter = elements.iterator() | ||
| currentFromTail = iterator.next() | ||
| } | ||
| return combineFn(currentFromTail, crtValuesIter.next()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 14 additions & 15 deletions
29
...hface/dfx/memory/TestResultFormatter.java → ...tchface/dfx/memory/TestResultFormatter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,35 @@ | ||
| /* | ||
| * Copyright 2023 Google LLC | ||
| * | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.wear.watchface.dfx.memory; | ||
| package com.google.wear.watchface.dfx.memory | ||
|
|
||
| /** Annotates test results to make it easier for humans to read them. */ | ||
| class TestResultFormatter { | ||
|
|
||
| static String formatSuccess(String successMessage) { | ||
| return String.format("[MEMORY_FOOTPRINT]: ✅PASS✅ %s ✅ ", successMessage); | ||
| internal object TestResultFormatter { | ||
| @JvmStatic | ||
| fun formatSuccess(successMessage: String): String { | ||
| return "[MEMORY_FOOTPRINT]: ✅PASS✅ $successMessage ✅ " | ||
| } | ||
|
|
||
| static String formatFailure(String failedMessage) { | ||
| return String.format("[MEMORY_FOOTPRINT]: ❌FAIL❌ %s ❌ ", failedMessage); | ||
| @JvmStatic | ||
| fun formatFailure(failedMessage: String): String { | ||
| return "[MEMORY_FOOTPRINT]: ❌FAIL❌ $failedMessage ❌ " | ||
| } | ||
|
|
||
| static String formatException(String exceptionMessage) { | ||
| return String.format( | ||
| "%s\n%s", | ||
| "❗❗❗❗ Something went wrong. Please retry or seek assistance.❗❗❗❗", | ||
| exceptionMessage); | ||
| @JvmStatic | ||
| fun formatException(exceptionMessage: String): String { | ||
| return "❗❗❗❗ Something went wrong. Please retry or seek assistance.❗❗❗❗\n$exceptionMessage" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice touch adding the emoji for clarity! One small concern is that emojis might not render consistently across all environments (encoding, terminals, IDEs). To keep things universally compatible, maybe we could stick to plain ASCII symbols like !, or x instead.