Skip to content

Commit f87d347

Browse files
committed
[refactor] Java16: Use pattern Variable
1 parent 4e843be commit f87d347

File tree

8 files changed

+14
-28
lines changed

8 files changed

+14
-28
lines changed

exist-core/src/main/java/org/exist/config/Configurator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ public static Configuration configure(final Configurable instance, final Configu
229229
//XXX: throw new ConfigurationException("No configuration [" + configName + "]");
230230
}
231231

232-
if (config instanceof ConfigurationImpl) {
233-
final ConfigurationImpl impl = (ConfigurationImpl) config;
232+
if (config instanceof ConfigurationImpl impl) {
234233
//XXX: lock issue here, fix it
235234
Configurable configurable = null;
236235
if (impl.configuredObjectReference != null) {

exist-core/src/main/java/org/exist/dom/persistent/DocumentImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,10 +948,9 @@ public int compareTo(@EnsureLocked(mode=READ_LOCK) final DocumentImpl other) {
948948

949949
@Override
950950
public IStoredNode updateChild(final Txn transaction, final Node oldChild, final Node newChild) throws DOMException {
951-
if(!(oldChild instanceof StoredNode)) {
951+
if(!(oldChild instanceof IStoredNode<?> oldNode)) {
952952
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Node does not belong to this document");
953953
}
954-
final IStoredNode<?> oldNode = (IStoredNode<?>) oldChild;
955954
final IStoredNode<?> newNode = (IStoredNode<?>) newChild;
956955
final IStoredNode<?> previousNode = (IStoredNode<?>) oldNode.getPreviousSibling();
957956
if(previousNode == null) {

exist-core/src/main/java/org/exist/jetty/JettyStart.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,11 @@ public synchronized void run(final String[] args, final Observer observer) {
320320
final LinkedHashSet<Handler> handlers = getAllHandlers(server.getHandler());
321321
for (final Handler handler: handlers) {
322322

323-
if (handler instanceof ContextHandler) {
324-
final ContextHandler contextHandler = (ContextHandler) handler;
323+
if (handler instanceof ContextHandler contextHandler) {
325324
logger.info("{} ({})", contextHandler.getContextPath(), contextHandler.getDisplayName());
326325
}
327326

328-
if (handler instanceof ServletContextHandler) {
329-
final ServletContextHandler contextHandler = (ServletContextHandler) handler;
327+
if (handler instanceof ServletContextHandler contextHandler) {
330328
final ServiceLoader<ExistExtensionServlet> services = ServiceLoader.load(ExistExtensionServlet.class);
331329

332330
for (ExistExtensionServlet existExtensionServlet : services) {

exist-core/src/main/java/org/exist/security/internal/AccountImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ private void instantiate(final Account from_user) throws PermissionDeniedExcepti
172172
//copy umask
173173
setUserMask(from_user.getUserMask());
174174

175-
if(from_user instanceof AccountImpl) {
176-
final AccountImpl user = (AccountImpl) from_user;
175+
if(from_user instanceof AccountImpl user) {
177176

178177
groups = new ArrayList<>(user.groups);
179178

@@ -183,8 +182,7 @@ private void instantiate(final Account from_user) throws PermissionDeniedExcepti
183182
hasDbaRole = user.hasDbaRole;
184183

185184
_cred = user._cred;
186-
} else if(from_user instanceof UserAider) {
187-
final UserAider user = (UserAider) from_user;
185+
} else if(from_user instanceof UserAider user) {
188186

189187
final String[] groups = user.getGroups();
190188
for (final String group : groups) {

exist-core/src/main/java/org/exist/util/XMLString.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ public boolean equals(final Object anObject) {
332332
if (this == anObject) {
333333
return true;
334334
}
335-
if (anObject instanceof XMLString) {
336-
final XMLString anotherString = (XMLString) anObject;
335+
if (anObject instanceof XMLString anotherString) {
337336
if (length_ == anotherString.length_) {
338337
int n = length_;
339338
final char[] v1 = value_;

exist-core/src/main/java/org/exist/xmldb/LocalXMLResource.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,18 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
397397
*/
398398
Object domResult = null;
399399
if(method.getName().equals("equals")
400-
&& proxy instanceof StoredNodeIdentity
401-
&& args.length == 1 && args[0] instanceof StoredNodeIdentity) {
402-
final StoredNodeIdentity ni1 = ((StoredNodeIdentity) proxy);
403-
final StoredNodeIdentity ni2 = ((StoredNodeIdentity) args[0]);
400+
&& proxy instanceof StoredNodeIdentity ni1
401+
&& args.length == 1 && args[0] instanceof StoredNodeIdentity ni2) {
404402

405403
final Optional<Boolean> niEquals = ni1.getNodeId().flatMap(n1id -> ni2.getNodeId().map(n1id::equals));
406404
if (niEquals.isPresent()) {
407405
domResult = niEquals.get();
408406
}
409407
} else if(method.getName().equals("equals")
410-
&& proxy instanceof MemtreeNodeIdentity
411-
&& args.length == 1 && args[0] instanceof MemtreeNodeIdentity) {
412-
final MemtreeNodeIdentity ni1 = ((MemtreeNodeIdentity) proxy);
413-
final MemtreeNodeIdentity ni2 = ((MemtreeNodeIdentity) args[0]);
408+
&& proxy instanceof MemtreeNodeIdentity ni1
409+
&& args.length == 1 && args[0] instanceof MemtreeNodeIdentity ni2) {
414410

415-
final Optional<Boolean> niEquals = ni1.getNodeId().flatMap(n1id -> ni2.getNodeId().map(n2id -> n1id._1 == n2id._1 && n1id._2 == n2id._2 && n1id._3 == n2id._3));
411+
final Optional<Boolean> niEquals = ni1.getNodeId().flatMap(n1id -> ni2.getNodeId().map(n2id -> n1id._1 == n2id._1 && n1id._2 == n2id._2 && n1id._3 == n2id._3));
416412
if (niEquals.isPresent()) {
417413
domResult = niEquals.get();
418414
}

exist-core/src/main/java/org/exist/xquery/LocationStep.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException
287287
// case Constants.DESCENDANT_AXIS:
288288
case Constants.DESCENDANT_SELF_AXIS:
289289
final Expression contextStep = contextInfo.getContextStep();
290-
if (contextStep instanceof LocationStep) {
291-
final LocationStep cStep = (LocationStep) contextStep;
290+
if (contextStep instanceof LocationStep cStep) {
292291

293292
if ((
294293
cStep.getTest().getType() == Type.ATTRIBUTE ||

exist-core/src/main/java/org/exist/xquery/PerformanceStatsImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,10 @@ public void recordAll(final PerformanceStats otherPerformanceStats) {
295295
return;
296296
}
297297

298-
if (!(otherPerformanceStats instanceof PerformanceStatsImpl)) {
298+
if (!(otherPerformanceStats instanceof PerformanceStatsImpl other)) {
299299
throw new IllegalArgumentException("Argument must be of type: " + getClass().getName());
300300
}
301301

302-
final PerformanceStatsImpl other = (PerformanceStatsImpl) otherPerformanceStats;
303-
304302
for (final QueryStats otherQueryStats : other.queries.values()) {
305303
final QueryStats copy = QueryStats.copy(otherQueryStats);
306304
@Nullable final QueryStats mine = queries.get(copy.source);

0 commit comments

Comments
 (0)