Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit b66be1b

Browse files
authored
Code cleanup and linting (#141)
* Various cleanup to - remove unused imports - use addAll() instead of adding items in a loop - use try-with-resources for closeable objects - use contains() instead of indexOf() * Various cleanup to - remove unused imports - use addAll() instead of adding items in a loop - use try-with-resources for closeable objects - use contains() instead of indexOf() * use try-with-resources, session is closeable
1 parent c79e56a commit b66be1b

File tree

9 files changed

+19
-41
lines changed

9 files changed

+19
-41
lines changed

src/main/java/com/marklogic/client/ext/DatabaseClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public DatabaseClientConfig(String host, int port, String username, String passw
4747

4848
@Override
4949
public String toString() {
50-
return String.format("[%s@%s:%d]", username, host, port, username);
50+
return String.format("[%s@%s:%d]", username, host, port);
5151
}
5252

5353
public String getHost() {

src/main/java/com/marklogic/client/ext/batch/DefaultBatchHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public void handleBatch(DatabaseClient client, List<? extends DocumentWriteOpera
3535
}
3636

3737
DocumentWriteSet set = mgr.newWriteSet();
38-
for (DocumentWriteOperation item : items) {
39-
set.add(item);
40-
}
38+
set.addAll(items);
4139

4240
int count = set.size();
4341
String connectionInfo = format("port: %d", client.getPort());

src/main/java/com/marklogic/client/ext/file/DefaultDocumentFormatGetter.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.core.io.Resource;
66

77
import java.util.ArrayList;
8+
import java.util.Arrays;
89
import java.util.List;
910

1011
/**
@@ -22,15 +23,9 @@ public class DefaultDocumentFormatGetter implements FormatGetter {
2223
private List<String> jsonExtensions = new ArrayList<>();
2324

2425
public DefaultDocumentFormatGetter() {
25-
for (String ext : DEFAULT_BINARY_EXTENSIONS) {
26-
binaryExtensions.add(ext);
27-
}
28-
for (String ext : DEFAULT_XML_EXTENSIONS) {
29-
xmlExtensions.add(ext);
30-
}
31-
for (String ext : DEFAULT_JSON_EXTENSIONS) {
32-
jsonExtensions.add(ext);
33-
}
26+
binaryExtensions.addAll(Arrays.asList(DEFAULT_BINARY_EXTENSIONS));
27+
xmlExtensions.addAll(Arrays.asList(DEFAULT_XML_EXTENSIONS));
28+
jsonExtensions.addAll(Arrays.asList(DEFAULT_JSON_EXTENSIONS));
3429
}
3530

3631
@Override

src/main/java/com/marklogic/client/ext/file/GenericFileLoader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ protected List<DocumentFileProcessor> buildDocumentFileProcessors() {
213213
processors.add(new TokenReplacerDocumentFileProcessor(tokenReplacer));
214214
}
215215
if (documentFileProcessors != null) {
216-
for (DocumentFileProcessor dfp : documentFileProcessors) {
217-
processors.add(dfp);
218-
}
216+
processors.addAll(documentFileProcessors);
219217
}
220218
return processors;
221219
}

src/main/java/com/marklogic/client/ext/modulesloader/impl/BaseModulesFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected void addAssetDirectories(Modules modules, String baseDir) {
7575
if (!(isRecognized || hasWeirdWarPath)) {
7676
boolean isDir = (resource instanceof FileSystemResource && f.isDirectory());
7777
boolean isUrlResource = (resource instanceof UrlResource);
78-
boolean notInList = dirs.indexOf(resource) < 0;
78+
boolean notInList = !dirs.contains(resource);
7979
if ((isDir || isUrlResource) && notInList) {
8080
dirs.add(resource);
8181
}

src/main/java/com/marklogic/client/ext/modulesloader/impl/DefaultModulesFinder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.marklogic.client.ext.modulesloader.Modules;
44
import com.marklogic.client.ext.modulesloader.ModulesFinder;
55

6-
76
/**
87
* Default implementation that loads all of the different kinds of REST modules.
98
*/

src/main/java/com/marklogic/client/ext/tokenreplacer/FilePropertiesSource.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public Properties getProperties() {
3434
protected Properties loadPropertiesFromFile(File file) {
3535
Properties properties = new Properties();
3636
if (file.exists()) {
37-
FileReader reader = null;
38-
try {
39-
reader = new FileReader(file);
37+
try (FileReader reader = new FileReader(file)) {
4038
if (logger.isDebugEnabled()) {
4139
logger.debug("Loading properties from: " + file.getAbsolutePath());
4240
}
@@ -45,15 +43,8 @@ protected Properties loadPropertiesFromFile(File file) {
4543
logger.warn(
4644
"Unable to load properties from file " + file.getAbsolutePath() + "; cause: " + ex.getMessage(),
4745
ex);
48-
} finally {
49-
if (reader != null) {
50-
try {
51-
reader.close();
52-
} catch (IOException ie) {
53-
// Ignore
54-
}
55-
}
5646
}
47+
// Ignore
5748
}
5849
return properties;
5950
}

src/main/java/com/marklogic/xcc/template/XccTemplate.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,11 @@ public XccTemplate(ContentSource contentSource) {
5656
}
5757

5858
public <T> T execute(XccCallback<T> callback) {
59-
Session session = contentSource.newSession();
60-
try {
61-
return callback.execute(session);
62-
} catch (RequestException re) {
63-
throw new RuntimeException(re);
64-
} finally {
65-
session.close();
66-
}
59+
try (Session session = contentSource.newSession()) {
60+
return callback.execute(session);
61+
} catch (RequestException re) {
62+
throw new RuntimeException(re);
63+
}
6764
}
6865

6966
/**

src/test/java/com/marklogic/client/ext/batch/RestBatchWriterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.nio.file.Paths;
21-
import java.util.Arrays;
21+
import java.util.Collections;
2222
import java.util.List;
2323

2424
import static org.junit.jupiter.api.Assertions.*;
@@ -33,7 +33,7 @@ public void failureTest() {
3333
"/test.xml", null, new StringHandle("<hello>world</hello>asdf"));
3434

3535
writer.initialize();
36-
writer.write(Arrays.asList(op));
36+
writer.write(Collections.singletonList(op));
3737

3838
try {
3939
writer.waitForCompletion();
@@ -53,7 +53,7 @@ public void failureTestWithCustomListener() {
5353
"/test.xml", null, new StringHandle("<hello>world</hello>asdf"));
5454

5555
writer.initialize();
56-
writer.write(Arrays.asList(op));
56+
writer.write(Collections.singletonList(op));
5757
writer.waitForCompletion();
5858

5959
Throwable caughtError = testWriteListener.caughtError;
@@ -78,7 +78,7 @@ public void writeDocumentWithTransform() throws IOException {
7878
writer.setServerTransform(new ServerTransform("simple"));
7979
writer.setContentFormat(Format.XML);
8080
writer.initialize();
81-
writer.write(Arrays.asList(op));
81+
writer.write(Collections.singletonList(op));
8282
writer.waitForCompletion();
8383

8484
client = newClient("Documents");

0 commit comments

Comments
 (0)