roryqi commented on code in PR #12162: URL: https://github.com/apache/gravitino/pull/12162#discussion_r3663667030
########## api/src/main/java/org/apache/gravitino/tag/TagAssignment.java: ########## @@ -0,0 +1,113 @@ +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.apache.gravitino.annotation.Evolving; + +/** Represents a tag assignment in a metadata-object context. */ +@Evolving +public final class TagAssignment { + + private static final TagAssignment WITHOUT_VALUES = new TagAssignment(new String[0]); + + private final String[] values; + + private TagAssignment(String[] values) { + this.values = values.clone(); + } + + /** + * Creates an assignment without values. + * + * @return The tag assignment. + */ + public static TagAssignment withoutValues() { Review Comment: Fixed. Renamed the factory to `noValue()`. ########## api/src/main/java/org/apache/gravitino/tag/TagAssignment.java: ########## @@ -0,0 +1,113 @@ +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.apache.gravitino.annotation.Evolving; + +/** Represents a tag assignment in a metadata-object context. */ +@Evolving +public final class TagAssignment { + + private static final TagAssignment WITHOUT_VALUES = new TagAssignment(new String[0]); Review Comment: Fixed. Renamed the singleton/type wording to `NO_VALUE`. ########## api/src/main/java/org/apache/gravitino/tag/TagValue.java: ########## @@ -0,0 +1,114 @@ +/* + * 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.Objects; +import java.util.Optional; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; +import org.apache.gravitino.annotation.Evolving; + +/** Represents one tag assignment value in tag association requests. */ +@Evolving +public final class TagValue { + + private final String name; + + @Nullable private final String value; + + private TagValue(String name, @Nullable String value) { + this.name = name; + this.value = value; + } + + /** + * Creates a valued tag assignment value. + * + * @param name The tag name. + * @param value The assignment value. + * @return The tag value. + */ + public static TagValue of(String name, String value) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Tag name must not be blank"); + Preconditions.checkArgument(StringUtils.isNotBlank(value), "Tag value must not be blank"); + return new TagValue(name, value); + } + + /** + * Creates a valueless tag assignment value. + * + * @param name The tag name. + * @return The tag value. + */ + public static TagValue valueless(String name) { Review Comment: Fixed. Renamed `TagValue.valueless(name)` to `TagValue.noValue(name)` and updated the wording to avoid the overloaded meaning of "valueless". ########## api/src/main/java/org/apache/gravitino/tag/TagValueConstraint.java: ########## @@ -0,0 +1,151 @@ +/* + * 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 = Review Comment: Fixed. Renamed the constraint case from `WITHOUT_VALUES` to `NO_VALUE` and the factory to `noValue()`. ########## api/src/main/java/org/apache/gravitino/tag/TagValueConstraint.java: ########## @@ -0,0 +1,151 @@ +/* + * 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 has no assignment value restriction and accepts valueless or valued assignments. */ + 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 with no assignment value restriction. + * + * <p>The tag may be assigned without values or with 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) { + Preconditions.checkArgument( + allowedValues != null && allowedValues.length > 0, + "Allowed values must not be null or empty"); + for (String allowedValue : allowedValues) { + Preconditions.checkArgument( + StringUtils.isNotBlank(allowedValue), "Allowed values must not contain blank values"); + } + + return new TagValueConstraint(Type.ALLOWED_VALUES, allowedValues); + } + + /** + * @return The value constraint type. + */ + public Type type() { + return type; + } + + /** + * @return The allowed values. Empty when the type is not {@link Type#ALLOWED_VALUES}. + */ + public String[] allowedValues() { + return allowedValues.clone(); + } + + /** + * Compares this constraint with another object. + * + * @param o The object to compare. + * @return True if the object is equal to this constraint. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TagValueConstraint)) { + return false; + } + + TagValueConstraint that = (TagValueConstraint) o; + return type == that.type && Arrays.equals(allowedValues, that.allowedValues); + } + + /** + * @return The hash code of this constraint. + */ + @Override + public int hashCode() { + int result = Objects.hash(type); + result = 31 * result + Arrays.hashCode(allowedValues); + return result; + } + + /** + * @return The string representation of this constraint. + */ + @Override + public String toString() { + return "TagValueConstraint{" + + "type=" + + type + + ", allowedValues=" + + Arrays.toString(allowedValues) + + "}"; Review Comment: Fixed. `toString()` now prints only the type for `ANY_VALUE` and `NO_VALUE`; `ALLOWED_VALUES` is the only case that includes the `allowedValues` list. -- 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]
