alexvanboxel commented on a change in pull request #10413: [BEAM-9035] Typed 
options for Row Schema and Field
URL: https://github.com/apache/beam/pull/10413#discussion_r388008991
 
 

 ##########
 File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/Schema.java
 ##########
 @@ -953,6 +1012,338 @@ public int hashCode() {
     }
   }
 
+  public static class Options implements Serializable {
+    private Map<String, Option> options;
+
+    @Override
+    public String toString() {
+      TreeMap sorted = new TreeMap(options);
+      return "{" + sorted + '}';
+    }
+
+    Map<String, Option> getAllOptions() {
+      return options;
+    }
+
+    public Set<String> getOptionNames() {
+      return options.keySet();
+    }
+
+    public boolean hasOptions() {
+      return options.size() > 0;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o == null || getClass() != o.getClass()) {
+        return false;
+      }
+      Options options1 = (Options) o;
+      if (!options.keySet().equals(options1.options.keySet())) {
+        return false;
+      }
+      for (Map.Entry<String, Option> optionEntry : options.entrySet()) {
+        Option thisOption = optionEntry.getValue();
+        Option otherOption = options1.options.get(optionEntry.getKey());
+        if (!thisOption.getType().equals(otherOption.getType())) {
+          return false;
+        }
+        switch (thisOption.getType().getTypeName()) {
+          case BYTE:
+          case INT16:
+          case INT32:
+          case INT64:
+          case DECIMAL:
+          case FLOAT:
+          case DOUBLE:
+          case STRING:
+          case DATETIME:
+          case BOOLEAN:
+          case ARRAY:
+          case ITERABLE:
+          case MAP:
+          case ROW:
+          case LOGICAL_TYPE:
+            if (!thisOption.getValue().equals(otherOption.getValue())) {
+              return false;
+            }
+            break;
+          case BYTES:
+            if (!Arrays.equals((byte[]) thisOption.getValue(), 
otherOption.getValue())) {
+              return false;
+            }
+        }
+      }
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return Objects.hash(options);
+    }
+
+    static class Option implements Serializable {
+      Option(FieldType type, Object value) {
+        this.type = type;
+        this.value = value;
+      }
+
+      private FieldType type;
+      private Object value;
+
+      @SuppressWarnings("TypeParameterUnusedInFormals")
+      <T> T getValue() {
+        return (T) value;
+      }
+
+      FieldType getType() {
+        return type;
+      }
+
+      @Override
+      public String toString() {
+        return "Option{type=" + type + ", value=" + value + '}';
+      }
+
+      @Override
+      public boolean equals(Object o) {
+        if (this == o) {
+          return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+          return false;
+        }
+        Option option = (Option) o;
+        return Objects.equals(type, option.type) && Objects.equals(value, 
option.value);
+      }
+
+      @Override
+      public int hashCode() {
+        return Objects.hash(type, value);
+      }
+    }
+
+    public static class Builder {
+      private Map<String, Option> options;
+
+      Builder(Map<String, Option> init) {
+        this.options = new HashMap<>(init);
+      }
+
+      Builder() {
+        this(new HashMap<>());
+      }
+
+      public Builder setByteOption(String optionName, Byte value) {
 
 Review comment:
   Thru, I can remove this. Most people will just use the getters anyway. The 
setters will be used by proto/avro/ etc implementations.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to