Skip to content

Commit 45dacb5

Browse files
committed
[refactor] Java14 - enhanced switch
1 parent 1f7b876 commit 45dacb5

File tree

79 files changed

+923
-1818
lines changed

Some content is hidden

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

79 files changed

+923
-1818
lines changed

exist-core/src/main/java/org/exist/client/ClientFrame.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,20 +1635,15 @@ public int getRowCount() {
16351635
public Object getValueAt(final int rowIndex, final int columnIndex) {
16361636
if (getRowCount() > 0) {
16371637
final ResourceDescriptor row = getRow(rowIndex);
1638-
switch (columnIndex) {
1639-
case 0:
1640-
return row.getName().toString();
1641-
case 1:
1642-
return DATE_TIME_FORMATTER.format(row.getInstant());
1643-
case 2:
1644-
return row.getOwner();
1645-
case 3:
1646-
return row.getGroup();
1647-
case 4:
1648-
return row.getPermissionsDescription();
1649-
default:
1650-
throw new RuntimeException(Messages.getString("ClientFrame.212")); //$NON-NLS-1$
1651-
}
1638+
//$NON-NLS-1$
1639+
return switch (columnIndex) {
1640+
case 0 -> row.getName().toString();
1641+
case 1 -> DATE_TIME_FORMATTER.format(row.getInstant());
1642+
case 2 -> row.getOwner();
1643+
case 3 -> row.getGroup();
1644+
case 4 -> row.getPermissionsDescription();
1645+
default -> throw new RuntimeException(Messages.getString("ClientFrame.212")); //$NON-NLS-1$
1646+
};
16521647
}
16531648
return "";
16541649
}

exist-core/src/main/java/org/exist/client/IndexDialog.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,14 @@ public int getRowCount()
467467
*/
468468
public Object getValueAt(int rowIndex, int columnIndex)
469469
{
470-
switch (columnIndex)
471-
{
472-
case 0 :
473-
return cx.getRangeIndex(rowIndex).getType();
474-
case 1 : /* XPath */
475-
return cx.getRangeIndex(rowIndex).getXPath();
476-
case 2 : /* xsType */
477-
return cx.getRangeIndex(rowIndex).getxsType();
478-
default :
479-
return null;
480-
}
470+
return switch (columnIndex) {
471+
case 0 -> cx.getRangeIndex(rowIndex).getType();
472+
case 1 -> /* XPath */
473+
cx.getRangeIndex(rowIndex).getXPath();
474+
case 2 -> /* xsType */
475+
cx.getRangeIndex(rowIndex).getxsType();
476+
default -> null;
477+
};
481478
}
482479
}
483480
}

exist-core/src/main/java/org/exist/client/NewResourceDialog.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,10 @@ private void setupComponents() {
124124
cmbResourceTypes.addActionListener(e -> {
125125
final Object src = e.getSource();
126126
if(src.equals(cmbResourceTypes)) {
127-
final boolean visible1;
128-
switch((ResourceType)cmbResourceTypes.getSelectedItem()) {
129-
case XQUERY_LIBRARY:
130-
visible1 = true;
131-
break;
132-
133-
default:
134-
visible1 = false;
135-
}
127+
final boolean visible1 = switch ((ResourceType) cmbResourceTypes.getSelectedItem()) {
128+
case XQUERY_LIBRARY -> true;
129+
default -> false;
130+
};
136131

137132
lblLibModule.setVisible(visible1);
138133
panLibModule.setVisible(visible1);

exist-core/src/main/java/org/exist/client/TriggersDialog.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,11 @@ public int getRowCount() {
363363
*/
364364
@Override
365365
public Object getValueAt(final int rowIndex, final int columnIndex) {
366-
switch(columnIndex) {
366+
return switch (columnIndex) {
367367
/* class */
368-
case 0:
369-
return cx.getTrigger(rowIndex).getTriggerClass();
370-
371-
default :
372-
return null;
373-
}
368+
case 0 -> cx.getTrigger(rowIndex).getTriggerClass();
369+
default -> null;
370+
};
374371
}
375372
}
376373
}

exist-core/src/main/java/org/exist/client/tristatecheckbox/TristateState.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,10 @@ public static TristateState fromBoolean(@Nullable final Boolean state) {
5858
}
5959

6060
public static @Nullable Boolean toBoolean(final TristateState state) {
61-
switch (state) {
62-
case DESELECTED:
63-
return false;
64-
case SELECTED:
65-
return true;
66-
67-
case INDETERMINATE:
68-
default:
69-
return null;
70-
}
61+
return switch (state) {
62+
case DESELECTED -> false;
63+
case SELECTED -> true;
64+
default -> null;
65+
};
7166
}
7267
}

exist-core/src/main/java/org/exist/collections/MutableCollection.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -556,21 +556,11 @@ private void addDocumentsToSet(final DBBroker broker, final Iterator<DocumentImp
556556
while(documentIterator.hasNext()) {
557557
final DocumentImpl doc = documentIterator.next();
558558
if(doc.getPermissions().validate(broker.getCurrentSubject(), requiredPermission)) {
559-
final ManagedDocumentLock documentLock;
560-
switch(lockType) {
561-
case WRITE_LOCK:
562-
documentLock = lockManager.acquireDocumentWriteLock(doc.getURI());
563-
break;
564-
565-
case READ_LOCK:
566-
documentLock = lockManager.acquireDocumentReadLock(doc.getURI());
567-
break;
568-
569-
case NO_LOCK:
570-
default:
571-
documentLock = ManagedSingleLockDocumentLock.notLocked(doc.getURI());
572-
break;
573-
}
559+
final ManagedDocumentLock documentLock = switch (lockType) {
560+
case WRITE_LOCK -> lockManager.acquireDocumentWriteLock(doc.getURI());
561+
case READ_LOCK -> lockManager.acquireDocumentReadLock(doc.getURI());
562+
default -> ManagedSingleLockDocumentLock.notLocked(doc.getURI());
563+
};
574564

575565
docs.add(doc);
576566
lockMap.add(new LockedDocument(documentLock, doc));
@@ -696,23 +686,21 @@ public LockedDocument getDocumentWithLock(final DBBroker broker, final XmldbURI
696686

697687
// lock the document
698688
final ManagedDocumentLock documentLock;
699-
final Runnable unlockFn; // we unlock on error, or if there is no Collection
700-
switch (lockMode) {
701-
case WRITE_LOCK:
689+
final Runnable unlockFn = switch (lockMode) {
690+
case WRITE_LOCK -> {
702691
documentLock = lockManager.acquireDocumentWriteLock(getURI().append(name.lastSegment()));
703-
unlockFn = documentLock::close;
704-
break;
705-
706-
case READ_LOCK:
692+
yield documentLock::close;
693+
}
694+
case READ_LOCK -> {
707695
documentLock = lockManager.acquireDocumentReadLock(getURI().append(name.lastSegment()));
708-
unlockFn = documentLock::close;
709-
break;
710-
711-
case NO_LOCK:
712-
default:
696+
yield documentLock::close;
697+
}
698+
default -> {
713699
documentLock = ManagedSingleLockDocumentLock.notLocked(getURI().append(name.lastSegment()));
714-
unlockFn = () -> {};
715-
}
700+
yield () -> {
701+
};
702+
}
703+
}; // we unlock on error, or if there is no Collection
716704

717705

718706
final DocumentImpl doc = documents.get(name.lastSegmentString());

exist-core/src/main/java/org/exist/collections/triggers/TriggerPhase.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ public enum TriggerPhase {
2727

2828
@Deprecated
2929
public String legacyPhaseName() {
30-
switch(this) {
31-
case BEFORE:
32-
return "prepare";
33-
case AFTER:
34-
return "finish";
35-
default:
36-
throw new IllegalStateException();
37-
}
30+
return switch (this) {
31+
case BEFORE -> "prepare";
32+
case AFTER -> "finish";
33+
default -> throw new IllegalStateException();
34+
};
3835
}
3936
}

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

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,10 @@ public Integer migrateId(final Integer oldId) {
506506
* matching the provided name
507507
*/
508508
public Principal getPrincipal(final SecurityManager sm, final String name) {
509-
switch(this) {
510-
case ACCOUNT:
511-
return sm.getAccount(name);
512-
case GROUP:
513-
return sm.getGroup(name);
514-
}
515-
return null;
509+
return switch (this) {
510+
case ACCOUNT -> sm.getAccount(name);
511+
case GROUP -> sm.getGroup(name);
512+
};
516513
}
517514

518515
/**
@@ -523,13 +520,10 @@ public Principal getPrincipal(final SecurityManager sm, final String name) {
523520
* @return true when exist
524521
*/
525522
public boolean hasPrincipal(final SecurityManager sm, final String name) {
526-
switch (this) {
527-
case ACCOUNT:
528-
return sm.hasAccount(name);
529-
case GROUP:
530-
return sm.hasGroup(name);
531-
}
532-
return false;
523+
return switch (this) {
524+
case ACCOUNT -> sm.hasAccount(name);
525+
case GROUP -> sm.hasGroup(name);
526+
};
533527
}
534528

535529
/**
@@ -542,13 +536,10 @@ public boolean hasPrincipal(final SecurityManager sm, final String name) {
542536
* matching the provided id
543537
*/
544538
public Principal getPrincipal(final SecurityManager sm, final int id) {
545-
switch(this) {
546-
case ACCOUNT:
547-
return sm.getAccount(id);
548-
case GROUP:
549-
return sm.getGroup(id);
550-
}
551-
return null;
539+
return switch (this) {
540+
case ACCOUNT -> sm.getAccount(id);
541+
case GROUP -> sm.getGroup(id);
542+
};
552543
}
553544

554545
/**
@@ -559,13 +550,10 @@ public Principal getPrincipal(final SecurityManager sm, final int id) {
559550
* @return true when exist
560551
*/
561552
public boolean hasPrincipal(final SecurityManager sm, final int id) {
562-
switch(this) {
563-
case ACCOUNT:
564-
return sm.hasUser(id);
565-
case GROUP:
566-
return sm.hasGroup(id);
567-
}
568-
return false;
553+
return switch (this) {
554+
case ACCOUNT -> sm.hasUser(id);
555+
case GROUP -> sm.hasGroup(id);
556+
};
569557
}
570558

571559
public void preAllocateId(final SecurityManager sm, final PreAllocatedIdReceiver receiver) throws PermissionDeniedException, EXistException {

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,11 @@ public Boolean getPropertyBoolean(final String name) {
284284
if(value == null) {
285285
return null;
286286
}
287-
switch(value.toLowerCase()) {
288-
case "yes":
289-
case "true":
290-
return true;
291-
292-
case "no":
293-
case "false":
294-
return false;
295-
296-
default:
297-
return null;
298-
}
287+
return switch (value.toLowerCase()) {
288+
case "yes", "true" -> true;
289+
case "no", "false" -> false;
290+
default -> null;
291+
};
299292
}
300293

301294
public Boolean getPropertyBoolean(String name, boolean defaultValue) {

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -519,29 +519,15 @@ public NodeImpl getNode(final int nodeNum) throws DOMException {
519519
if(nodeNum >= size) {
520520
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "node not found");
521521
}
522-
final NodeImpl node;
523-
switch(nodeKind[nodeNum]) {
524-
case Node.ELEMENT_NODE:
525-
node = new ElementImpl(getExpression(), this, nodeNum);
526-
break;
527-
case Node.TEXT_NODE:
528-
node = new TextImpl(getExpression(), this, nodeNum);
529-
break;
530-
case Node.COMMENT_NODE:
531-
node = new CommentImpl(getExpression(), this, nodeNum);
532-
break;
533-
case Node.PROCESSING_INSTRUCTION_NODE:
534-
node = new ProcessingInstructionImpl(getExpression(), this, nodeNum);
535-
break;
536-
case Node.CDATA_SECTION_NODE:
537-
node = new CDATASectionImpl(getExpression(), this, nodeNum);
538-
break;
539-
case NodeImpl.REFERENCE_NODE:
540-
node = new ReferenceNode(getExpression(), this, nodeNum);
541-
break;
542-
default:
543-
throw new DOMException(DOMException.NOT_FOUND_ERR, "node not found");
544-
}
522+
final NodeImpl node = switch (nodeKind[nodeNum]) {
523+
case Node.ELEMENT_NODE -> new ElementImpl(getExpression(), this, nodeNum);
524+
case Node.TEXT_NODE -> new TextImpl(getExpression(), this, nodeNum);
525+
case Node.COMMENT_NODE -> new CommentImpl(getExpression(), this, nodeNum);
526+
case Node.PROCESSING_INSTRUCTION_NODE -> new ProcessingInstructionImpl(getExpression(), this, nodeNum);
527+
case Node.CDATA_SECTION_NODE -> new CDATASectionImpl(getExpression(), this, nodeNum);
528+
case NodeImpl.REFERENCE_NODE -> new ReferenceNode(getExpression(), this, nodeNum);
529+
default -> throw new DOMException(DOMException.NOT_FOUND_ERR, "node not found");
530+
};
545531
return node;
546532
}
547533

0 commit comments

Comments
 (0)