-
Notifications
You must be signed in to change notification settings - Fork 640
dataconnect: EnumValue and EnumValueSerializer added #7153
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
Merged
dconeybe
merged 11 commits into
main
from
dconeybe/dataconnect/UserDefinedEnumsInternal
Sep 16, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b83721
dataconnect: EnumValue and EnumValueSerializer added, but not public yet
dconeybe eb1c1ae
empty commit to trigger github actions
dconeybe ce899f5
fix typo: visilibity -> visibility
dconeybe 2117741
Merge branch 'main' into dconeybe/dataconnect/UserDefinedEnumsInternal
dconeybe 0e4a3f8
Merge remote-tracking branch 'origin/main' into UserDefinedEnumsInternal
dconeybe 01a1681
CHANGELOG.md entry added
dconeybe 257f673
make the new classes public, now that api council has approved the ap…
dconeybe 0d7c206
bump minor version (instead of just patch version) since new apis are…
dconeybe de49230
Merge remote-tracking branch 'origin/main' into UserDefinedEnumsInternal
dconeybe f373e41
Merge remote-tracking branch 'origin/main' into UserDefinedEnumsInternal
dconeybe 4449d1e
use RandomSource in calls to next()
dconeybe 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
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
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,2 +1,2 @@ | ||
version=17.0.1 | ||
version=17.1.0 | ||
latestReleasedVersion=17.0.0 |
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
130 changes: 130 additions & 0 deletions
130
firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/EnumValue.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,130 @@ | ||
/* | ||
* Copyright 2025 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.firebase.dataconnect | ||
|
||
/** | ||
* Stores the value of an `enum` or a string if the string does not correspond to one of the enum's | ||
* values. | ||
*/ | ||
public sealed interface EnumValue<out T : Enum<out T>> { | ||
|
||
/** [Known.value] in the case of [Known], or `null` in the case of [Unknown]. */ | ||
public val value: T? | ||
|
||
/** | ||
* The string value of the enum, either the [Enum.name] of [Known.value] in the case of [Known] or | ||
* the `stringValue` given to the constructor in the case of [Unknown]. | ||
*/ | ||
public val stringValue: String | ||
|
||
/** | ||
* Represents an unknown enum value. | ||
* | ||
* This could happen, for example, if an enum gained a new value but this code was compiled for | ||
* the older version that lacked the new enum value. Instead of failing, the unknown enum value | ||
* will be gracefully mapped to [Unknown]. | ||
*/ | ||
public class Unknown( | ||
/** The unknown string value. */ | ||
public override val stringValue: String | ||
) : EnumValue<Nothing> { | ||
|
||
/** Always `null`. */ | ||
override val value: Nothing? = null | ||
|
||
/** | ||
* Compares this object with another object for equality. | ||
* | ||
* @param other The object to compare to this for equality. | ||
* @return true if, and only if, the other object is an instance of [Unknown] whose | ||
* [stringValue] compares equal to this object's [stringValue] using the `==` operator. | ||
*/ | ||
override fun equals(other: Any?): Boolean = other is Unknown && stringValue == other.stringValue | ||
|
||
/** | ||
* Calculates and returns the hash code for this object. | ||
* | ||
* The hash code is _not_ guaranteed to be stable across application restarts. | ||
* | ||
* @return the hash code for this object, that incorporates the values of this object's public | ||
* properties. | ||
*/ | ||
override fun hashCode(): Int = stringValue.hashCode() | ||
|
||
/** | ||
* Returns a string representation of this object, useful for debugging. | ||
* | ||
* The string representation is _not_ guaranteed to be stable and may change without notice at | ||
* any time. Therefore, the only recommended usage of the returned string is debugging and/or | ||
* logging. Namely, parsing the returned string or storing the returned string in non-volatile | ||
* storage should generally be avoided in order to be robust in case that the string | ||
* representation changes. | ||
*/ | ||
override fun toString(): String = "Unknown($stringValue)" | ||
|
||
/** Creates and returns a new [Unknown] instance with the given property values. */ | ||
public fun copy(stringValue: String = this.stringValue): Unknown = Unknown(stringValue) | ||
} | ||
|
||
/** | ||
* Represents a known enum value. | ||
* | ||
* @param value The enum value. | ||
*/ | ||
public class Known<T : Enum<T>>( | ||
/** The enum value wrapped by this object. */ | ||
override val value: T | ||
) : EnumValue<T> { | ||
|
||
/** [Enum.name] of [value]. */ | ||
override val stringValue: String | ||
get() = value.name | ||
|
||
/** | ||
* Compares this object with another object for equality. | ||
* | ||
* @param other The object to compare to this for equality. | ||
* @return true if, and only if, the other object is an instance of [Known] whose [value] | ||
* compares equal to this object's [value] using the `==` operator. | ||
*/ | ||
override fun equals(other: Any?): Boolean = other is Known<*> && value == other.value | ||
|
||
/** | ||
* Calculates and returns the hash code for this object. | ||
* | ||
* The hash code is _not_ guaranteed to be stable across application restarts. | ||
* | ||
* @return the hash code for this object, that incorporates the values of this object's public | ||
* properties. | ||
*/ | ||
override fun hashCode(): Int = value.hashCode() | ||
|
||
/** | ||
* Returns a string representation of this object, useful for debugging. | ||
* | ||
* The string representation is _not_ guaranteed to be stable and may change without notice at | ||
* any time. Therefore, the only recommended usage of the returned string is debugging and/or | ||
* logging. Namely, parsing the returned string or storing the returned string in non-volatile | ||
* storage should generally be avoided in order to be robust in case that the string | ||
* representation changes. | ||
*/ | ||
override fun toString(): String = "Known(${value.name})" | ||
|
||
/** Creates and returns a new [Known] instance with the given property values. */ | ||
public fun copy(value: T = this.value): Known<T> = Known(value) | ||
} | ||
dconeybe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.