mgroovy commented on a change in pull request #1660:
URL: https://github.com/apache/groovy/pull/1660#discussion_r762579784
##########
File path: src/main/java/groovy/lang/NamedValue.java
##########
@@ -0,0 +1,24 @@
+package groovy.lang;
+
+public class NamedValue<T> {
Review comment:
Yes, semantically it is quite different. The implementation we use also
shows that, since toString auto-quotes String/GString/Character (making the
output much easier to read), and is exception safe (so NV macros can be used
e.g. when embedding context information objects in the message string of an
exception), e.g.:
```
throw new SqlExecutorException(innerException, "updateValueAtPosition failed
for ${NVL(table,schema,pos,val,updateSql)}")
```
```
String toString() {
name + "=" + safeQuote(val)
}
static String safeQuote(final Object o) {
if(null == o) {
return null
}
else if(o instanceof GString) {
return '"' + o + '"'
}
else if(o instanceof String) {
return "'" + o + "'"
}
else if(o instanceof Character) {
return "C'" + o + "'"
}
else {
try {
return o.toString()
}
catch(Throwable throwable0) {
try {
return "NV(${o.getClass().getSimpleName()}.toString() threw
${throwable0.getClass().getSimpleName()})"
}
catch(Throwable throwable1) {
return "NV(o.getClass() threw ${throwable1.getClass().getSimpleName()})"
}
}
}
}
```
--
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]