From 65bc730cc152d86325cdc35b15bbdc06376080d5 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 30 Oct 2024 10:00:13 +0100 Subject: [PATCH] use switch expressions in isWider() impls Signed-off-by: Gavin King --- .../descriptor/java/BigDecimalJavaType.java | 22 ++++++--------- .../descriptor/java/BigIntegerJavaType.java | 20 +++++--------- .../descriptor/java/CalendarDateJavaType.java | 10 +++---- .../descriptor/java/CalendarJavaType.java | 12 +++------ .../descriptor/java/CalendarTimeJavaType.java | 10 +++---- .../type/descriptor/java/DateJavaType.java | 12 +++------ .../type/descriptor/java/DoubleJavaType.java | 27 +++++++------------ .../type/descriptor/java/FloatJavaType.java | 24 +++++++---------- .../type/descriptor/java/IntegerJavaType.java | 14 ++++------ .../java/JdbcTimestampJavaType.java | 13 +++------ .../descriptor/java/LocalDateJavaType.java | 10 +++---- .../java/LocalDateTimeJavaType.java | 13 +++------ .../descriptor/java/LocalTimeJavaType.java | 10 +++---- .../type/descriptor/java/LongJavaType.java | 17 +++++------- .../type/descriptor/java/ShortJavaType.java | 11 +++----- .../type/descriptor/java/StringJavaType.java | 16 +++++------ 16 files changed, 88 insertions(+), 153 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java index 60cfd9f6f6..be0e5a11bc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalJavaType.java @@ -99,20 +99,14 @@ public class BigDecimalJavaType extends AbstractClassJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - case "short": - case "java.lang.Short": - case "int": - case "java.lang.Integer": - case "long": - case "java.lang.Long": - case "java.math.BigInteger": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte", + "short", "java.lang.Short", + "int", "java.lang.Integer", + "long", "java.lang.Long", + "java.math.BigInteger" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java index f191b96cf4..0354ceed18 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerJavaType.java @@ -97,19 +97,13 @@ public class BigIntegerJavaType extends AbstractClassJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - case "short": - case "java.lang.Short": - case "int": - case "java.lang.Integer": - case "long": - case "java.lang.Long": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte", + "short", "java.lang.Short", + "int", "java.lang.Integer", + "long", "java.lang.Long" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java index cdd82a23b4..7e8961454e 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaType.java @@ -130,12 +130,10 @@ public class CalendarDateJavaType extends AbstractTemporalJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Date": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Date" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java index 94c3f809ee..26789ccdf1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaType.java @@ -147,14 +147,10 @@ public class CalendarJavaType extends AbstractTemporalJavaType impleme @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.util.Date": - case "java.sql.Date": - case "java.sql.Timestamp": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.util.Date", "java.sql.Date", "java.sql.Timestamp" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java index 98f20e03cd..bd2a9accb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaType.java @@ -132,12 +132,10 @@ public class CalendarTimeJavaType extends AbstractTemporalJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Time": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Time" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java index 4cc39a33f5..bae8b2f2b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DateJavaType.java @@ -168,14 +168,10 @@ public class DateJavaType extends AbstractTemporalJavaType implements Vers @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Date": - case "java.sql.Timestamp": - case "java.util.Calendar": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Date", "java.sql.Timestamp", "java.util.Calendar" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java index 359a92bea1..68c9f94680 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DoubleJavaType.java @@ -103,23 +103,16 @@ public class DoubleJavaType extends AbstractClassJavaType implements @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - case "short": - case "java.lang.Short": - case "int": - case "java.lang.Integer": - case "long": - case "java.lang.Long": - case "float": - case "java.lang.Float": - case "java.math.BigInteger": - case "java.math.BigDecimal": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte", + "short", "java.lang.Short", + "int", "java.lang.Integer", + "long", "java.lang.Long", + "float", "java.lang.Float", + "java.math.BigInteger", + "java.math.BigDecimal" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java index 721d51300c..956af27bc9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/FloatJavaType.java @@ -102,21 +102,15 @@ public class FloatJavaType extends AbstractClassJavaType implements Primi @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - case "short": - case "java.lang.Short": - case "int": - case "java.lang.Integer": - case "long": - case "java.lang.Long": - case "java.math.BigInteger": - case "java.math.BigDecimal": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte", + "short", "java.lang.Short", + "int", "java.lang.Integer", + "long", "java.lang.Long", + "java.math.BigInteger", + "java.math.BigDecimal" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java index 05d62a9f72..ad0634983f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/IntegerJavaType.java @@ -99,15 +99,11 @@ public class IntegerJavaType extends AbstractClassJavaType @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - case "short": - case "java.lang.Short": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte", + "short", "java.lang.Short" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java index a3d2c98d0b..2674935b70 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java @@ -192,15 +192,10 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType implem @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Date": - case "java.sql.Timestamp": - case "java.util.Date": - case "java.util.Calendar": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Date", "java.sql.Timestamp", "java.util.Date", "java.util.Calendar" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java index 1cbe12afed..7b36a45177 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java @@ -166,12 +166,10 @@ public class LocalDateJavaType extends AbstractTemporalJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Date": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Date" -> true; + default -> false; + }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java index a4ae976bcb..3ca0cf3aaf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java @@ -165,15 +165,10 @@ public class LocalDateTimeJavaType extends AbstractTemporalJavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Date": - case "java.sql.Timestamp": - case "java.util.Date": - case "java.util.Calendar": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Date", "java.sql.Timestamp", "java.util.Date", "java.util.Calendar" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalTimeJavaType.java index e584438a38..9cb3deb58d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalTimeJavaType.java @@ -177,12 +177,10 @@ public class LocalTimeJavaType extends AbstractTemporalJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "java.sql.Time": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "java.sql.Time" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java index 919385fc48..aeefc8c6d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LongJavaType.java @@ -99,17 +99,12 @@ public class LongJavaType extends AbstractClassJavaType @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - case "short": - case "java.lang.Short": - case "int": - case "java.lang.Integer": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte", + "short", "java.lang.Short", + "int", "java.lang.Integer" -> true; + default -> false; + }; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java index f1e56a7231..aef3386ecc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ShortJavaType.java @@ -45,13 +45,10 @@ public class ShortJavaType extends AbstractClassJavaType @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "byte": - case "java.lang.Byte": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "byte", "java.lang.Byte" -> true; + default -> false; + }; } @SuppressWarnings("unchecked") diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java index 48a8c2fdca..9cc631b623 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/StringJavaType.java @@ -126,15 +126,13 @@ public class StringJavaType extends AbstractClassJavaType { @Override public boolean isWider(JavaType javaType) { - switch ( javaType.getTypeName() ) { - case "char": - case "char[]": - case "java.lang.Character": - case "java.lang.Character[]": - return true; - default: - return false; - } + return switch ( javaType.getTypeName() ) { + case "char", + "char[]", + "java.lang.Character", + "java.lang.Character[]" -> true; + default -> false; + }; } @Override