Skip to content

Commit aaf0f6b

Browse files
committed
misc code cleanups
1 parent a9f015e commit aaf0f6b

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public T fromString(CharSequence string) {
9393
}
9494

9595
protected MutabilityPlan<T> getMutabilityPlan() {
96-
return this.mutabilityPlan;
96+
return mutabilityPlan;
9797
}
9898

9999
@Override

hibernate-core/src/main/java/org/hibernate/type/BasicArrayType.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.hibernate.type.descriptor.jdbc.JdbcType;
1313
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
1414

15+
import static java.lang.Character.toUpperCase;
16+
1517
/**
1618
* A type that maps between {@link java.sql.Types#ARRAY ARRAY} and {@code T[]}
1719
*
@@ -37,7 +39,8 @@ static String determineElementTypeName(BasicType<?> baseDescriptor) {
3739
final String elementName = baseDescriptor.getName();
3840
return switch ( elementName ) {
3941
case "boolean", "byte", "char", "short", "int", "long", "float", "double" ->
40-
Character.toUpperCase( elementName.charAt( 0 ) ) + elementName.substring( 1 );
42+
toUpperCase( elementName.charAt( 0 ) )
43+
+ elementName.substring( 1 );
4144
default -> elementName;
4245
};
4346
}
@@ -63,16 +66,18 @@ protected boolean registerUnderJavaType() {
6366

6467
@Override
6568
public <X> BasicType<X> resolveIndicatedType(JdbcTypeIndicators indicators, JavaType<X> domainJtd) {
66-
// TODO: maybe fallback to some encoding by default if the DB doesn't support arrays natively?
67-
// also, maybe move that logic into the ArrayJdbcType
69+
// TODO: maybe fall back to some encoding by default if
70+
// the database doesn't support arrays natively?
71+
// also, maybe move that logic into the ArrayJdbcType
6872
//noinspection unchecked
6973
return (BasicType<X>) this;
7074
}
7175

7276
@Override
7377
public boolean equals(Object object) {
74-
return object == this || object.getClass() == BasicArrayType.class
75-
&& Objects.equals( baseDescriptor, ( (BasicArrayType<?, ?>) object ).baseDescriptor );
78+
return object == this
79+
|| object instanceof BasicArrayType<?,?> arrayType // no subtypes
80+
&& Objects.equals( baseDescriptor, arrayType.baseDescriptor );
7681
}
7782

7883
@Override

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampJavaType.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,32 +85,26 @@ public boolean areEqual(Date one, Date another) {
8585
if ( one == another ) {
8686
return true;
8787
}
88-
if ( one == null || another == null) {
88+
else if ( one == null || another == null) {
8989
return false;
9090
}
91-
92-
long t1 = one.getTime();
93-
long t2 = another.getTime();
94-
95-
boolean oneIsTimestamp = one instanceof Timestamp;
96-
boolean anotherIsTimestamp = another instanceof Timestamp;
97-
98-
int n1 = oneIsTimestamp ? ( (Timestamp) one ).getNanos() : 0;
99-
int n2 = anotherIsTimestamp ? ( (Timestamp) another ).getNanos() : 0;
100-
101-
if ( t1 != t2 ) {
102-
return false;
103-
}
104-
105-
if ( oneIsTimestamp && anotherIsTimestamp ) {
106-
// both are Timestamps
107-
int nn1 = n1 % 1000000;
108-
int nn2 = n2 % 1000000;
109-
return nn1 == nn2;
110-
}
11191
else {
112-
// at least one is a plain old Date
113-
return true;
92+
final long t1 = one.getTime();
93+
final long t2 = another.getTime();
94+
if ( t1 != t2 ) {
95+
return false;
96+
}
97+
else if ( one instanceof Timestamp ts1
98+
&& another instanceof Timestamp ts2 ) {
99+
// both are Timestamps
100+
final int nn1 = ts1.getNanos() % 1000000;
101+
final int nn2 = ts2.getNanos() % 1000000;
102+
return nn1 == nn2;
103+
}
104+
else {
105+
// at least one is a plain old Date
106+
return true;
107+
}
114108
}
115109
}
116110

@@ -132,8 +126,8 @@ public Object unwrap(Date value, Class type, WrapperOptions options) {
132126
}
133127

134128
if ( Timestamp.class.isAssignableFrom( type ) ) {
135-
return value instanceof Timestamp
136-
? (Timestamp) value
129+
return value instanceof Timestamp timestamp
130+
? timestamp
137131
: new Timestamp( value.getTime() );
138132
}
139133

0 commit comments

Comments
 (0)