chaokunyang commented on code in PR #3062: URL: https://github.com/apache/fory/pull/3062#discussion_r2637540972
########## java/fory-core/src/main/java/org/apache/fory/type/union/Union4.java: ########## @@ -0,0 +1,266 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.fory.type.union; + +import java.util.Objects; + +/** + * A typed union that can hold one of four alternative types. The active alternative is identified + * by an index (0, 1, 2, or 3). + * + * <p>This class provides a type-safe way to represent values that can be one of four types. + * + * <p>Usage example: + * + * <pre>{@code + * // Create a union holding a String (type T2, index 1) + * Union4<Integer, String, Double, Boolean> union = Union4.ofT2("hello"); + * + * // Get the value + * if (union.isT2()) { + * String value = union.getT2(); + * } + * }</pre> + * + * @param <T1> the first alternative type + * @param <T2> the second alternative type + * @param <T3> the third alternative type + * @param <T4> the fourth alternative type + */ +public class Union4<T1, T2, T3, T4> { Review Comment: could we also add union5 and 6. I think six can cover most cases. If not user can use geenric Union instead. Please also document this in the javadoc. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
