<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
we have quite a few places in our code where we do:</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
logger.error("Param {} must be in [{}-{}]", name, low, high);</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
throw new ValidationException("Param " + name + " must be in [" + low + "-" + high + "]");</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
This is obviously ugly. Other options would be to use</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
String msg = String.format("Param %s must be in [%s-%s]", name, low, high);<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
logger.error(msg);</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
throw new ValidationException(msg);</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
or</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
String msg = MessageFormatter.format("Param {} must be in [{}-{}]", new Object[] {name, low, high}).getMessage();<br>
</div>
<div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt"> logger.error(msg);</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt"> throw new ValidationException(msg);</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt"><br>
</div>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Both are not ideal. Can't we have a logger.format method which returns a FormattingTuple w/o the explicit array creation</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
and allow logger.error etc. to be called with a FormattingTuple? Then I could write</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
FormattingTuple entry = logger.format("Param {} must be in [{}-{}]", name, low, high);<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
logger.error(entry);</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
throw new ValidationException(entry.getMessage());<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
For my own exception classes I could then even offer a constructor that takes a FormattingTuple and internally use the</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
message and the throwable (if it is not null).<br>
</div>
<div style="font-family: Tahoma, Geneva, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div></div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Tahoma,Geneva,sans-serif">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px"><span lang="en-US">
<div style="margin:0" align="justify"><font size="2" face="Arial,sans-serif"><span style="font-size:10pt"><font size="3" face="Calibri,sans-serif" color="#17365D"><span style="font-size:12pt"></nk><br>
<br>
---<br>
</span></font></span></font></div>
<div style="margin:0" align="justify"><font size="2" face="Arial,sans-serif"><span style="font-size:10pt"><font size="3" face="Calibri,sans-serif" color="#17365D"><span style="font-size:12pt"><br>
</span></font></span></font></div>
<div style="margin:0" align="justify"><font size="2" face="Arial,sans-serif"><span style="font-size:10pt"><font size="3" face="Calibri,sans-serif" color="#17365D"><span style="font-size:12pt">
<div>
<table style="font-family:Calibri,Verdana,Arial,sans-serif; color:#808288; font-size:11px; text-align:left" width="500" height="125" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2" valign="top" height="8" align="left">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td width="100%" valign="top" bgcolor="#FFFFFF" align="left"><br>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="color:#808288; font-size:1em; padding-top:10px; line-height:16px; padding-left:5px; font-family:Calibri,Verdana,Arial,sans-serif" width="75%" valign="top">
<span style="font-family:Calibri,Verdana,Arial,sans-serif; color:#0b6eb9; font-size:16px">Norbert Kiesel</span><br>
Systems Architect, Engineering<br>
E: <a href="mailto:sonia.sharma@metricstream.com" title="Ctrl+Click or tap to follow the link">
nkiesel@metricstream.com</a><br>
W: <a>www.metricstream.com</a></td>
<td style="font-family:Calibri,Verdana,Arial,sans-serif; color:#006eb8; padding-bottom:5px" width="25%" valign="bottom" align="center">
<br>
</td>
</tr>
<tr>
<td colspan="2" valign="top" align="right">
<table width="100%" height="5" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td width="100%" valign="top" bgcolor="#FFFFFF" align="right"><br>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</span></font></span></font><font size="2" face="Arial,sans-serif"><span style="font-size:10pt"><font size="3" face="Calibri,sans-serif" color="#17365D"><span style="font-size:12pt"></span></font></span></font></div>
</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>