Skip to content

Commit 353acea

Browse files
authored
Build warning fixes (#75)
* Simplify Stream API * Simplify collection creation * Lambdas & Method refs * Pattern variables * Final fields * Simplify if/else * if/else -> switch * isEmpty() * Unnecessary null checks * requireNonNullElseGet * Diamond operator * Boxing / unboxing * Unnecessary StringBuilder * Unnecessary modifier * Unnecessary semicolon * Visibility issues * Static access * Usage of raw class * Sequenced collection
1 parent 74cfe50 commit 353acea

37 files changed

+189
-221
lines changed

extension/persistence/eclipselink/src/main/java/io/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public class PolarisEclipseLinkMetaStoreSessionImpl implements PolarisMetaStoreS
7676
private static final Logger LOG =
7777
LoggerFactory.getLogger(PolarisEclipseLinkMetaStoreSessionImpl.class);
7878

79-
private EntityManagerFactory emf;
80-
private ThreadLocal<EntityManager> localSession = new ThreadLocal<>();
79+
private final EntityManagerFactory emf;
80+
private final ThreadLocal<EntityManager> localSession = new ThreadLocal<>();
8181
private final PolarisEclipseLinkStore store;
8282
private final PolarisStorageIntegrationProvider storageIntegrationProvider;
8383
private static volatile Map<String, String> properties;
@@ -119,8 +119,8 @@ public PolarisEclipseLinkMetaStoreSessionImpl(
119119

120120
/** Load the persistence unit properties from a given configuration file */
121121
private Map<String, String> loadProperties(String confFile, String persistenceUnitName) {
122-
if (this.properties != null) {
123-
return this.properties;
122+
if (properties != null) {
123+
return properties;
124124
}
125125

126126
try {
@@ -141,7 +141,7 @@ private Map<String, String> loadProperties(String confFile, String persistenceUn
141141
nodeMap.getNamedItem("value").getNodeValue());
142142
}
143143

144-
this.properties = properties;
144+
PolarisEclipseLinkMetaStoreSessionImpl.properties = properties;
145145
return properties;
146146
} catch (Exception e) {
147147
LOG.warn(
@@ -262,10 +262,10 @@ public void writeToEntities(
262262

263263
/** {@inheritDoc} */
264264
@Override
265-
public void persistStorageIntegrationIfNeeded(
265+
public <T extends PolarisStorageConfigurationInfo> void persistStorageIntegrationIfNeeded(
266266
@NotNull PolarisCallContext callContext,
267267
@NotNull PolarisBaseEntity entity,
268-
@Nullable PolarisStorageIntegration storageIntegration) {
268+
@Nullable PolarisStorageIntegration<T> storageIntegration) {
269269
// not implemented for eclipselink store
270270
}
271271

@@ -373,7 +373,7 @@ public void deleteAll(@NotNull PolarisCallContext callCtx) {
373373
public @NotNull List<PolarisBaseEntity> lookupEntities(
374374
@NotNull PolarisCallContext callCtx, List<PolarisEntityId> entityIds) {
375375
return this.store.lookupEntities(localSession.get(), entityIds).stream()
376-
.map(model -> ModelEntity.toEntity(model))
376+
.map(ModelEntity::toEntity)
377377
.toList();
378378
}
379379

@@ -477,7 +477,7 @@ public List<PolarisEntityActiveRecord> lookupEntityActiveBatch(
477477
return this.store
478478
.lookupFullEntitiesActive(localSession.get(), catalogId, parentId, entityType)
479479
.stream()
480-
.map(model -> ModelEntity.toEntity(model))
480+
.map(ModelEntity::toEntity)
481481
.filter(entityFilter)
482482
.limit(limit)
483483
.map(transformer)
@@ -534,7 +534,7 @@ public int lookupEntityGrantRecordsVersion(
534534
return this.store
535535
.lookupAllGrantRecordsOnSecurable(localSession.get(), securableCatalogId, securableId)
536536
.stream()
537-
.map(model -> ModelGrantRecord.toGrantRecord(model))
537+
.map(ModelGrantRecord::toGrantRecord)
538538
.toList();
539539
}
540540

@@ -546,7 +546,7 @@ public int lookupEntityGrantRecordsVersion(
546546
return this.store
547547
.lookupGrantRecordsOnGrantee(localSession.get(), granteeCatalogId, granteeId)
548548
.stream()
549-
.map(model -> ModelGrantRecord.toGrantRecord(model))
549+
.map(ModelGrantRecord::toGrantRecord)
550550
.toList();
551551
}
552552

extension/persistence/eclipselink/src/main/java/io/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class PolarisEclipseLinkStore {
4848
private static final Logger LOG = LoggerFactory.getLogger(PolarisEclipseLinkStore.class);
4949

5050
// diagnostic services
51-
private PolarisDiagnostics diagnosticServices;
51+
private final PolarisDiagnostics diagnosticServices;
5252

5353
/**
5454
* Constructor, allocate everything at once

polaris-core/src/main/java/io/polaris/core/auth/AuthenticatedPolarisPrincipal.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ public void setActivatedPrincipalRoles(List<PrincipalRoleEntity> activatedPrinci
5959

6060
@Override
6161
public String toString() {
62-
StringBuilder sb = new StringBuilder();
63-
sb.append("principalEntity=" + getPrincipalEntity());
64-
sb.append(";activatedPrincipalRoleNames=" + getActivatedPrincipalRoleNames());
65-
sb.append(";activatedPrincipalRoles=" + getActivatedPrincipalRoles());
66-
return sb.toString();
62+
return "principalEntity="
63+
+ getPrincipalEntity()
64+
+ ";activatedPrincipalRoleNames="
65+
+ getActivatedPrincipalRoleNames()
66+
+ ";activatedPrincipalRoles="
67+
+ getActivatedPrincipalRoles();
6768
}
6869
}

polaris-core/src/main/java/io/polaris/core/catalog/PolarisCatalogHelpers.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.polaris.core.catalog;
1717

18+
import com.google.common.collect.ImmutableList;
1819
import io.polaris.core.entity.PolarisEntity;
1920
import java.util.ArrayList;
2021
import java.util.Arrays;
@@ -36,10 +37,11 @@ public class PolarisCatalogHelpers {
3637
private PolarisCatalogHelpers() {}
3738

3839
public static List<String> tableIdentifierToList(TableIdentifier identifier) {
39-
List<String> fullList = new ArrayList<>();
40+
ImmutableList.Builder<String> fullList =
41+
ImmutableList.builderWithExpectedSize(identifier.namespace().length() + 1);
4042
fullList.addAll(Arrays.asList(identifier.namespace().levels()));
4143
fullList.add(identifier.name());
42-
return fullList;
44+
return fullList.build();
4345
}
4446

4547
public static TableIdentifier listToTableIdentifier(List<String> ids) {

polaris-core/src/main/java/io/polaris/core/context/CallContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface CallContext extends AutoCloseable {
4040

4141
// For requests that make use of a Catalog instance, this holds the instance that was
4242
// created, scoped to the current call context.
43-
public static final String REQUEST_PATH_CATALOG_INSTANCE_KEY = "REQUEST_PATH_CATALOG_INSTANCE";
43+
String REQUEST_PATH_CATALOG_INSTANCE_KEY = "REQUEST_PATH_CATALOG_INSTANCE";
4444

4545
// Authenticator filters should populate this field alongside resolving a SecurityContext.
4646
// Value type: AuthenticatedPolarisPrincipal

polaris-core/src/main/java/io/polaris/core/entity/PolarisEntity.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,20 @@ public NameAndId nameAndId() {
203203

204204
@Override
205205
public String toString() {
206-
StringBuilder sb = new StringBuilder();
207-
sb.append("name=" + getName());
208-
sb.append(";id=" + getId());
209-
sb.append(";parentId=" + getParentId());
210-
sb.append(";entityVersion=" + getEntityVersion());
211-
sb.append(";type=" + getType());
212-
sb.append(";subType=" + getSubType());
213-
sb.append(";internalProperties=" + getInternalPropertiesAsMap());
214-
return sb.toString();
206+
return "name="
207+
+ getName()
208+
+ ";id="
209+
+ getId()
210+
+ ";parentId="
211+
+ getParentId()
212+
+ ";entityVersion="
213+
+ getEntityVersion()
214+
+ ";type="
215+
+ getType()
216+
+ ";subType="
217+
+ getSubType()
218+
+ ";internalProperties="
219+
+ getInternalPropertiesAsMap();
215220
}
216221

217222
@Override

polaris-core/src/main/java/io/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
public abstract class LocalPolarisMetaStoreManagerFactory<StoreType>
4444
implements MetaStoreManagerFactory {
4545

46-
Map<String, PolarisMetaStoreManager> metaStoreManagerMap = new HashMap<>();
47-
Map<String, StorageCredentialCache> storageCredentialCacheMap = new HashMap<>();
48-
Map<String, StoreType> backingStoreMap = new HashMap<>();
49-
Map<String, Supplier<PolarisMetaStoreSession>> sessionSupplierMap = new HashMap<>();
50-
protected PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
46+
final Map<String, PolarisMetaStoreManager> metaStoreManagerMap = new HashMap<>();
47+
final Map<String, StorageCredentialCache> storageCredentialCacheMap = new HashMap<>();
48+
final Map<String, StoreType> backingStoreMap = new HashMap<>();
49+
final Map<String, Supplier<PolarisMetaStoreSession>> sessionSupplierMap = new HashMap<>();
50+
protected final PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
5151

5252
protected PolarisStorageIntegrationProvider storageIntegration;
5353

54-
private Logger logger =
54+
private final Logger logger =
5555
org.slf4j.LoggerFactory.getLogger(LocalPolarisMetaStoreManagerFactory.class);
5656

5757
protected abstract StoreType createBackingStore(@NotNull PolarisDiagnostics diagnostics);

polaris-core/src/main/java/io/polaris/core/persistence/PolarisObjectMapperUtil.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,25 @@ public int getAttemptCount() {
150150
while (jParser.nextToken() != JsonToken.END_OBJECT) {
151151
if (jParser.getCurrentToken() == JsonToken.FIELD_NAME) {
152152
String fieldName = jParser.currentName();
153-
if (fieldName.equals(PolarisTaskConstants.LAST_ATTEMPT_EXECUTOR_ID)) {
154-
jParser.nextToken();
155-
executorId = jParser.getText();
156-
} else if (fieldName.equals(PolarisTaskConstants.LAST_ATTEMPT_START_TIME)) {
157-
jParser.nextToken();
158-
lastAttemptStartTime = Long.parseLong(jParser.getText());
159-
} else if (fieldName.equals(PolarisTaskConstants.ATTEMPT_COUNT)) {
160-
jParser.nextToken();
161-
attemptCount = Integer.parseInt(jParser.getText());
162-
} else {
163-
JsonToken next = jParser.nextToken();
164-
if (next == JsonToken.START_OBJECT || next == JsonToken.START_ARRAY) {
165-
jParser.skipChildren();
166-
}
153+
switch (fieldName) {
154+
case PolarisTaskConstants.LAST_ATTEMPT_EXECUTOR_ID:
155+
jParser.nextToken();
156+
executorId = jParser.getText();
157+
break;
158+
case PolarisTaskConstants.LAST_ATTEMPT_START_TIME:
159+
jParser.nextToken();
160+
lastAttemptStartTime = Long.parseLong(jParser.getText());
161+
break;
162+
case PolarisTaskConstants.ATTEMPT_COUNT:
163+
jParser.nextToken();
164+
attemptCount = Integer.parseInt(jParser.getText());
165+
break;
166+
default:
167+
JsonToken next = jParser.nextToken();
168+
if (next == JsonToken.START_OBJECT || next == JsonToken.START_ARRAY) {
169+
jParser.skipChildren();
170+
}
171+
break;
167172
}
168173
}
169174
}

polaris-core/src/main/java/io/polaris/core/persistence/PolarisResolvedPathWrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public List<PolarisEntity> getRawFullPath() {
5454
if (resolvedPath == null) {
5555
return null;
5656
}
57-
return resolvedPath.stream().map(resolved -> resolved.getEntity()).toList();
57+
return resolvedPath.stream().map(ResolvedPolarisEntity::getEntity).toList();
5858
}
5959

6060
public List<ResolvedPolarisEntity> getResolvedParentPath() {
@@ -68,14 +68,11 @@ public List<PolarisEntity> getRawParentPath() {
6868
if (resolvedPath == null) {
6969
return null;
7070
}
71-
return getResolvedParentPath().stream().map(resolved -> resolved.getEntity()).toList();
71+
return getResolvedParentPath().stream().map(ResolvedPolarisEntity::getEntity).toList();
7272
}
7373

7474
@Override
7575
public String toString() {
76-
StringBuilder sb = new StringBuilder();
77-
sb.append("resolvedPath:");
78-
sb.append(resolvedPath);
79-
return sb.toString();
76+
return "resolvedPath:" + resolvedPath;
8077
}
8178
}

polaris-core/src/main/java/io/polaris/core/persistence/PolarisTreeMapMetaStoreSessionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ public void writeToEntities(
104104

105105
/** {@inheritDoc} */
106106
@Override
107-
public void persistStorageIntegrationIfNeeded(
107+
public <T extends PolarisStorageConfigurationInfo> void persistStorageIntegrationIfNeeded(
108108
@NotNull PolarisCallContext callContext,
109109
@NotNull PolarisBaseEntity entity,
110-
@Nullable PolarisStorageIntegration storageIntegration) {
110+
@Nullable PolarisStorageIntegration<T> storageIntegration) {
111111
// not implemented for in-memory store
112112
}
113113

0 commit comments

Comments
 (0)