-
Notifications
You must be signed in to change notification settings - Fork 226
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
http-client-java, unify branded/unbranded ExpandableEnum #5334
Merged
XiaofeiCao
merged 6 commits into
microsoft:main
from
XiaofeiCao:java_fix_unbranded_non_string_expandable_enum
Dec 12, 2024
Merged
http-client-java, unify branded/unbranded ExpandableEnum #5334
XiaofeiCao
merged 6 commits into
microsoft:main
from
XiaofeiCao:java_fix_unbranded_non_string_expandable_enum
Dec 12, 2024
Conversation
This file contains 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
microsoft-github-policy-service
bot
added
the
emitter:client:java
Issue for the Java client emitter: @typespec/http-client-java
label
Dec 11, 2024
No changes needing a change description found. |
XiaofeiCao
requested review from
srnagar,
weidongxu-microsoft and
haolingdong-msft
as code owners
December 11, 2024 09:56
You can try these changes here
|
weidongxu-microsoft
approved these changes
Dec 12, 2024
archerzz
pushed a commit
to archerzz/typespec
that referenced
this pull request
Dec 17, 2024
) ### Issue - Last item of Azure/autorest.java#2841 - Previous unbranded implementation has two major issues - No `equals()` override - Non-string implementation can't compile ### This PR - Apply current branded ExpandableEnum interface implementation to unbranded - `fromString` will be unified as `fromValue`, and will throw if parameter is null(previously will return null) ### Test Tested with openai, no compilation issue found: ```java// Code generated by Microsoft (R) TypeSpec Code Generator. package com.openai; import io.clientcore.core.annotation.Metadata; import io.clientcore.core.util.ExpandableEnum; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; /** * Defines values for OlympicRecordModel. */ public final class OlympicRecordModel implements ExpandableEnum<Double> { private static final Map<Double, OlympicRecordModel> VALUES = new ConcurrentHashMap<>(); private static final Function<Double, OlympicRecordModel> NEW_INSTANCE = OlympicRecordModel::new; /** * Static value 9.58 for OlympicRecordModel. */ @metadata(generated = true) public static final OlympicRecordModel OLYMPIC_100_METERS = fromValue(9.58); /** * Static value 19.3 for OlympicRecordModel. */ @metadata(generated = true) public static final OlympicRecordModel OLYMPIC_200_METERS = fromValue(19.3); private final Double value; private OlympicRecordModel(Double value) { this.value = value; } /** * Creates or finds a OlympicRecordModel. * * @param value a value to look for. * @return the corresponding OlympicRecordModel. * @throws IllegalArgumentException if value is null. */ @metadata(generated = true) public static OlympicRecordModel fromValue(Double value) { if (value == null) { throw new IllegalArgumentException("'value' cannot be null."); } return VALUES.computeIfAbsent(value, NEW_INSTANCE); } /** * Gets known OlympicRecordModel values. * * @return Known OlympicRecordModel values. */ @metadata(generated = true) public static Collection<OlympicRecordModel> values() { return new ArrayList<>(VALUES.values()); } /** * Gets the value of the OlympicRecordModel instance. * * @return the value of the OlympicRecordModel instance. */ @metadata(generated = true) @OverRide public Double getValue() { return this.value; } @metadata(generated = true) @OverRide public String toString() { return Objects.toString(this.value); } @metadata(generated = true) @OverRide public boolean equals(Object obj) { return this == obj; } @metadata(generated = true) @OverRide public int hashCode() { return Objects.hashCode(this.value); } } ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
toJson
, it called non-existtoInt
method on extensible enum whose value is Integer. Azure/autorest.java#2841equals()
overrideThis PR
fromString
will be unified asfromValue
, and will throw if parameter is null(previously will return null)Test
Tested with openai, no compilation issue found: