Skip to content

Commit ea8d917

Browse files
committed
Code clean up for UUIDConverter
1 parent 77d8dfd commit ea8d917

File tree

1 file changed

+14
-10
lines changed
  • spring-integration-core/src/main/java/org/springframework/integration/util

1 file changed

+14
-10
lines changed

spring-integration-core/src/main/java/org/springframework/integration/util/UUIDConverter.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@
3232
* @author Dave Syer
3333
* @author Gary Russell
3434
* @author Christian Tzolov
35+
* @author Artem Bilan
3536
*/
3637
public class UUIDConverter implements Converter<Object, UUID> {
3738

3839
/**
39-
* @deprecated since 6.0.8 as it is not used internally by the UUIDConverter. The internal implementation relies, now,
40-
* on StandardCharsets.UTF_8 instead.
40+
* @deprecated since 6.0.8 as it is not used internally by the UUIDConverter.
41+
* The internal implementation relies on {@link StandardCharsets#UTF_8} instead.
4142
*/
4243
@Deprecated
4344
public static final String DEFAULT_CHARSET = "UTF-8";
4445

45-
private static final Pattern UUID_REGEX = Pattern
46-
.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
46+
private static final Pattern UUID_REGEX =
47+
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
4748

4849
/**
4950
* Convert the input to a UUID using the convenience method {@link #getUUID(Object)}.
@@ -75,22 +76,25 @@ public static UUID getUUID(Object input) {
7576
if (input instanceof UUID) {
7677
return (UUID) input;
7778
}
78-
if (input instanceof String) {
79-
String inputText = (String) input;
79+
if (input instanceof String inputText) {
8080
if (isValidUuidStringRepresentation(inputText)) {
8181
return UUID.fromString(inputText);
8282
}
8383
else {
84-
return UUID.nameUUIDFromBytes((inputText).getBytes(StandardCharsets.UTF_8));
84+
return fromStringBytes(inputText);
8585
}
8686
}
8787
if (ClassUtils.isPrimitiveOrWrapper(input.getClass())) {
88-
return UUID.nameUUIDFromBytes(input.toString().getBytes(StandardCharsets.UTF_8));
88+
return fromStringBytes(input.toString());
8989
}
9090
byte[] bytes = serialize(input);
9191
return UUID.nameUUIDFromBytes(bytes);
9292
}
9393

94+
private static UUID fromStringBytes(String input) {
95+
return UUID.nameUUIDFromBytes(input.getBytes(StandardCharsets.UTF_8));
96+
}
97+
9498
private static byte[] serialize(Object object) {
9599
if (object == null) {
96100
return null;
@@ -99,8 +103,8 @@ private static byte[] serialize(Object object) {
99103
try {
100104
new ObjectOutputStream(stream).writeObject(object);
101105
}
102-
catch (IOException e) {
103-
throw new IllegalArgumentException("Could not serialize object of type: " + object.getClass(), e);
106+
catch (IOException ex) {
107+
throw new IllegalArgumentException("Could not serialize object of type: " + object.getClass(), ex);
104108
}
105109
return stream.toByteArray();
106110
}

0 commit comments

Comments
 (0)