Skip to content

Commit 9264ddd

Browse files
committed
Refactor
This update includes general refactoring, like: - converting to local variables - removal of empty methods - removal of redundant throws - making eligible classes static - removal of identical override methods - upgrade to enhanced switch - update to text block - using pattern variables - using records - using collection factory calls
1 parent 636828d commit 9264ddd

File tree

122 files changed

+762
-1485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+762
-1485
lines changed

driver/src/main/java/org/neo4j/driver/Config.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.io.Serial;
2727
import java.io.Serializable;
2828
import java.net.InetAddress;
29-
import java.util.ArrayList;
3029
import java.util.Arrays;
3130
import java.util.Collections;
3231
import java.util.List;
@@ -808,7 +807,7 @@ private TrustStrategy(Strategy strategy) {
808807
private TrustStrategy(Strategy strategy, List<File> certFiles) {
809808
Objects.requireNonNull(certFiles, "certFiles can't be null");
810809
this.strategy = strategy;
811-
this.certFiles = Collections.unmodifiableList(new ArrayList<>(certFiles));
810+
this.certFiles = List.copyOf(certFiles);
812811
}
813812

814813
/**

driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,11 @@ protected static MetricsProvider getOrCreateMetricsProvider(Config config, Clock
161161
if (metricsAdapter == null) {
162162
metricsAdapter = config.isMetricsEnabled() ? MetricsAdapter.DEFAULT : MetricsAdapter.DEV_NULL;
163163
}
164-
switch (metricsAdapter) {
165-
case DEV_NULL:
166-
return DevNullMetricsProvider.INSTANCE;
167-
case DEFAULT:
168-
return new InternalMetricsProvider(clock, config.logging());
169-
case MICROMETER:
170-
return MicrometerMetricsProvider.forGlobalRegistry();
171-
}
172-
throw new IllegalStateException("Unknown or unsupported MetricsAdapter: " + metricsAdapter);
164+
return switch (metricsAdapter) {
165+
case DEV_NULL -> DevNullMetricsProvider.INSTANCE;
166+
case DEFAULT -> new InternalMetricsProvider(clock, config.logging());
167+
case MICROMETER -> MicrometerMetricsProvider.forGlobalRegistry();
168+
};
173169
}
174170

175171
protected ChannelConnector createConnector(

driver/src/main/java/org/neo4j/driver/internal/InternalIsoDuration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import static java.time.temporal.ChronoUnit.MONTHS;
2323
import static java.time.temporal.ChronoUnit.NANOS;
2424
import static java.time.temporal.ChronoUnit.SECONDS;
25-
import static java.util.Arrays.asList;
26-
import static java.util.Collections.unmodifiableList;
2725

2826
import java.time.Duration;
2927
import java.time.Period;
@@ -36,7 +34,7 @@
3634

3735
public class InternalIsoDuration implements IsoDuration {
3836
private static final long NANOS_PER_SECOND = 1_000_000_000;
39-
private static final List<TemporalUnit> SUPPORTED_UNITS = unmodifiableList(asList(MONTHS, DAYS, SECONDS, NANOS));
37+
private static final List<TemporalUnit> SUPPORTED_UNITS = List.of(MONTHS, DAYS, SECONDS, NANOS);
4038

4139
private final long months;
4240
private final long days;

driver/src/main/java/org/neo4j/driver/internal/InternalPath.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,7 @@
3434
* {@link Path} implementation that directly contains all nodes and relationships.
3535
*/
3636
public class InternalPath implements Path, AsValue {
37-
public static class SelfContainedSegment implements Segment {
38-
private final Node start;
39-
private final Relationship relationship;
40-
private final Node end;
41-
42-
public SelfContainedSegment(Node start, Relationship relationship, Node end) {
43-
this.start = start;
44-
this.relationship = relationship;
45-
this.end = end;
46-
}
47-
48-
@Override
49-
public Node start() {
50-
return start;
51-
}
52-
53-
@Override
54-
public Relationship relationship() {
55-
return relationship;
56-
}
57-
58-
@Override
59-
public Node end() {
60-
return end;
61-
}
37+
public record SelfContainedSegment(Node start, Relationship relationship, Node end) implements Segment {
6238

6339
@Override
6440
public boolean equals(Object other) {
@@ -73,14 +49,6 @@ public boolean equals(Object other) {
7349
return start.equals(that.start) && end.equals(that.end) && relationship.equals(that.relationship);
7450
}
7551

76-
@Override
77-
public int hashCode() {
78-
var result = start.hashCode();
79-
result = 31 * result + relationship.hashCode();
80-
result = 31 * result + end.hashCode();
81-
return result;
82-
}
83-
8452
@Override
8553
@SuppressWarnings("deprecation")
8654
public String toString() {

driver/src/main/java/org/neo4j/driver/internal/InternalPoint2D.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,9 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21-
import java.util.Objects;
2221
import org.neo4j.driver.types.Point;
2322

24-
public class InternalPoint2D implements Point {
25-
private final int srid;
26-
private final double x;
27-
private final double y;
28-
29-
public InternalPoint2D(int srid, double x, double y) {
30-
this.srid = srid;
31-
this.x = x;
32-
this.y = y;
33-
}
34-
35-
@Override
36-
public int srid() {
37-
return srid;
38-
}
39-
40-
@Override
41-
public double x() {
42-
return x;
43-
}
44-
45-
@Override
46-
public double y() {
47-
return y;
48-
}
23+
public record InternalPoint2D(int srid, double x, double y) implements Point {
4924

5025
@Override
5126
public double z() {
@@ -64,11 +39,6 @@ public boolean equals(Object o) {
6439
return srid == that.srid && Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0;
6540
}
6641

67-
@Override
68-
public int hashCode() {
69-
return Objects.hash(srid, x, y);
70-
}
71-
7242
@Override
7343
public String toString() {
7444
return "Point{" + "srid=" + srid + ", x=" + x + ", y=" + y + '}';

driver/src/main/java/org/neo4j/driver/internal/InternalPoint3D.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,9 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21-
import java.util.Objects;
2221
import org.neo4j.driver.types.Point;
2322

24-
public class InternalPoint3D implements Point {
25-
private final int srid;
26-
private final double x;
27-
private final double y;
28-
private final double z;
29-
30-
public InternalPoint3D(int srid, double x, double y, double z) {
31-
this.srid = srid;
32-
this.x = x;
33-
this.y = y;
34-
this.z = z;
35-
}
36-
37-
@Override
38-
public int srid() {
39-
return srid;
40-
}
41-
42-
@Override
43-
public double x() {
44-
return x;
45-
}
46-
47-
@Override
48-
public double y() {
49-
return y;
50-
}
51-
52-
@Override
53-
public double z() {
54-
return z;
55-
}
23+
public record InternalPoint3D(int srid, double x, double y, double z) implements Point {
5624

5725
@Override
5826
public boolean equals(Object o) {
@@ -69,11 +37,6 @@ public boolean equals(Object o) {
6937
&& Double.compare(that.z, z) == 0;
7038
}
7139

72-
@Override
73-
public int hashCode() {
74-
return Objects.hash(srid, x, y, z);
75-
}
76-
7740
@Override
7841
public String toString() {
7942
return "Point{" + "srid=" + srid + ", x=" + x + ", y=" + y + ", z=" + z + '}';

driver/src/main/java/org/neo4j/driver/internal/InternalRecord.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ public String toString() {
127127
public boolean equals(Object other) {
128128
if (this == other) {
129129
return true;
130-
} else if (other instanceof Record) {
131-
var otherRecord = (Record) other;
130+
} else if (other instanceof Record otherRecord) {
132131
var size = size();
133132
if (!(size == otherRecord.size())) {
134133
return false;

driver/src/main/java/org/neo4j/driver/internal/Scheme.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public static void validateScheme(String scheme) {
3131
throw new IllegalArgumentException("Scheme must not be null");
3232
}
3333
switch (scheme) {
34-
case BOLT_URI_SCHEME:
35-
case BOLT_LOW_TRUST_URI_SCHEME:
36-
case BOLT_HIGH_TRUST_URI_SCHEME:
37-
case NEO4J_URI_SCHEME:
38-
case NEO4J_LOW_TRUST_URI_SCHEME:
39-
case NEO4J_HIGH_TRUST_URI_SCHEME:
34+
case BOLT_URI_SCHEME,
35+
BOLT_LOW_TRUST_URI_SCHEME,
36+
BOLT_HIGH_TRUST_URI_SCHEME,
37+
NEO4J_URI_SCHEME,
38+
NEO4J_LOW_TRUST_URI_SCHEME,
39+
NEO4J_HIGH_TRUST_URI_SCHEME -> {
4040
return;
41-
default:
42-
throw new IllegalArgumentException("Invalid address format " + scheme);
41+
}
42+
default -> throw new IllegalArgumentException("Invalid address format " + scheme);
4343
}
4444
}
4545

driver/src/main/java/org/neo4j/driver/internal/SecuritySettings.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,18 @@
2121
import java.io.Serializable;
2222
import org.neo4j.driver.Config;
2323

24-
public class SecuritySettings implements Serializable {
24+
public record SecuritySettings(boolean encrypted, Config.TrustStrategy trustStrategy) implements Serializable {
2525
private static final long serialVersionUID = 4494615367164106576L;
2626

2727
private static final boolean DEFAULT_ENCRYPTED = false;
2828
private static final Config.TrustStrategy DEFAULT_TRUST_STRATEGY = Config.TrustStrategy.trustSystemCertificates();
2929
public static final SecuritySettings DEFAULT = new SecuritySettings(DEFAULT_ENCRYPTED, DEFAULT_TRUST_STRATEGY);
30-
private final boolean encrypted;
31-
private final Config.TrustStrategy trustStrategy;
3230

3331
public SecuritySettings(boolean encrypted, Config.TrustStrategy trustStrategy) {
3432
this.encrypted = encrypted;
3533
this.trustStrategy = trustStrategy == null ? DEFAULT_TRUST_STRATEGY : trustStrategy;
3634
}
3735

38-
public boolean encrypted() {
39-
return encrypted;
40-
}
41-
42-
public Config.TrustStrategy trustStrategy() {
43-
return trustStrategy;
44-
}
45-
4636
public static class SecuritySettingsBuilder {
4737
private boolean isCustomized = false;
4838
private boolean encrypted;

driver/src/main/java/org/neo4j/driver/internal/SessionFactoryImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ public class SessionFactoryImpl implements SessionFactory {
4343
private final Logging logging;
4444
private final boolean leakedSessionsLoggingEnabled;
4545
private final long defaultFetchSize;
46-
private final NotificationConfig driverNotificationConfig;
4746

4847
SessionFactoryImpl(ConnectionProvider connectionProvider, RetryLogic retryLogic, Config config) {
4948
this.connectionProvider = connectionProvider;
5049
this.leakedSessionsLoggingEnabled = config.logLeakedSessions();
5150
this.retryLogic = retryLogic;
5251
this.logging = config.logging();
5352
this.defaultFetchSize = config.fetchSize();
54-
this.driverNotificationConfig = config.notificationConfig();
5553
}
5654

5755
@Override

0 commit comments

Comments
 (0)