-
Notifications
You must be signed in to change notification settings - Fork 3k
API: Add default value API #4732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,43 +415,64 @@ public int hashCode() { | |
|
|
||
| public static class NestedField implements Serializable { | ||
| public static NestedField optional(int id, String name, Type type) { | ||
| return new NestedField(true, id, name, type, null); | ||
| return new NestedField(true, id, name, type, null, null, null); | ||
| } | ||
|
|
||
| public static NestedField optional(int id, String name, Type type, String doc) { | ||
| return new NestedField(true, id, name, type, doc); | ||
| return new NestedField(true, id, name, type, doc, null, null); | ||
| } | ||
|
|
||
| public static NestedField optional(int id, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| return new NestedField(true, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public static NestedField required(int id, String name, Type type) { | ||
| return new NestedField(false, id, name, type, null); | ||
| return new NestedField(false, id, name, type, null, null, null); | ||
| } | ||
|
|
||
| public static NestedField required(int id, String name, Type type, String doc) { | ||
| return new NestedField(false, id, name, type, doc); | ||
| return new NestedField(false, id, name, type, doc, null, null); | ||
| } | ||
|
|
||
| public static NestedField required(int id, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| return new NestedField(false, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public static NestedField of(int id, boolean isOptional, String name, Type type) { | ||
| return new NestedField(isOptional, id, name, type, null); | ||
| return new NestedField(isOptional, id, name, type, null, null, null); | ||
| } | ||
|
|
||
| public static NestedField of(int id, boolean isOptional, String name, Type type, String doc) { | ||
| return new NestedField(isOptional, id, name, type, doc); | ||
| return new NestedField(isOptional, id, name, type, doc, null, null); | ||
| } | ||
|
|
||
| public static NestedField of(int id, boolean isOptional, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| return new NestedField(isOptional, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| private final boolean isOptional; | ||
| private final int id; | ||
| private final String name; | ||
| private final Type type; | ||
| private final String doc; | ||
| private final Object initialDefault; | ||
| private final Object writeDefault; | ||
|
|
||
| private NestedField(boolean isOptional, int id, String name, Type type, String doc) { | ||
| private NestedField( | ||
| boolean isOptional, int id, String name, Type type, String doc, | ||
| Object initialDefault, Object writeDefault) { | ||
| Preconditions.checkNotNull(name, "Name cannot be null"); | ||
| Preconditions.checkNotNull(type, "Type cannot be null"); | ||
| this.isOptional = isOptional; | ||
| this.id = id; | ||
| this.name = name; | ||
| this.type = type; | ||
| this.doc = doc; | ||
| this.initialDefault = initialDefault; | ||
| this.writeDefault = writeDefault; | ||
| } | ||
|
|
||
| public boolean isOptional() { | ||
|
|
@@ -462,7 +483,7 @@ public NestedField asOptional() { | |
| if (isOptional) { | ||
| return this; | ||
| } | ||
| return new NestedField(true, id, name, type, doc); | ||
| return new NestedField(true, id, name, type, doc, initialDefault, writeDefault); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the API always expect
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible, I'd really like to hide the complexity of both defaults as you're suggesting. Unfortunately, I don't see a good way to do that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, but I think we could handle that in the table API. |
||
| } | ||
|
|
||
| public boolean isRequired() { | ||
|
|
@@ -473,7 +494,11 @@ public NestedField asRequired() { | |
| if (!isOptional) { | ||
| return this; | ||
| } | ||
| return new NestedField(false, id, name, type, doc); | ||
| return new NestedField(false, id, name, type, doc, initialDefault, writeDefault); | ||
| } | ||
|
|
||
| public NestedField withWriteDefault(Object newWriteDefault) { | ||
| return new NestedField(isOptional, id, name, type, doc, initialDefault, newWriteDefault); | ||
| } | ||
|
|
||
| public int fieldId() { | ||
|
|
@@ -492,6 +517,14 @@ public String doc() { | |
| return doc; | ||
| } | ||
|
|
||
| public Object initialDefault() { | ||
| return initialDefault; | ||
| } | ||
|
|
||
| public Object writeDefault() { | ||
| return writeDefault; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("%d: %s: %s %s", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it acceptable to always expect
docif we need to declare a default value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a way around this so it should be okay.