Skip to content

Commit

Permalink
code style: replace String.format() by .formatted(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
groldan committed May 21, 2024
1 parent 3debae2 commit ea8a373
Show file tree
Hide file tree
Showing 28 changed files with 123 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onApplicationReady(ApplicationReadyEvent e) {
final String instanceId = env.getProperty("info.instance-id");
String nodeOpts = System.getProperty("GEOSERVER_NODE_OPTS");
if (null == nodeOpts) {
nodeOpts = String.format("id:%s;color:FF0000", instanceId);
nodeOpts = "id:%s;color:FF0000".formatted(instanceId);
System.setProperty("GEOSERVER_NODE_OPTS", nodeOpts);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private String getStatus(org.springframework.cloud.client.ServiceInstance i) {
private String buildUrl(org.springframework.cloud.client.ServiceInstance i) {
URI uri = i.getUri();
if (uri == null) {
uri = URI.create(String.format("%s://%s:%s", i.getScheme(), i.getHost(), i.getPort()));
uri = URI.create("%s://%s:%s".formatted(i.getScheme(), i.getHost(), i.getPort()));
}
return uri.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public boolean test(ServerWebExchange exchange) {

@Override
public String toString() {
return String.format(
"Query: param regexp='%s' value regexp='%s'",
config.getParamRegexp(), config.getValueRegexp());
return "Query: param regexp='%s' value regexp='%s'"
.formatted(config.getParamRegexp(), config.getValueRegexp());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ private HttpClientBuilder builder() {
HttpClientBuilder builder =
HttpClientBuilder.create()
.setUserAgent(
String.format(
"GeoTools/%s (%s)",
GeoTools.getVersion(), this.getClass().getSimpleName()))
"GeoTools/%s (%s)"
.formatted(
GeoTools.getVersion(),
this.getClass().getSimpleName()))
.useSystemProperties()
.setConnectionManager(connectionManager);
if (credsProvider != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,20 @@ void validateConfig() {
final boolean passwordSet = StringUtils.hasText(adminPassword);
if (userSet && !passwordSet) {
String msg =
String.format(
"""
"""
Found overriding admin username config property geoserver.admin.username=%s, \
but password not provided through config property geoserver.admin.password
""",
adminUserName);
"""
.formatted(adminUserName);
throw new BeanInstantiationException(getClass(), msg);
}
if (passwordSet && !userSet) {
String msg =
String.format(
"""
"""
Found overriding admin password config property geoserver.admin.password, \
but admin username not provided through config property geoserver.admin.username
""",
adminUserName);
"""
.formatted(adminUserName);
throw new BeanInstantiationException(getClass(), msg);
}
enabled = userSet && passwordSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public File getCacheDirectory() {

private static String defaultCacheDirectory() {
String tmpdir = System.getProperty("java.io.tmpdir");
return String.format("%s%sgeoserver-jdbcconfig-cache", tmpdir, File.separator);
return "%s%sgeoserver-jdbcconfig-cache".formatted(tmpdir, File.separator);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.cloud.config.catalog.backend.jdbcconfig;

import static java.lang.String.format;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -59,22 +57,21 @@ public void afterPropertiesSet() throws Exception {
String createSequenceStatement;
if (props.isPostgreSQL()) {
createSequenceStatement =
format("CREATE SEQUENCE IF NOT EXISTS %s AS BIGINT CYCLE", SEQUENCE_NAME);
"CREATE SEQUENCE IF NOT EXISTS %s AS BIGINT CYCLE".formatted(SEQUENCE_NAME);
// not using CURRVAL() to avoid the "currval of sequence "<name>" is not yet defined in
// this session" error
getQuery = format("SELECT last_value FROM %s", SEQUENCE_NAME);
incrementAndGetQuery = format("SELECT NEXTVAL('%s')", SEQUENCE_NAME);
getQuery = "SELECT last_value FROM %s".formatted(SEQUENCE_NAME);
incrementAndGetQuery = "SELECT NEXTVAL('%s')".formatted(SEQUENCE_NAME);
} else if (props.isH2()) {
createSequenceStatement = format("CREATE SEQUENCE IF NOT EXISTS %s", SEQUENCE_NAME);
createSequenceStatement = "CREATE SEQUENCE IF NOT EXISTS %s".formatted(SEQUENCE_NAME);
getQuery =
format(
"""
"""
SELECT CURRENT_VALUE \
FROM INFORMATION_SCHEMA.SEQUENCES \
WHERE SEQUENCE_NAME = '%s'
""",
SEQUENCE_NAME.toUpperCase());
incrementAndGetQuery = format("SELECT NEXTVAL('%s')", SEQUENCE_NAME);
"""
.formatted(SEQUENCE_NAME.toUpperCase());
incrementAndGetQuery = "SELECT NEXTVAL('%s')".formatted(SEQUENCE_NAME);
} else {
throw new IllegalStateException("Db is not PostgreSQL nor H2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public RemoteGeoServerEvent(

@Override
public String toString() {
return String.format(
"[%s id: '%s', originService: '%s', destinationService: '%s', payload: %s]",
getClass().getSimpleName(),
getId(),
getOriginService(),
getDestinationService(),
getEvent());
return "[%s id: '%s', originService: '%s', destinationService: '%s', payload: %s]"
.formatted(
getClass().getSimpleName(),
getId(),
getOriginService(),
getDestinationService(),
getEvent());
}

public String toShortString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,8 @@ private Patch roundtrip(Patch patch) throws JsonProcessingException {
Class<? extends Info> type = ProxyUtils.referenceTypeOf(patchValue).orElseThrow();
Supplier<String> desc =
() -> {
return String.format(
"Patch value of type %s shall be encoded as reference, got value %s",
type.getCanonicalName(), typeName);
return "Patch value of type %s shall be encoded as reference, got value %s"
.formatted(type.getCanonicalName(), typeName);
};
assertThat(typeName).as(desc).isEqualTo("ResolvingProxy");
} else {
Expand Down Expand Up @@ -837,16 +836,14 @@ protected void assertNotAProxy(Object value) {
assertThat(ProxyUtils.isResolvingProxy(info))
.as(
() ->
String.format(
"%s should not be a ResolvingProxy: %s",
info.getId(), typeName(info)))
"%s should not be a ResolvingProxy: %s"
.formatted(info.getId(), typeName(info)))
.isFalse();
assertThat(ProxyUtils.isModificationProxy(info))
.as(
() ->
String.format(
"%s should not be a ModificationProxy: %s",
info.getId(), typeName(info)))
"%s should not be a ModificationProxy: %s"
.formatted(info.getId(), typeName(info)))
.isFalse();
}
}
Expand All @@ -855,9 +852,8 @@ protected <I extends Info> I assertModificationProxy(I info) {
assertThat(ProxyUtils.isModificationProxy(info))
.as(
() ->
String.format(
"%s should be a ModificationProxy, got %s",
info.getId(), typeName(info)))
"%s should be a ModificationProxy, got %s"
.formatted(info.getId(), typeName(info)))
.isTrue();

I real = ModificationProxy.unwrap(info);
Expand All @@ -876,19 +872,17 @@ protected void assertResolvingProxy(Info info) {
assertThat(ProxyUtils.isResolvingProxy(info))
.as(
() ->
String.format(
"%s should be a ResolvingProxy, got %s",
info.getId(), typeName(info)))
"%s should be a ResolvingProxy, got %s"
.formatted(info.getId(), typeName(info)))
.isTrue();
}

private void assertValueObject(Object valueObject, Class<?> valueType) {
if (valueObject instanceof Info info) {
Supplier<String> msg =
() ->
String.format(
"expected pure value object of type %s, got %s",
valueType.getCanonicalName(), typeName(valueObject));
"expected pure value object of type %s, got %s"
.formatted(valueType.getCanonicalName(), typeName(valueObject));
assertThat(ProxyUtils.isResolvingProxy(info)).as(msg).isFalse();
assertThat(ProxyUtils.isModificationProxy(info)).as(msg).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void assertActuallyEqualsExact(Geometry g1, Geometry g2) {
for (int i = 0; i < cs1.length; i++) {
Coordinate c1 = cs1[i];
Coordinate c2 = cs2[i];
assertTrue(c1.equals3D(c2), String.format("expected %s, got %s", c1, c2));
assertTrue(c1.equals3D(c2), "expected %s, got %s".formatted(c1, c2));
assertEquals(c1.getM(), c2.getM(), 1e-9d);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public void add(T value) {
synchronized (idMap) {
if (null != idMap.putIfAbsent(value.getId(), value)) {
String msg =
String.format(
"%s:%s(%s) already exists",
ClassMappings.fromImpl(value.getClass()),
value.getId(),
nameMapper.apply(value).getLocalPart());
"%s:%s(%s) already exists"
.formatted(
ClassMappings.fromImpl(value.getClass()),
value.getId(),
nameMapper.apply(value).getLocalPart());
LOGGER.warning(msg);
}
Name name = nameMapper.apply(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ private static boolean isCollection(Method getter) {
public String toString() {
String props =
this.getPatches().stream()
.map(p -> String.format("(%s: %s)", p.getName(), p.getValue()))
.map(p -> "(%s: %s)".formatted(p.getName(), p.getValue()))
.collect(Collectors.joining(","));
return String.format("%s[%s]", getClass().getSimpleName(), props);
return "%s[%s]".formatted(getClass().getSimpleName(), props);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static Change valueOf(String propertyName, Object oldValue, Object newVal

@Override
public String toString() {
return String.format("%s: {old: %s, new: %s}", propertyName, oldValue, newValue);
return "%s: {old: %s, new: %s}".formatted(propertyName, oldValue, newValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.geoserver.catalog.plugin;

import static java.lang.String.format;

import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogCapabilities;
import org.geoserver.catalog.CatalogException;
Expand Down Expand Up @@ -665,9 +663,8 @@ private <T extends CatalogInfo> void checkCanSort(final Query<T> query) {
private <T extends CatalogInfo> void checkCanSort(final Class<T> type, SortBy order) {
if (!canSort(type, order.getPropertyName().getPropertyName())) {
throw new IllegalArgumentException(
format(
"Can't sort objects of type %s by %s",
type.getName(), order.getPropertyName()));
"Can't sort objects of type %s by %s"
.formatted(type.getName(), order.getPropertyName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import static org.geoserver.GeoServerConfigurationLock.LockType.WRITE;

import static java.lang.String.format;

import lombok.NonNull;

import org.geoserver.GeoServerConfigurationLock;
Expand Down Expand Up @@ -76,9 +74,11 @@ public boolean isWriteLocked() {
final boolean globalWriteLocked = GLOBAL.get().isWriteLocked();
if (jvmWriteLocked != globalWriteLocked) {
String msg =
format(
"local JVM and global write lock status discrepancy: globally held lock count: %d, jvm locked: %s. The global lock will forcedly be released.",
GLOBAL.get().writeHoldCount, jvmWriteLocked);
"""
local JVM and global write lock status discrepancy: \
globally held lock count: %d, jvm locked: %s. The global lock will forcedly be released.
"""
.formatted(GLOBAL.get().writeHoldCount, jvmWriteLocked);

GLOBAL.get().forceUnlock();
GLOBAL.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import static org.geoserver.catalog.plugin.locking.LockingSupport.nameOf;
import static org.geoserver.catalog.plugin.locking.LockingSupport.typeOf;

import static java.lang.String.format;

import lombok.NonNull;

import org.geoserver.GeoServerConfigurationLock;
Expand Down Expand Up @@ -82,47 +80,44 @@ public void disableLocking() {
public void setDefaultDataStore(@NonNull WorkspaceInfo workspace, DataStoreInfo store) {
locking.runInWriteLock(
() -> super.setDefaultDataStore(workspace, store),
format(
"setDefaultDataStore(%s, %s)",
workspace.getName(), store == null ? "null" : store.getName()));
"setDefaultDataStore(%s, %s)"
.formatted(workspace.getName(), store == null ? "null" : store.getName()));
}

@Override
public void setDefaultNamespace(NamespaceInfo defaultNamespace) {
locking.runInWriteLock(
() -> super.setDefaultNamespace(defaultNamespace),
format(
"setDefaultNamespace(%s)",
defaultNamespace == null ? "null" : defaultNamespace.getName()));
"setDefaultNamespace(%s)"
.formatted(defaultNamespace == null ? "null" : defaultNamespace.getName()));
}

@Override
public void setDefaultWorkspace(WorkspaceInfo defaultWorkspace) {
locking.runInWriteLock(
() -> super.setDefaultWorkspace(defaultWorkspace),
format(
"setDefaultWorkspace(%s)",
defaultWorkspace == null ? "null" : defaultWorkspace.getName()));
"setDefaultWorkspace(%s)"
.formatted(defaultWorkspace == null ? "null" : defaultWorkspace.getName()));
}

/** {@inheritDoc} */
protected @Override <T extends CatalogInfo> void doAdd(T info, UnaryOperator<T> inserter) {
locking.runInWriteLock(
() -> super.doAdd(info, inserter),
format("add(%s[%s])", typeOf(info), nameOf(info)));
"add(%s[%s])".formatted(typeOf(info), nameOf(info)));
}

/** {@inheritDoc} */
protected @Override <I extends CatalogInfo> void doSave(final I info) {
locking.runInWriteLock(
() -> super.doSave(info), format("save(%s[%s])", typeOf(info), nameOf(info)));
() -> super.doSave(info), "save(%s[%s])".formatted(typeOf(info), nameOf(info)));
}

/** {@inheritDoc} */
protected @Override <T extends CatalogInfo> void doRemove(T info, Class<T> type) {
locking.runInWriteLock(
() -> super.doRemove(info, type),
format("remove(%s[%s])", typeOf(info), nameOf(info)));
"remove(%s[%s])".formatted(typeOf(info), nameOf(info)));
}

/**
Expand All @@ -131,6 +126,6 @@ public void setDefaultWorkspace(WorkspaceInfo defaultWorkspace) {
@Override
public void save(StoreInfo store) {
locking.runInWriteLock(
() -> super.save(store), format("save(%s[%s])", typeOf(store), nameOf(store)));
() -> super.save(store), "save(%s[%s])".formatted(typeOf(store), nameOf(store)));
}
}

0 comments on commit ea8a373

Please sign in to comment.