Skip to content

Commit 2909a75

Browse files
authored
Merge pull request #3178 from dizzzz/feature/misc_code_improvements
Misc code improvements
2 parents b0a7fc1 + 4a1f0ce commit 2909a75

File tree

231 files changed

+1196
-1399
lines changed

Some content is hidden

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

231 files changed

+1196
-1399
lines changed

exist-core/src/main/java/org/exist/BTreeTest.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public BTreeTest() {
2828

2929
BrokerPool.configure(1, 5, config);
3030
pool = BrokerPool.getInstance();
31-
} catch (DatabaseConfigurationException e) {
32-
e.printStackTrace();
33-
} catch (EXistException e) {
31+
} catch (DatabaseConfigurationException | EXistException e) {
3432
e.printStackTrace();
3533
}
3634
}
@@ -41,9 +39,7 @@ public void shutdown() {
4139

4240
public void create(int count) throws DBException, IOException {
4341
FileUtils.deleteQuietly(file);
44-
BTree btree = null;
45-
try {
46-
btree = new BTree(pool, BTREE_TEST_FILE_ID, BTREE_TEST_FILE_VERSION, false, pool.getCacheManager(), file);
42+
try (BTree btree = new BTree(pool, BTREE_TEST_FILE_ID, BTREE_TEST_FILE_VERSION, false, pool.getCacheManager(), file)) {
4743
btree.create((short) -1);
4844

4945
String prefixStr = "KEY";
@@ -53,14 +49,10 @@ public void create(int count) throws DBException, IOException {
5349
}
5450
btree.flush();
5551

56-
try(final OutputStreamWriter writer = new OutputStreamWriter(System.out)) {
52+
try (final OutputStreamWriter writer = new OutputStreamWriter(System.out)) {
5753
btree.dump(writer);
5854
writer.flush();
5955
}
60-
} finally {
61-
if (btree != null) {
62-
btree.close();
63-
}
6456
}
6557
}
6658

@@ -125,11 +117,7 @@ public static void main(String[] args) {
125117
} else if ("rebuild".equals(command)) {
126118
test.rebuild();
127119
}
128-
} catch (DBException e) {
129-
e.printStackTrace();
130-
} catch (IOException e) {
131-
e.printStackTrace();
132-
} catch (TerminatedException e) {
120+
} catch (DBException | TerminatedException | IOException e) {
133121
e.printStackTrace();
134122
} finally {
135123
test.shutdown();

exist-core/src/main/java/org/exist/Indexer.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,22 @@ public Indexer(final DBBroker broker, final Txn transaction)
164164
final String suppressWS = (String) config
165165
.getProperty(PROPERTY_SUPPRESS_WHITESPACE);
166166
if (suppressWS != null) {
167-
if ("leading".equals(suppressWS)) {
168-
normalize = XMLString.SUPPRESS_LEADING_WS;
169-
} else if ("trailing".equals(suppressWS)) {
170-
normalize = XMLString.SUPPRESS_TRAILING_WS;
171-
} else if ("none".equals(suppressWS)) {
172-
normalize = 0;
167+
switch (suppressWS) {
168+
case "leading":
169+
normalize = XMLString.SUPPRESS_LEADING_WS;
170+
break;
171+
case "trailing":
172+
normalize = XMLString.SUPPRESS_TRAILING_WS;
173+
break;
174+
case "none":
175+
normalize = 0;
176+
break;
173177
}
174178
}
175179
Boolean temp;
176180
if ((temp = (Boolean) config
177181
.getProperty(PROPERTY_PRESERVE_WS_MIXED_CONTENT)) != null) {
178-
preserveWSmixed = temp.booleanValue();
182+
preserveWSmixed = temp;
179183
}
180184
}
181185

exist-core/src/main/java/org/exist/backup/Restore.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ public void restore(final DBBroker broker, @Nullable final Txn transaction, fina
7171

7272
// count all files
7373
long totalNrOfFiles = 0;
74-
Iterator<BackupDescriptor> bdIterator = descriptors.iterator();
75-
while(bdIterator.hasNext()){
76-
totalNrOfFiles += bdIterator.next().getNumberOfFiles();
74+
for (BackupDescriptor backupDescriptor : descriptors) {
75+
totalNrOfFiles += backupDescriptor.getNumberOfFiles();
7776
}
7877

7978
// continue restore

exist-core/src/main/java/org/exist/backup/restore/RestoreHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private DeferredPermission restoreCollectionEntry(final Attributes atts) throws
201201
}
202202

203203
if (version >= BLOB_STORE_VERSION) {
204-
this.deduplicateBlobs = Boolean.valueOf(atts.getValue("deduplicate-blobs"));
204+
this.deduplicateBlobs = Boolean.parseBoolean(atts.getValue("deduplicate-blobs"));
205205
} else {
206206
this.deduplicateBlobs = false;
207207
}

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ private void moveAction(final ActionEvent ev) {
767767
//get an array of collection paths
768768
try {
769769
final Collection root = client.getCollection(XmldbURI.ROOT_COLLECTION);
770-
final List<PrettyXmldbURI> alCollections = getCollections(root, new ArrayList<PrettyXmldbURI>());
770+
final List<PrettyXmldbURI> alCollections = getCollections(root, new ArrayList<>());
771771
collections = new PrettyXmldbURI[alCollections.size()];
772772
alCollections.toArray(collections);
773773
} catch (final XMLDBException e) {
@@ -786,12 +786,12 @@ private void moveAction(final ActionEvent ev) {
786786
try {
787787
final EXistCollectionManagementService service = (EXistCollectionManagementService)
788788
client.current.getService("CollectionManagementService", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$
789-
for (int i = 0; i < res.length; i++) {
790-
setStatus(Messages.getString("ClientFrame.115") + res[i].getName() + Messages.getString("ClientFrame.116") + destinationPath + Messages.getString("ClientFrame.117")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
791-
if (res[i].isCollection()) {
792-
service.move(res[i].getName(), destinationPath, null);
789+
for (ResourceDescriptor re : res) {
790+
setStatus(Messages.getString("ClientFrame.115") + re.getName() + Messages.getString("ClientFrame.116") + destinationPath + Messages.getString("ClientFrame.117")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
791+
if (re.isCollection()) {
792+
service.move(re.getName(), destinationPath, null);
793793
} else {
794-
service.moveResource(res[i].getName(), destinationPath, null);
794+
service.moveResource(re.getName(), destinationPath, null);
795795
}
796796
}
797797
client.reloadCollection();
@@ -828,12 +828,12 @@ private void renameAction(final ActionEvent ev) {
828828
try {
829829
final EXistCollectionManagementService service = (EXistCollectionManagementService)
830830
client.current.getService("CollectionManagementService", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$
831-
for (int i = 0; i < res.length; i++) {
832-
setStatus(Messages.getString("ClientFrame.124") + res[i].getName() + Messages.getString("ClientFrame.125") + destinationFilename + Messages.getString("ClientFrame.126")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
833-
if (res[i].isCollection()) {
834-
service.move(res[i].getName(), null, destinationFilename);
831+
for (ResourceDescriptor re : res) {
832+
setStatus(Messages.getString("ClientFrame.124") + re.getName() + Messages.getString("ClientFrame.125") + destinationFilename + Messages.getString("ClientFrame.126")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
833+
if (re.isCollection()) {
834+
service.move(re.getName(), null, destinationFilename);
835835
} else {
836-
service.moveResource(res[i].getName(), null, destinationFilename);
836+
service.moveResource(re.getName(), null, destinationFilename);
837837
}
838838
}
839839
client.reloadCollection();
@@ -853,7 +853,7 @@ private void copyAction(final ActionEvent ev) {
853853
//get an array of collection paths
854854
try {
855855
final Collection root = client.getCollection(XmldbURI.ROOT_COLLECTION);
856-
final List<PrettyXmldbURI> alCollections = getCollections(root, new ArrayList<PrettyXmldbURI>());
856+
final List<PrettyXmldbURI> alCollections = getCollections(root, new ArrayList<>());
857857
collections = new PrettyXmldbURI[alCollections.size()];
858858
alCollections.toArray(collections);
859859
} catch (final XMLDBException e) {
@@ -873,7 +873,7 @@ private void copyAction(final ActionEvent ev) {
873873
try {
874874
final EXistCollectionManagementService service = (EXistCollectionManagementService)
875875
client.current.getService("CollectionManagementService", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$
876-
for (int i = 0; i < res.length; i++) {
876+
for (ResourceDescriptor re : res) {
877877

878878
//TODO
879879
//what happens if the source and destination paths are the same?
@@ -884,11 +884,11 @@ private void copyAction(final ActionEvent ev) {
884884
//
885885
//Its too late and brain hurts - deliriumsky
886886

887-
setStatus(Messages.getString("ClientFrame.132") + res[i].getName() + Messages.getString("ClientFrame.133") + destinationPath + Messages.getString("ClientFrame.134")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
888-
if (res[i].isCollection()) {
889-
service.copy(res[i].getName(), destinationPath, null);
887+
setStatus(Messages.getString("ClientFrame.132") + re.getName() + Messages.getString("ClientFrame.133") + destinationPath + Messages.getString("ClientFrame.134")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
888+
if (re.isCollection()) {
889+
service.copy(re.getName(), destinationPath, null);
890890
} else {
891-
service.copyResource(res[i].getName(), destinationPath, null);
891+
service.copyResource(re.getName(), destinationPath, null);
892892
}
893893
}
894894
client.reloadCollection();
@@ -904,9 +904,9 @@ private ArrayList<PrettyXmldbURI> getCollections(final Collection root, final Ar
904904
collectionsList.add(new PrettyXmldbURI(XmldbURI.create(root.getName())));
905905
final String[] childCollections = root.listChildCollections();
906906
Collection child = null;
907-
for (int i = 0; i < childCollections.length; i++) {
907+
for (String childCollection : childCollections) {
908908
try {
909-
child = root.getChildCollection(childCollections[i]);
909+
child = root.getChildCollection(childCollection);
910910
} catch (final XMLDBException xmldbe) {
911911
if (xmldbe.getCause() instanceof PermissionDeniedException) {
912912
continue;
@@ -955,8 +955,7 @@ private void reindexAction(final ActionEvent ev) {
955955
try {
956956
service = (IndexQueryService)
957957
client.current.getService("IndexQueryService", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$
958-
for (int i = 0; i < collections.length; i++) {
959-
final ResourceDescriptor next = collections[i];
958+
for (final ResourceDescriptor next : collections) {
960959
setStatus(Messages.getString("ClientFrame.142") + next.getName() + Messages.getString("ClientFrame.143")); //$NON-NLS-1$ //$NON-NLS-2$
961960
service.reindexCollection(next.getName());
962961
}
@@ -1305,10 +1304,10 @@ private void setPermAction(final ActionEvent ev) throws PermissionDeniedExceptio
13051304
permAider = PermissionAiderFactory.getPermission(account.getName(), account.getPrimaryGroup(), Permission.DEFAULT_RESOURCE_PERM); //$NON-NLS-1$ //$NON-NLS-2$
13061305
}
13071306

1308-
final List<ResourceDescriptor> selected = new ArrayList<ResourceDescriptor>();
1307+
final List<ResourceDescriptor> selected = new ArrayList<>();
13091308
final int rows[] = fileman.getSelectedRows();
1310-
for (int i = 0; i < rows.length; i++) {
1311-
selected.add(resources.getRow(fileman.convertRowIndexToModel(rows[i])));
1309+
for (int row : rows) {
1310+
selected.add(resources.getRow(fileman.convertRowIndexToModel(row)));
13121311
}
13131312

13141313
final EditPropertiesDialog editPropertiesDialog = new EditPropertiesDialog(service, client.getProperties().getProperty(InteractiveClient.USER), collection, name, mimeType, created, modified, size, messageDigest, permAider, selected);
@@ -1491,7 +1490,7 @@ static class ResourceTableModel extends AbstractTableModel {
14911490
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
14921491

14931492
public void setData(final List<ResourceDescriptor> rows) {
1494-
Collections.sort(rows, new ResourceComparator());
1493+
rows.sort(new ResourceComparator());
14951494
this.rows = rows;
14961495
fireTableDataChanged();
14971496
}
@@ -1688,7 +1687,7 @@ public static int showErrorMessageQuery(final String message, final Throwable t)
16881687
if (result == null) {
16891688
return 2;
16901689
}
1691-
return ((Integer) optionPane.getValue()).intValue();
1690+
return (Integer) optionPane.getValue();
16921691
}
16931692

16941693
/*

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
package org.exist.client;
2121

2222
import java.io.IOException;
23-
import java.util.ArrayList;
24-
import java.util.Enumeration;
25-
import java.util.LinkedHashMap;
26-
import java.util.List;
27-
import java.util.Map;
28-
import java.util.Properties;
23+
import java.util.*;
2924
import javax.xml.parsers.DocumentBuilder;
3025
import javax.xml.parsers.DocumentBuilderFactory;
3126
import javax.xml.parsers.ParserConfigurationException;
@@ -378,7 +373,7 @@ private LinkedHashMap<String, String> getCustomNamespaces(Element xconf)
378373
final Node a = attrs.item(i);
379374
if(a.getNodeName().startsWith("xmlns:"))
380375
{
381-
final String namespaceLocalName = a.getNodeName().substring(a.getNodeName().indexOf(":")+1);
376+
final String namespaceLocalName = a.getNodeName().substring(a.getNodeName().indexOf(':')+1);
382377
namespaces.put(namespaceLocalName, a.getNodeValue());
383378
}
384379
}
@@ -395,7 +390,7 @@ private RangeIndex[] getRangeIndexes(Element xconf)
395390
final NodeList nlRangeIndexes = xconf.getElementsByTagName("create");
396391
if(nlRangeIndexes.getLength() > 0)
397392
{
398-
final List<RangeIndex> rl = new ArrayList<RangeIndex>();
393+
final List<RangeIndex> rl = new ArrayList<>();
399394
for(int i = 0; i < nlRangeIndexes.getLength(); i++)
400395
{
401396
final Element rangeIndex = (Element)nlRangeIndexes.item(i);
@@ -674,10 +669,10 @@ protected String toXMLString()
674669
{
675670
if(parameters.size() > 0)
676671
{
677-
final Enumeration pKeys = parameters.keys();
678-
while(pKeys.hasMoreElements())
672+
Iterator iterator = parameters.keySet().iterator();
673+
while(iterator.hasNext())
679674
{
680-
final String name = (String)pKeys.nextElement();
675+
final String name = (String) iterator.next();
681676
final String value = parameters.getProperty(name);
682677

683678
trigger.append("<parameter name=\"");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class ConnectionDialog extends javax.swing.JDialog implements DialogWithR
5252
private final boolean disableEmbeddedConnectionType;
5353
private Path config;
5454

55-
private final List<DialogCompleteWithResponse<Connection>> dialogCompleteWithResponseCallbacks = new ArrayList<DialogCompleteWithResponse<Connection>>();
55+
private final List<DialogCompleteWithResponse<Connection>> dialogCompleteWithResponseCallbacks = new ArrayList<>();
5656

5757
private enum ConnectionType {
5858
Remote,
@@ -104,7 +104,7 @@ private DefaultListModel getFavouritesModel() {
104104

105105
private void storeFavourites(final ListModel model) {
106106

107-
final List<FavouriteConnection> favourites = new ArrayList<FavouriteConnection>();
107+
final List<FavouriteConnection> favourites = new ArrayList<>();
108108

109109
// Write a node for each item in model.
110110
for (int i = 0; i < model.getSize(); i++) {
@@ -577,7 +577,7 @@ private void lstFavouritesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIR
577577
tpConnectionType.setSelectedIndex(cmbConnectionType.getSelectedIndex());
578578

579579
txtServerUri.setText(favourite.getUri());
580-
chkSsl.setSelected(Boolean.valueOf(favourite.isSsl()));
580+
chkSsl.setSelected(favourite.isSsl());
581581

582582
txtConfiguration.setText(favourite.getConfiguration());
583583

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static List<FavouriteConnection> load() {
9191
}
9292

9393
// Copy for each connection data into Favourite array
94-
final List<FavouriteConnection> favourites = new ArrayList<FavouriteConnection>();
94+
final List<FavouriteConnection> favourites = new ArrayList<>();
9595

9696
for(final String favouriteNodeName : favouriteNodeNames) {
9797
final Preferences node = favouritesNode.node(favouriteNodeName);

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ private void setupComponents()
124124
{
125125
final Collection root = client.getCollection(XmldbURI.ROOT_COLLECTION);
126126
final ArrayList alAllCollections = getCollections(root, new ArrayList());
127-
for(int i = 0; i < alAllCollections.size(); i++)
128-
{
129-
//TODO : use XmldbURIs !
130-
if(alAllCollections.get(i).toString().contains(CollectionConfigurationManager.CONFIG_COLLECTION))
131-
{
132-
alCollections.add(alAllCollections.get(i));
133-
}
127+
for (Object alAllCollection : alAllCollections) {
128+
//TODO : use XmldbURIs !
129+
if (alAllCollection.toString().contains(CollectionConfigurationManager.CONFIG_COLLECTION)) {
130+
alCollections.add(alAllCollection);
131+
}
134132
}
135133
}
136134
catch (final XMLDBException e)
@@ -278,9 +276,8 @@ private void saveChanges(boolean ask)
278276

279277
ArrayList subCollections = getCollections(client.getCollection((String)cmbCollections.getSelectedItem()), new ArrayList());
280278

281-
for(int i = 0; i < subCollections.size(); i++)
282-
{
283-
service.reindexCollection(((ResourceDescriptor)subCollections.get(i)).getName());
279+
for (Object subCollection : subCollections) {
280+
service.reindexCollection(((ResourceDescriptor) subCollection).getName());
284281
}
285282

286283
//reindex done

0 commit comments

Comments
 (0)