Skip to content

Commit 1f7b876

Browse files
committed
[refactor] Java8 - use lamda's
1 parent af8182e commit 1f7b876

File tree

9 files changed

+38
-71
lines changed

9 files changed

+38
-71
lines changed

exist-core/src/main/java/org/exist/xquery/functions/request/GetData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Sequence eval(final Sequence[] args, @Nonnull final RequestWrapper reques
8282
if (request.getContentLength() <= 0) {
8383
final boolean isChunkedTransferEncoding = Optional.ofNullable(request.getHeader("Transfer-Encoding"))
8484
.filter(str -> !str.trim().isEmpty())
85-
.map(str -> "chunked".equals(str)).orElse(false);
85+
.map("chunked"::equals).orElse(false);
8686

8787
if (!isChunkedTransferEncoding) {
8888
return Sequence.EMPTY_SEQUENCE;

exist-core/src/test/java/org/exist/dom/persistent/NodeTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,10 @@ public void visitor() throws EXistException, LockException, PermissionDeniedExce
218218
try(final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
219219
final LockedDocument lockedDoc = root.getDocumentWithLock(broker, XmldbURI.create("test.xml"),LockMode.READ_LOCK)) {
220220
StoredNode rootNode = (StoredNode) lockedDoc.getDocument().getDocumentElement();
221-
NodeVisitor visitor = new NodeVisitor() {
222-
@Override
223-
public boolean visit(IStoredNode node) {
224-
node.getNodeId();
225-
node.getNodeName();
226-
return true;
227-
};
221+
NodeVisitor visitor = node -> {
222+
node.getNodeId();
223+
node.getNodeName();
224+
return true;
228225
};
229226
rootNode.accept(visitor);
230227
}

exist-core/src/test/java/org/exist/storage/FluentBrokerAPITest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public void all() throws PermissionDeniedException, EXistException, LockExceptio
7878

7979
ctrl.replay();
8080

81-
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
81+
final Function<Collection, Long> collectionOp = Collection::getCreated;
8282
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
83-
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
83+
final Function<DocumentImpl, Long> documentOp = DocumentImpl::getLastModified;
8484

8585
final Tuple3<Long, String, Long> result = FluentBrokerAPI.builder(mockBrokerPool)
8686
.withCollection(TEST_COLLECTION_URI, READ_LOCK)
@@ -118,7 +118,7 @@ public void collectionOnly() throws PermissionDeniedException, EXistException, L
118118

119119
ctrl.replay();
120120

121-
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
121+
final Function<Collection, Long> collectionOp = Collection::getCreated;
122122

123123
final long result = FluentBrokerAPI.builder(mockBrokerPool)
124124
.withCollection(TEST_COLLECTION_URI, READ_LOCK)
@@ -196,7 +196,7 @@ public void docOnly() throws PermissionDeniedException, EXistException, LockExce
196196

197197
ctrl.replay();
198198

199-
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
199+
final Function<DocumentImpl, Long> documentOp = DocumentImpl::getLastModified;
200200

201201
final long result = FluentBrokerAPI.builder(mockBrokerPool)
202202
.withCollection(TEST_COLLECTION_URI, READ_LOCK)
@@ -238,7 +238,7 @@ public void collectionThenCollectionAndDoc() throws PermissionDeniedException, E
238238

239239
ctrl.replay();
240240

241-
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
241+
final Function<Collection, Long> collectionOp = Collection::getCreated;
242242
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
243243

244244
final Tuple2<Long, String> result = FluentBrokerAPI.builder(mockBrokerPool)
@@ -282,8 +282,8 @@ public void collectionThenDoc() throws PermissionDeniedException, EXistException
282282

283283
ctrl.replay();
284284

285-
final Function<Collection, Long> collectionOp = collection -> collection.getCreated();
286-
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
285+
final Function<Collection, Long> collectionOp = Collection::getCreated;
286+
final Function<DocumentImpl, Long> documentOp = DocumentImpl::getLastModified;
287287

288288
final Tuple2<Long, Long> result = FluentBrokerAPI.builder(mockBrokerPool)
289289
.withCollection(TEST_COLLECTION_URI, READ_LOCK)
@@ -328,7 +328,7 @@ public void collectionAndDocThenDoc() throws PermissionDeniedException, EXistExc
328328
ctrl.replay();
329329

330330
final BiFunction<Collection, DocumentImpl, String> collectionDocOp = (collection, doc) -> collection.getURI().append(doc.getFileURI()).toString();
331-
final Function<DocumentImpl, Long> documentOp = document -> document.getLastModified();
331+
final Function<DocumentImpl, Long> documentOp = DocumentImpl::getLastModified;
332332

333333
final Tuple2<String, Long> result = FluentBrokerAPI.builder(mockBrokerPool)
334334
.withCollection(TEST_COLLECTION_URI, READ_LOCK)

exist-core/src/test/java/org/exist/storage/RemoveRootCollectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void addDocumentToRoot() throws Exception {
9999
final BrokerPool pool = BrokerPool.getInstance();
100100
final TransactionManager transact = pool.getTransactionManager();
101101
try (final Txn transaction = transact.beginTransaction()) {
102-
broker.storeDocument(transaction, XmldbURI.create("hamlet.xml"), new InputStreamSupplierInputSource(() -> SAMPLES.getHamletSample()), MimeType.XML_TYPE, root);
102+
broker.storeDocument(transaction, XmldbURI.create("hamlet.xml"), new InputStreamSupplierInputSource(SAMPLES::getHamletSample), MimeType.XML_TYPE, root);
103103
transact.commit(transaction);
104104
}
105105
}

exist-core/src/test/java/org/exist/storage/txn/ConcurrentTransactionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void setupDocs() throws EXistException, PermissionDeniedException, IOExce
184184
assertNotNull(test);
185185
broker.saveCollection(transaction, test);
186186

187-
broker.storeDocument(transaction, XmldbURI.create("hamlet.xml"), new InputStreamSupplierInputSource(() -> SAMPLES.getHamletSample()), MimeType.XML_TYPE, test);
187+
broker.storeDocument(transaction, XmldbURI.create("hamlet.xml"), new InputStreamSupplierInputSource(SAMPLES::getHamletSample), MimeType.XML_TYPE, test);
188188

189189
transact.commit(transaction);
190190
}

exist-core/src/test/java/org/exist/util/sorters/PlainArrayChecker.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,18 @@ void check(SortOrder sortOrder, int lo, int hi)
124124
Comparator<Integer> getComparator(SortOrder sortOrder) {
125125
switch (sortOrder) {
126126
case ASCENDING:
127-
return new Comparator<Integer>() {
128-
public int compare(Integer o1, Integer o2) {
129-
return o1.intValue() - o2.intValue();
130-
}
131-
};
127+
return (o1, o2) -> o1.intValue() - o2.intValue();
132128
case DESCENDING:
133-
return new Comparator<Integer>() {
134-
public int compare(Integer o1, Integer o2) {
135-
return o2.intValue() - o1.intValue();
136-
}
137-
};
129+
return (o1, o2) -> o2.intValue() - o1.intValue();
138130
case RANDOM:
139-
return new Comparator<Integer>() {
140-
public int compare(Integer o1, Integer o2) {
141-
return rnd.nextBoolean() ? -1 : 1;
142-
}
143-
};
131+
return (o1, o2) -> rnd.nextBoolean() ? -1 : 1;
144132
case UNSTABLE:
145-
return new Comparator<Integer>() {
146-
public int compare(Integer o1, Integer o2) {
147-
if (o1.intValue() <= o2.intValue())
148-
return (o2.intValue() - o1.intValue()) % 3 - 1;
149-
else
150-
return 1 - (o1.intValue() - o2.intValue()) % 3;
151-
}
152-
};
133+
return (o1, o2) -> {
134+
if (o1.intValue() <= o2.intValue())
135+
return (o2.intValue() - o1.intValue()) % 3 - 1;
136+
else
137+
return 1 - (o1.intValue() - o2.intValue()) % 3;
138+
};
153139
}
154140
return null; // should never happen
155141
}

exist-core/src/test/java/org/exist/xquery/functions/securitymanager/AccountManagementFunctionRemoveAccountTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,22 @@ public class AccountManagementFunctionRemoveAccountTest {
4848
public void cannotDeleteSystemAccount() throws XPathException, PermissionDeniedException, EXistException, AuthenticationException {
4949
final BrokerPool pool = existWebServer.getBrokerPool();
5050
final Subject admin = pool.getSecurityManager().authenticate(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
51-
extractPermissionDenied(() -> {
52-
xqueryRemoveAccount(SecurityManager.SYSTEM, Optional.of(admin));
53-
});
51+
extractPermissionDenied(() -> xqueryRemoveAccount(SecurityManager.SYSTEM, Optional.of(admin)));
5452
}
5553

5654
@Test(expected = PermissionDeniedException.class)
5755
public void cannotDeleteDbaAccount() throws XPathException, PermissionDeniedException, EXistException {
58-
extractPermissionDenied(() -> {
59-
xqueryRemoveAccount(SecurityManager.DBA_USER);
60-
});
56+
extractPermissionDenied(() -> xqueryRemoveAccount(SecurityManager.DBA_USER));
6157
}
6258

6359
@Test(expected = PermissionDeniedException.class)
6460
public void cannotDeleteGuestAccount() throws XPathException, PermissionDeniedException, EXistException {
65-
extractPermissionDenied(() -> {
66-
xqueryRemoveAccount(SecurityManager.GUEST_USER);
67-
});
61+
extractPermissionDenied(() -> xqueryRemoveAccount(SecurityManager.GUEST_USER));
6862
}
6963

7064
@Test(expected = PermissionDeniedException.class)
7165
public void cannotDeleteUnknownAccount() throws XPathException, PermissionDeniedException, EXistException {
72-
extractPermissionDenied(() -> {
73-
xqueryRemoveAccount(SecurityManager.UNKNOWN_USER);
74-
});
66+
extractPermissionDenied(() -> xqueryRemoveAccount(SecurityManager.UNKNOWN_USER));
7567
}
7668

7769
private Sequence xqueryRemoveAccount(final String username) throws XPathException, PermissionDeniedException, EXistException {

exist-core/src/test/java/org/exist/xquery/functions/securitymanager/GroupManagementFunctionRemoveGroupTest.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,17 @@ public class GroupManagementFunctionRemoveGroupTest {
5555

5656
@Test(expected = PermissionDeniedException.class)
5757
public void cannotDeleteDbaGroup() throws XPathException, PermissionDeniedException, EXistException {
58-
extractPermissionDenied(() -> {
59-
xqueryRemoveGroup(SecurityManager.DBA_GROUP);
60-
});
58+
extractPermissionDenied(() -> xqueryRemoveGroup(SecurityManager.DBA_GROUP));
6159
}
6260

6361
@Test(expected = PermissionDeniedException.class)
6462
public void cannotDeleteGuestGroup() throws XPathException, PermissionDeniedException, EXistException {
65-
extractPermissionDenied(() -> {
66-
xqueryRemoveGroup(SecurityManager.GUEST_GROUP);
67-
});
63+
extractPermissionDenied(() -> xqueryRemoveGroup(SecurityManager.GUEST_GROUP));
6864
}
6965

7066
@Test(expected = PermissionDeniedException.class)
7167
public void cannotDeleteUnknownGroup() throws XPathException, PermissionDeniedException, EXistException {
72-
extractPermissionDenied(() -> {
73-
xqueryRemoveGroup(SecurityManager.UNKNOWN_GROUP);
74-
});
68+
extractPermissionDenied(() -> xqueryRemoveGroup(SecurityManager.UNKNOWN_GROUP));
7569
}
7670

7771
@Test

exist-core/src/test/java/org/exist/xquery/functions/xmldb/DbStoreTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ public final void simpleTest() throws XMLDBException {
5252
}
5353

5454
final XPathQueryService xpqs = testCol.getService(XPathQueryService.class);
55-
assertThrows(XMLDBException.class, () -> {
56-
xpqs.query(
57-
"xmldb:store(\n" +
58-
" '/db',\n" +
59-
" 'image.jpg',\n" +
60-
" xs:anyURI('https://www.example.com/image.jpg'),\n" +
61-
" 'image/png'\n" +
62-
" )");
63-
});
55+
assertThrows(XMLDBException.class, () -> xpqs.query(
56+
"xmldb:store(\n" +
57+
" '/db',\n" +
58+
" 'image.jpg',\n" +
59+
" xs:anyURI('https://www.example.com/image.jpg'),\n" +
60+
" 'image/png'\n" +
61+
" )"));
6462

6563

6664
}

0 commit comments

Comments
 (0)