jerryshao commented on code in PR #12162: URL: https://github.com/apache/gravitino/pull/12162#discussion_r3654961453
########## api/src/main/java/org/apache/gravitino/tag/TagValueConstraint.java: ########## @@ -0,0 +1,149 @@ +/* + * 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.gravitino.tag; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.Objects; +import org.apache.commons.lang3.StringUtils; +import org.apache.gravitino.annotation.Evolving; + +/** Describes what assignment values a tag accepts. */ +@Evolving +public final class TagValueConstraint { + + private static final TagValueConstraint ANY_VALUE = + new TagValueConstraint(Type.ANY_VALUE, new String[0]); + + private static final TagValueConstraint WITHOUT_VALUES = + new TagValueConstraint(Type.WITHOUT_VALUES, new String[0]); + + private final Type type; + private final String[] allowedValues; + + private TagValueConstraint(Type type, String[] allowedValues) { + this.type = type; + this.allowedValues = allowedValues.clone(); + } + + /** The value constraint type. */ + public enum Type { + /** The tag accepts any non-empty assignment value. */ + ANY_VALUE, + + /** The tag only accepts assignments without values. */ + WITHOUT_VALUES, + + /** The tag only accepts values from the allowed value list. */ + ALLOWED_VALUES + } + + /** + * Creates a constraint that accepts any non-empty assignment value. + * + * @return The value constraint. + */ + public static TagValueConstraint anyValue() { + return ANY_VALUE; + } + + /** + * Creates a constraint that only accepts assignments without values. + * + * @return The value constraint. + */ + public static TagValueConstraint withoutValues() { + return WITHOUT_VALUES; + } + + /** + * Creates a constraint that only accepts values from the allowed value list. + * + * @param allowedValues The allowed assignment values. + * @return The value constraint. + */ + public static TagValueConstraint ofAllowedValues(String... allowedValues) { Review Comment: How about `withAllowedValues`? -- 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]
