Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit a30f622

Browse files
committed
Refactor to use pattern variables
1 parent c8c9554 commit a30f622

File tree

41 files changed

+129
-145
lines changed

Some content is hidden

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

41 files changed

+129
-145
lines changed

bootstrap/src/main/java/com/proofpoint/bootstrap/Bootstrap.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ public Injector initialize()
307307
Map<String, ConfigurationDefaultingModule> moduleDefaultSource = new HashMap<>();
308308
List<Message> moduleDefaultErrors = new ArrayList<>();
309309
for (Module module : modules) {
310-
if (module instanceof ConfigurationDefaultingModule) {
311-
ConfigurationDefaultingModule configurationDefaultingModule = (ConfigurationDefaultingModule) module;
310+
if (module instanceof ConfigurationDefaultingModule configurationDefaultingModule) {
312311
Map<String, String> defaults = configurationDefaultingModule.getConfigurationDefaults();
313312
for (Entry<String, String> entry : defaults.entrySet()) {
314313
ConfigurationDefaultingModule oldModule = moduleDefaultSource.put(entry.getKey(), configurationDefaultingModule);

concurrent/src/main/java/com/proofpoint/concurrent/MoreFutures.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ public static <V> CompletableFuture<V> firstCompletedFuture(Iterable<? extends C
345345
future.exceptionally(throwable -> {
346346
if (throwable instanceof CancellationException) {
347347
for (CompletionStage<? extends V> sourceFuture : futures) {
348-
if (sourceFuture instanceof Future) {
349-
((Future<?>) sourceFuture).cancel(true);
348+
if (sourceFuture instanceof Future<?> f) {
349+
f.cancel(true);
350350
}
351351
}
352352
}

configuration/src/main/java/com/proofpoint/configuration/AbstractConfigurationAwareModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ protected synchronized <T> T buildConfigObject(Class<T> configClass, String pref
5959

6060
protected synchronized void install(Module module)
6161
{
62-
if (module instanceof ConfigurationAwareModule) {
63-
((ConfigurationAwareModule) module).setConfigurationFactory(configurationFactory);
62+
if (module instanceof ConfigurationAwareModule configurationAwareModule) {
63+
configurationAwareModule.setConfigurationFactory(configurationFactory);
6464
}
6565
binder.install(module);
6666
}

configuration/src/main/java/com/proofpoint/configuration/ConfigurationValidator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ public List<Message> validate(Iterable<? extends Module> modules)
6666
public <T> Void visit(Binding<T> binding)
6767
{
6868
// look for ConfigurationAwareProviders...
69-
if (binding instanceof ProviderInstanceBinding) {
70-
ProviderInstanceBinding<?> providerInstanceBinding = (ProviderInstanceBinding<?>) binding;
69+
if (binding instanceof ProviderInstanceBinding<?> providerInstanceBinding) {
7170
Provider<?> provider = providerInstanceBinding.getUserSuppliedProvider();
72-
if (provider instanceof ConfigurationAwareProvider) {
73-
ConfigurationAwareProvider<?> configurationProvider = (ConfigurationAwareProvider<?>) provider;
71+
if (provider instanceof ConfigurationAwareProvider<?> configurationProvider) {
7472
// give the provider the configuration factory
7573
configurationProvider.setConfigurationFactory(configurationFactory);
7674
try {

configuration/src/main/java/com/proofpoint/configuration/TypeParameterUtils.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ private TypeParameterUtils()
2929

3030
public static Type[] getTypeParameters(Class<?> desiredType, Type type)
3131
{
32-
if (type instanceof Class) {
33-
Class<?> rawClass = (Class<?>) type;
34-
32+
if (type instanceof Class<?> rawClass) {
3533
// if this is the collection class we're done
3634
if (desiredType.equals(type)) {
3735
return null;
@@ -46,9 +44,7 @@ public static Type[] getTypeParameters(Class<?> desiredType, Type type)
4644

4745
return getTypeParameters(desiredType, rawClass.getGenericSuperclass());
4846
}
49-
if (type instanceof ParameterizedType) {
50-
ParameterizedType parameterizedType = (ParameterizedType) type;
51-
47+
if (type instanceof ParameterizedType parameterizedType) {
5248
Type rawType = parameterizedType.getRawType();
5349
if (desiredType.equals(rawType)) {
5450
return parameterizedType.getActualTypeArguments();
@@ -57,8 +53,7 @@ public static Type[] getTypeParameters(Class<?> desiredType, Type type)
5753
Type[] collectionTypes = getTypeParameters(desiredType, rawType);
5854
if (collectionTypes != null) {
5955
for (int i = 0; i < collectionTypes.length; i++) {
60-
if (collectionTypes[i] instanceof TypeVariable) {
61-
TypeVariable<?> typeVariable = (TypeVariable<?>) collectionTypes[i];
56+
if (collectionTypes[i] instanceof TypeVariable<?> typeVariable) {
6257
TypeVariable<?>[] rawTypeParams = ((GenericDeclaration) rawType).getTypeParameters();
6358
for (int j = 0; j < rawTypeParams.length; j++) {
6459
if (typeVariable.getName().equals(rawTypeParams[j].getName())) {

discovery/src/main/java/com/proofpoint/discovery/client/HttpDiscoveryLookupClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public final T handleException(Request request, Exception exception)
186186
if (exception instanceof CancellationException) {
187187
throw new DiscoveryException(name + " was canceled");
188188
}
189-
if (exception instanceof DiscoveryException) {
190-
throw (DiscoveryException) exception;
189+
if (exception instanceof DiscoveryException discoveryException) {
190+
throw discoveryException;
191191
}
192192

193193
throw new DiscoveryException(name + " failed", exception);

discovery/src/main/java/com/proofpoint/discovery/client/ServiceTypeImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ public boolean equals(Object o)
4848
if (this == o) {
4949
return true;
5050
}
51-
if (!(o instanceof ServiceType)) {
51+
if (!(o instanceof ServiceType that)) {
5252
return false;
5353
}
5454

55-
ServiceType that = (ServiceType) o;
56-
5755
if (!value.equals(that.value())) {
5856
return false;
5957
}

discovery/src/main/java/com/proofpoint/discovery/client/announce/HttpDiscoveryAnnouncementClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public final T handleException(Request request, Exception exception)
169169
if (exception instanceof CancellationException) {
170170
throw new DiscoveryException(name + " was canceled");
171171
}
172-
if (exception instanceof DiscoveryException) {
173-
throw (DiscoveryException) exception;
172+
if (exception instanceof DiscoveryException discoveryException) {
173+
throw discoveryException;
174174
}
175175

176176
throw new DiscoveryException(name + " failed", exception);

event/src/main/java/com/proofpoint/event/client/EventTypeMetadata.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ private Class<?> extractIterableType(Method method)
237237
return null;
238238
}
239239
Type type = types[0];
240-
if (!(type instanceof Class)) {
240+
if (!(type instanceof Class<?> clazz)) {
241241
addMethodError("Iterable type parameter [%s] must be an exact type", method, type);
242242
return null;
243243
}
244-
if (isIterable((Class<?>) type)) {
244+
if (isIterable(clazz)) {
245245
addMethodError("Iterable of iterable is not supported", method);
246246
return null;
247247
}
248-
return (Class<?>) type;
248+
return clazz;
249249
}
250250

251251
private Class<?> extractMapType(Method method, Class<?> mapClass)
@@ -258,22 +258,22 @@ private Class<?> extractMapType(Method method, Class<?> mapClass)
258258
}
259259
Type keyType = types[0];
260260
Type valueType = types[1];
261-
if (!(keyType instanceof Class)) {
261+
if (!(keyType instanceof Class<?> keyClass)) {
262262
addMethodError("%s key type parameter [%s] must be an exact type", method, className, keyType);
263263
return null;
264264
}
265-
if (!(valueType instanceof Class)) {
265+
if (!(valueType instanceof Class<?> valueClass)) {
266266
addMethodError("%s value type parameter [%s] must be an exact type", method, className, valueType);
267267
return null;
268268
}
269-
if (!isString((Class<?>) keyType)) {
269+
if (!isString(keyClass)) {
270270
addMethodError("%s key type parameter [%s] must be a String", method, className, keyType);
271271
}
272-
if (isIterable((Class<?>) valueType)) {
272+
if (isIterable(valueClass)) {
273273
addMethodError("%s value type parameter [%s] cannot be iterable", method, className, valueType);
274274
return null;
275275
}
276-
return (Class<?>) valueType;
276+
return valueClass;
277277
}
278278

279279
@SuppressWarnings("unchecked")

http-client/src/main/java/com/proofpoint/http/client/Request.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,9 @@ public int hashCode()
123123
@Override
124124
public boolean equals(Object obj)
125125
{
126-
if (!(obj instanceof Request)) {
126+
if (!(obj instanceof Request r)) {
127127
return false;
128128
}
129-
final Request r = (Request) obj;
130129
return Objects.equals(uri, r.uri) &&
131130
Objects.equals(method, r.method) &&
132131
Objects.equals(headers, r.headers) &&

0 commit comments

Comments
 (0)