Skip to content

Commit a0bf4f4

Browse files
mawiesnerzo1
authored andcommitted
Replace local var declarations with more compact pattern variables (Part 3)
1 parent 02e9064 commit a0bf4f4

File tree

112 files changed

+256
-526
lines changed

Some content is hidden

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

112 files changed

+256
-526
lines changed

container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ private static List<String> getClosedJarFiles(final ClassLoader cl) {
170170

171171
final List<String> files = new ArrayList<>();
172172

173-
if (null != cl && cl instanceof URLClassLoader) {
173+
if (null != cl && cl instanceof URLClassLoader ucl) {
174174

175-
final URLClassLoader ucl = (URLClassLoader) cl;
176175
final Class clazz = URLClassLoader.class;
177176

178177
try {
@@ -229,11 +228,10 @@ public boolean finalizeNativeLibs(final ClassLoader cl) {
229228
//Ignore
230229
}
231230

232-
if (!(obj instanceof Vector)) {
231+
if (!(obj instanceof Vector javaLangClassLoaderNativeLibrary)) {
233232
return false;
234233
}
235234

236-
final Vector javaLangClassLoaderNativeLibrary = (Vector) obj;
237235
Method finalize;
238236

239237
for (final Object lib : javaLangClassLoaderNativeLibrary) {
@@ -394,8 +392,7 @@ private static synchronized void clearSunJarFileFactoryCacheImpl(final String ja
394392
final Map.Entry entry = (Map.Entry) iterator.next();
395393
final Object key = entry.getKey();
396394

397-
if (key instanceof ZipFile) {
398-
final ZipFile zf = (ZipFile) key;
395+
if (key instanceof ZipFile zf) {
399396
final File file = new File(zf.getName()); //getName returns File.getPath()
400397
if (isParent(jarLocation, file)) {
401398
//Flag for removal

container/openejb-core/src/main/java/org/apache/openejb/Injection.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ public boolean equals(final Object o) {
7676
if (this == o) {
7777
return true;
7878
}
79-
if (!(o instanceof Injection)) {
79+
if (!(o instanceof Injection injection)) {
8080
return false;
8181
}
8282

83-
final Injection injection = (Injection) o;
84-
8583
if (!Objects.equals(name, injection.name)) {
8684
return false;
8785
}

container/openejb-core/src/main/java/org/apache/openejb/MethodSpec.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ public boolean equals(final Object obj) {
8787
return true;
8888
}
8989

90-
if (!(obj instanceof MethodSpec)) {
90+
if (!(obj instanceof MethodSpec methodSpec)) {
9191
return false;
9292
}
9393

94-
final MethodSpec methodSpec = (MethodSpec) obj;
9594
return methodIntf.equals(methodSpec.methodIntf) &&
9695
methodName.equals(methodSpec.methodName) &&
9796
Arrays.equals(parameterTypes, methodSpec.parameterTypes);
@@ -142,13 +141,12 @@ public boolean matches(final String methodIntf, final String methodName, final S
142141
}
143142

144143
public int compareTo(final Object o) {
145-
if (!(o instanceof MethodSpec)) {
144+
if (!(o instanceof MethodSpec other)) {
146145
return -1;
147146
}
148147
if (this == o) {
149148
return 0;
150149
}
151-
final MethodSpec other = (MethodSpec) o;
152150
if (parameterTypes != null) {
153151
if (other.parameterTypes == null) {
154152
//parameter types always come before no param types

container/openejb-core/src/main/java/org/apache/openejb/OpenEjbContainer.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -502,14 +502,13 @@ private AppModule createAppModule(final Map<?, ?> map, final ConfigurationFactor
502502
final URL url = ((File) modules).toURI().toURL();
503503
classLoader = new URLClassLoader(new URL[]{url}, classLoader);
504504
moduleLocations = Collections.singletonList((File) modules);
505-
} else if (modules instanceof File[]) {
506-
final File[] files = (File[]) modules;
505+
} else if (modules instanceof File[] files) {
507506
final URL[] urls = new URL[files.length];
508507
for (int i = 0; i < urls.length; i++) {
509508
urls[i] = files[i].toURI().toURL();
510509
}
511510
classLoader = new URLClassLoader(urls, classLoader);
512-
moduleLocations = Arrays.asList((File[]) modules);
511+
moduleLocations = Arrays.asList(files);
513512
} else if (modules == null) {
514513
moduleLocations = configurationFactory.getModulesFromClassPath(null, classLoader);
515514
} else {
@@ -535,28 +534,22 @@ private AppModule createAppModule(final Map<?, ?> map) {
535534
Application application = null;
536535
AppModule appModule = new AppModule(this.getClass().getClassLoader(), appId);
537536

538-
if (modules instanceof EjbJar) {
539-
final EjbJar ejbJar = (EjbJar) modules;
537+
if (modules instanceof EjbJar ejbJar) {
540538
appModule.getEjbModules().add(new EjbModule(ejbJar));
541-
} else if (modules instanceof EnterpriseBean) {
542-
final EnterpriseBean bean = (EnterpriseBean) modules;
539+
} else if (modules instanceof EnterpriseBean bean) {
543540
final EjbJar ejbJar = new EjbJar();
544541
ejbJar.addEnterpriseBean(bean);
545542
appModule.getEjbModules().add(new EjbModule(ejbJar));
546543

547544
} else if (modules instanceof Application) {
548545
application = (Application) modules;
549-
} else if (modules instanceof Connector) {
550-
final Connector connector = (Connector) modules;
546+
} else if (modules instanceof Connector connector) {
551547
appModule.getConnectorModules().add(new ConnectorModule(connector));
552-
} else if (modules instanceof org.apache.openejb.jee.jpa.unit.Persistence) {
553-
final org.apache.openejb.jee.jpa.unit.Persistence persistence = (org.apache.openejb.jee.jpa.unit.Persistence) modules;
548+
} else if (modules instanceof org.apache.openejb.jee.jpa.unit.Persistence persistence) {
554549
appModule.addPersistenceModule(new PersistenceModule(appModule, "", persistence));
555-
} else if (modules instanceof PersistenceUnit) {
556-
final PersistenceUnit unit = (PersistenceUnit) modules;
550+
} else if (modules instanceof PersistenceUnit unit) {
557551
appModule.addPersistenceModule(new PersistenceModule(appModule, "", new org.apache.openejb.jee.jpa.unit.Persistence(unit)));
558-
} else if (modules instanceof Beans) {
559-
final Beans beans = (Beans) modules;
552+
} else if (modules instanceof Beans beans) {
560553
final EjbModule ejbModule = new EjbModule(new EjbJar());
561554
ejbModule.setBeans(beans);
562555
appModule.getEjbModules().add(ejbModule);

container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,8 +2136,7 @@ private void doResourceDestruction(final String name, final String className, fi
21362136
final ResourceBeforeDestroyed event = new ResourceBeforeDestroyed(jndiObject, name);
21372137
SystemInstance.get().fireEvent(event);
21382138
final Object object = event.getReplacement() == null ? jndiObject : event.getReplacement();
2139-
if (object instanceof ResourceAdapterReference) {
2140-
final ResourceAdapterReference resourceAdapter = (ResourceAdapterReference) object;
2139+
if (object instanceof ResourceAdapterReference resourceAdapter) {
21412140
try {
21422141
logger.info("Stopping ResourceAdapter: " + name);
21432142

@@ -2157,8 +2156,7 @@ private void doResourceDestruction(final String name, final String className, fi
21572156

21582157
removeResourceMBean(name, "ResourceAdapter");
21592158

2160-
} else if (object instanceof ResourceAdapter) {
2161-
final ResourceAdapter resourceAdapter = (ResourceAdapter) object;
2159+
} else if (object instanceof ResourceAdapter resourceAdapter) {
21622160
try {
21632161
logger.info("Stopping ResourceAdapter: " + name);
21642162

@@ -2181,8 +2179,7 @@ private void doResourceDestruction(final String name, final String className, fi
21812179
} catch (final Throwable t) {
21822180
//Ignore
21832181
}
2184-
} else if (object instanceof ConnectorReference) {
2185-
final ConnectorReference cr = (ConnectorReference) object;
2182+
} else if (object instanceof ConnectorReference cr) {
21862183
try {
21872184
final ConnectionManager cm = cr.getConnectionManager();
21882185
if (cm != null && cm instanceof AbstractConnectionManager) {
@@ -2488,8 +2485,7 @@ public void destroyApplication(final AppInfo appInfo) throws UndeployException {
24882485
}
24892486
}
24902487
try {
2491-
if (globalContext instanceof IvmContext) {
2492-
final IvmContext ivmContext = (IvmContext) globalContext;
2488+
if (globalContext instanceof IvmContext ivmContext) {
24932489
ivmContext.prune("openejb/Deployment");
24942490
ivmContext.prune("openejb/local");
24952491
ivmContext.prune("openejb/remote");
@@ -2975,8 +2971,7 @@ public void createProxyFactory(final ProxyFactoryInfo serviceInfo) throws OpenEJ
29752971

29762972
private void replaceResourceAdapterProperty(final ObjectRecipe serviceRecipe) throws OpenEJBException {
29772973
final Object resourceAdapterId = serviceRecipe.getProperty("ResourceAdapter");
2978-
if (resourceAdapterId instanceof String) {
2979-
String id = (String) resourceAdapterId;
2974+
if (resourceAdapterId instanceof String id) {
29802975
id = id.trim();
29812976

29822977
Object resourceAdapter = null;
@@ -3210,8 +3205,7 @@ public synchronized boolean containsKey(final Object key) {
32103205
serviceInfo.unsetProperties = injectedProperties.get();
32113206

32123207
// Java Connector spec ResourceAdapters and ManagedConnectionFactories need special activation
3213-
if (service instanceof ResourceAdapter) {
3214-
final ResourceAdapter resourceAdapter = (ResourceAdapter) service;
3208+
if (service instanceof ResourceAdapter resourceAdapter) {
32153209

32163210
// Create a thead pool for work manager
32173211
final int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
@@ -3276,8 +3270,7 @@ public synchronized boolean containsKey(final Object key) {
32763270

32773271
registerAsMBean(serviceInfo.id, "ResourceAdapter", resourceAdapter);
32783272
service = new ResourceAdapterReference(resourceAdapter, threadPool, OPENEJB_RESOURCE_JNDI_PREFIX + serviceInfo.id);
3279-
} else if (service instanceof ManagedConnectionFactory) {
3280-
final ManagedConnectionFactory managedConnectionFactory = (ManagedConnectionFactory) service;
3273+
} else if (service instanceof ManagedConnectionFactory managedConnectionFactory) {
32813274

32823275
// connection manager is constructed via a recipe so we automatically expose all cmf properties
32833276
final ObjectRecipe connectionManagerRecipe = new ObjectRecipe(GeronimoConnectionManagerFactory.class, "create");
@@ -3906,12 +3899,10 @@ public boolean equals(final Object o) {
39063899
if (this == o) {
39073900
return true;
39083901
}
3909-
if (!(o instanceof DeploymentListenerObserver)) {
3902+
if (!(o instanceof DeploymentListenerObserver that)) {
39103903
return false;
39113904
}
39123905

3913-
final DeploymentListenerObserver that = (DeploymentListenerObserver) o;
3914-
39153906
return !(!Objects.equals(delegate, that.delegate));
39163907
}
39173908

container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/CmpJarBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ private void generate() throws IOException {
8585
final Map<String, Entry> classes = new HashMap<>();
8686
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
8787
for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
88-
if (beanInfo instanceof EntityBeanInfo) {
89-
final EntityBeanInfo entityBeanInfo = (EntityBeanInfo) beanInfo;
88+
if (beanInfo instanceof EntityBeanInfo entityBeanInfo) {
9089
if ("CONTAINER".equalsIgnoreCase(entityBeanInfo.persistenceType)) {
9190
final Entry entry = generateClass(jarOutputStream, entityBeanInfo);
9291
classes.put(entry.clazz, entry);
@@ -128,8 +127,7 @@ private void generate() throws IOException {
128127
private boolean hasCmpBeans() {
129128
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
130129
for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
131-
if (beanInfo instanceof EntityBeanInfo) {
132-
final EntityBeanInfo entityBeanInfo = (EntityBeanInfo) beanInfo;
130+
if (beanInfo instanceof EntityBeanInfo entityBeanInfo) {
133131
if ("CONTAINER".equalsIgnoreCase(entityBeanInfo.persistenceType)) {
134132
return true;
135133
}

container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ public BeanContext build() throws OpenEJBException {
182182
deployment.setStatefulTimeout(new Duration(bean.statefulTimeout.time, TimeUnit.valueOf(bean.statefulTimeout.unit)));
183183
}
184184

185-
if (bean instanceof StatefulBeanInfo) {
186-
final StatefulBeanInfo statefulBeanInfo = (StatefulBeanInfo) bean;
185+
if (bean instanceof StatefulBeanInfo statefulBeanInfo) {
187186

188187
for (final InitMethodInfo init : statefulBeanInfo.initMethods) {
189188
final Method beanMethod = MethodInfoUtil.toMethod(ejbClass, init.beanMethod);

container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/InterceptorBindingBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public void build(final BeanContext beanContext, final EnterpriseBeanInfo beanIn
129129
toCallback(clazz, beanInfo.postConstruct, beanAsInterceptor.getPostConstruct());
130130
toCallback(clazz, beanInfo.preDestroy, beanAsInterceptor.getPreDestroy());
131131

132-
if (beanInfo instanceof StatefulBeanInfo) {
133-
final StatefulBeanInfo stateful = (StatefulBeanInfo) beanInfo;
132+
if (beanInfo instanceof StatefulBeanInfo stateful) {
134133
toCallback(clazz, stateful.postActivate, beanAsInterceptor.getPostActivate());
135134
toCallback(clazz, stateful.prePassivate, beanAsInterceptor.getPrePassivate());
136135

container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/cmd/Info2Properties.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,13 @@ private static void printSystemProperties(final PrintStream out, final String cr
223223

224224
private static void copyOpenEjbProperties(final Properties source, final Properties dest) {
225225
for (final Map.Entry<Object, Object> entry : source.entrySet()) {
226-
if (!(entry.getKey() instanceof String)) {
226+
if (!(entry.getKey() instanceof String key)) {
227227
continue;
228228
}
229229
if (!(entry.getValue() instanceof String)) {
230230
continue;
231231
}
232232

233-
final String key = (String) entry.getKey();
234233
if (key.startsWith("openejb.")) {
235234
dest.put(entry.getKey(), entry.getValue());
236235
}

container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ public Object call() throws Exception {
112112

113113
final Object value = callable.call();
114114

115-
if (value instanceof Future<?>) {
115+
if (value instanceof Future<?> future) {
116116
// This is the Future object returned by the bean code
117-
final Future<?> future = (Future<?>) value;
118117

119118
return future.get();
120119

0 commit comments

Comments
 (0)