-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Value#asXXX(defalutValue)
for primary types
#481
Conversation
Add Value#computeOrDefault(Function<Value, T> mapper, T defaultValue) for other types Add Value#computeOrNull(Function<Value, T> mapper) for shortcuts to call Value#computeOrDefault(Function<Value, T> mapper, T defaultValue=null)
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.
@zhenlineo Changes look good to me. Made couple minor comments. Methods with default value should also be added for native temporal types from java.time
:
LocalDate asLocalDate(LocalDate defaultValue)
OffsetTime asOffsetTime(OffsetTime defaultValue)
LocalTime asLocalTime(LocalTime defaultValue)
LocalDateTime asLocalDateTime(LocalDateTime defaultValue)
ZonedDateTime asZonedDateTime(ZonedDateTime defaultValue)
/** | ||
* @return the value as a Java boolean, if possible. | ||
* @throws Uncoercible if value types are incompatible. | ||
*/ | ||
boolean asBoolean(); | ||
|
||
/** | ||
* @param defaultValue return this value if the value is a {@link NullValue}. |
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.
Maybe add description and @throws Uncoercible if value types are incompatible.
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.
It was in the javadoc.
@@ -212,6 +237,12 @@ | |||
*/ | |||
String asString(); | |||
|
|||
/** | |||
* @param defaultValue return this value if the value is null. |
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.
Maybe add description and @throws Uncoercible if value types are incompatible.
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.
Done
* @return the value as a Java double. | ||
* @throws LossyCoercion if it is not possible to convert the value without loosing precision. | ||
* @throws Uncoercible if value types are incompatible. | ||
|
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.
Empty line should probably be removed
* @return the value as a Java float. | ||
* @throws LossyCoercion if it is not possible to convert the value without loosing precision. | ||
* @throws Uncoercible if value types are incompatible. | ||
|
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.
Empty line should probably be removed
d5cec76
to
8b54a3b
Compare
@sarmbruster Given we have general methods On which level do you suggest to have
|
Hi @zhenlineo, |
@sarmbruster I mean primitive types. So basically I guess you are asking for the following API:
But how about I give you a smaller API:
Which API is more useful to you (most of users)? or how would you improve one of them? |
Imho a slightly trimmed version 1 would be great:
|
+1 on @lutovich 's previous commit. I guess we should have a For the remainder having a type agnostic |
887f78d
to
3637193
Compare
Add
Value#computeOrDefault(Function<Value, T> mapper, T defaultValue)
for other typesAdd
Value#computeOrNull(Function<Value, T> mapper)
for shortcuts to callValue#computeOrDefault(Function<Value, T> mapper, T defaultValue=null)