-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http-client-java, unify branded/unbranded ExpandableEnum (#5334)
### 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); } } ```
- Loading branch information
1 parent
093e986
commit df5a885
Showing
7 changed files
with
125 additions
and
185 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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