adutra commented on code in PR #282:
URL: https://github.com/apache/polaris/pull/282#discussion_r1763661096
##########
polaris-core/src/main/java/org/apache/polaris/core/PolarisConfiguration.java:
##########
@@ -19,89 +19,54 @@
package org.apache.polaris.core;
import java.util.Optional;
+import org.apache.polaris.immutables.PolarisImmutable;
+import org.immutables.value.Value;
-public class PolarisConfiguration<T> {
-
- public final String key;
- public final String description;
- public final T defaultValue;
- private final Optional<String> catalogConfigImpl;
- private final Class<T> typ;
-
- @SuppressWarnings("unchecked")
- public PolarisConfiguration(
- String key, String description, T defaultValue, Optional<String>
catalogConfig) {
- this.key = key;
- this.description = description;
- this.defaultValue = defaultValue;
- this.catalogConfigImpl = catalogConfig;
- this.typ = (Class<T>) defaultValue.getClass();
- }
+@PolarisImmutable
+public interface PolarisConfiguration<T> {
- public boolean hasCatalogConfig() {
- return catalogConfigImpl.isPresent();
- }
+ String key();
+
+ String description();
+
+ T defaultValue();
+
+ Optional<String> catalogConfig();
- public String catalogConfig() {
- return catalogConfigImpl.orElseThrow(
- () ->
- new IllegalStateException(
- "Attempted to read a catalog config key from a configuration
that doesn't have one."));
+ @Value.Derived
+ default boolean hasCatalogConfig() {
+ return catalogConfig().isPresent();
}
- T cast(Object value) {
- return this.typ.cast(value);
+ @Value.NonAttribute
+ default String catalogConfigOrThrow() {
+ return catalogConfig()
+ .orElseThrow(
+ () ->
+ new IllegalStateException(
+ "Attempted to read a catalog config key from a
configuration that doesn't have one."));
}
- public static class Builder<T> {
- private String key;
- private String description;
- private T defaultValue;
- private Optional<String> catalogConfig = Optional.empty();
-
- public Builder<T> key(String key) {
- this.key = key;
- return this;
- }
-
- public Builder<T> description(String description) {
- this.description = description;
- return this;
- }
-
- public Builder<T> defaultValue(T defaultValue) {
- this.defaultValue = defaultValue;
- return this;
- }
-
- public Builder<T> catalogConfig(String catalogConfig) {
- this.catalogConfig = Optional.of(catalogConfig);
- return this;
- }
-
- public PolarisConfiguration<T> build() {
- if (key == null || description == null || defaultValue == null) {
- throw new IllegalArgumentException("key, description, and defaultValue
are required");
- }
- return new PolarisConfiguration<>(key, description, defaultValue,
catalogConfig);
- }
+ default T cast(Object value) {
Review Comment:
I don't think so, this method is not a setter nor a getter. If you look at
the generated class, there is no `cast` method nor field.
--
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]