Skip to content

Commit 4fdae91

Browse files
committed
CSSTUDIO-3605 Improve typing and limit scope of 'buf'.
1 parent 010be78 commit 4fdae91

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/ui/src/main/java/org/phoebus/ui/vtype/FormatOptionHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ private static String formatNumber(final Number value, final Display display,
223223
}
224224
if (option == FormatOption.HEX)
225225
{
226-
final StringBuilder buf = new StringBuilder();
227-
Optional<Long> maybeLongValue;
226+
final Optional<Long> maybeLongValue;
228227
if (value instanceof Byte valueByte) {
229228
maybeLongValue = Optional.of(Byte.toUnsignedLong(valueByte));
230229
} else if (value instanceof Short valueShort) {
@@ -248,17 +247,18 @@ private static String formatNumber(final Number value, final Display display,
248247
} else {
249248
maybeLongValue = Optional.empty();
250249
}
251-
250+
252251
if (maybeLongValue.isPresent()) {
253252
long longValue = maybeLongValue.get();
254-
String hexString = Long.toHexString(longValue);
253+
final String hexString = Long.toHexString(longValue);
254+
final StringBuilder buf = new StringBuilder();
255255
buf.append(hexString.toUpperCase());
256256
for (int i=buf.length(); i<precision; ++i)
257257
buf.insert(0, '0');
258258
buf.insert(0, "0x");
259259
return buf.toString();
260260
} else {
261-
String numberFormat = value.getClass().getSimpleName();
261+
final String numberFormat = value.getClass().getSimpleName();
262262
Logger.getLogger(FormatOptionHandler.class.getPackageName())
263263
.log(Level.WARNING, "Error: Number format is unsupported for conversion to HEX format: " + numberFormat);
264264
return "ERROR: Unsupported number format: " + numberFormat;

0 commit comments

Comments
 (0)