Skip to content

Commit 4a83dec

Browse files
committed
Simplify version string creation in GDSServerVersion
1 parent 13e38c3 commit 4a83dec

1 file changed

Lines changed: 6 additions & 29 deletions

File tree

src/main/org/firebirdsql/gds/impl/GDSServerVersion.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,11 @@ public List<String> getRawVersions() {
126126
}
127127

128128
public @Nullable String getExtendedServerName() {
129-
if (rawVersions.length < 2) {
130-
return null;
131-
} else if (rawVersions.length == 2) {
132-
return rawVersions[1];
133-
} else {
134-
// Reserve additional space for connection information, etc. We could be more precise by summing the length
135-
// of each version string from index 1 in the array, but this is good enough
136-
var sb = new StringBuilder((rawVersions[1].length() + 50) * (rawVersions.length - 1));
137-
for (int idx = 1; idx < rawVersions.length; idx++) {
138-
if (idx > 1) {
139-
sb.append(',');
140-
}
141-
sb.append(rawVersions[idx]);
142-
}
143-
return sb.toString();
144-
}
129+
return switch (rawVersions.length) {
130+
case 0, 1 -> null;
131+
case 2 -> rawVersions[1];
132+
default -> String.join(",", Arrays.asList(rawVersions).subList(1, rawVersions.length));
133+
};
145134
}
146135

147136
public String getFullVersion() {
@@ -194,19 +183,7 @@ public boolean equals(Object obj) {
194183
}
195184

196185
public String toString() {
197-
if (rawVersions.length == 1) {
198-
return rawVersions[0];
199-
}
200-
// Reserve additional space for connection information, etc. We could be more precise by summing the length of
201-
// each version string in the array, but this is good enough
202-
var sb = new StringBuilder((rawVersions[0].length() + 50) * rawVersions.length);
203-
int idx = 0;
204-
sb.append(rawVersions[idx++]);
205-
do {
206-
sb.append(',');
207-
sb.append(rawVersions[idx++]);
208-
} while (idx < rawVersions.length);
209-
return sb.toString();
186+
return rawVersions.length == 1 ? rawVersions[0] : String.join(",", rawVersions);
210187
}
211188

212189
/**

0 commit comments

Comments
 (0)