Skip to content

Commit 9851c79

Browse files
committed
More lambda's to simplify code (some potential changes were left out because it would become less readable)
1 parent 4d08d96 commit 9851c79

17 files changed

+28
-42
lines changed

exist-core/src/main/java/org/exist/launcher/ServiceManagerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class ServiceManagerFactory {
1010

11-
private static final AtomicLazyVal<ServiceManager> WINDOWS_SERVICE_MANAGER = new AtomicLazyVal<>(() -> new WindowsServiceManager());
11+
private static final AtomicLazyVal<ServiceManager> WINDOWS_SERVICE_MANAGER = new AtomicLazyVal<>(WindowsServiceManager::new);
1212

1313
/**
1414
* Returns the service manager for the current

exist-core/src/main/java/org/exist/repo/Deployment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ private void checkUserSettings(final DBBroker broker, final RequestedPerms reque
636636
if (!secman.hasAccount(requestedPerms.user)) {
637637
final UserAider aider = new UserAider(requestedPerms.user);
638638
aider.setPassword(requestedPerms.password);
639-
requestedPerms.group.ifPresent(groupName -> aider.addGroup(groupName));
639+
requestedPerms.group.ifPresent(aider::addGroup);
640640
secman.addAccount(broker, aider);
641641
}
642642
} catch (final PermissionDeniedException | EXistException e) {

exist-core/src/main/java/org/exist/security/AbstractSubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public boolean equals(final Object obj) {
180180
return Optional
181181
.ofNullable(obj)
182182
.flatMap(other -> other instanceof Account ? Optional.of((Account)other) : Optional.empty())
183-
.map(otherAccount -> account.equals(otherAccount))
183+
.map(account::equals)
184184
.orElse(false);
185185
}
186186

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,7 @@ private int getCurrentPrincipalId() {
935935
* @param updateFn A function which updates the principal db and returns a new principal id.
936936
*/
937937
public void update(final BiFunction<Int2ObjectMap<V>, Integer, Integer> updateFn) {
938-
write(principalDb -> {
939-
this.principalId = updateFn.apply(principalDb, principalId);
940-
});
938+
write(principalDb -> this.principalId = updateFn.apply(principalDb, principalId));
941939
}
942940
}
943941

exist-core/src/main/java/org/exist/storage/structural/NativeStructuralIndexWorker.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,9 @@ private void addNode(QName qname, NodeProxy proxy) {
651651
throw new IllegalArgumentException("Document id ('" + document.getDocId() + "') and proxy id ('" +
652652
proxy.getOwnerDocument().getDocId() + "') differ !");
653653
}
654-
//Is this qname already pending ?
655-
List<NodeProxy> buf = pending.get(qname);
656-
if (buf == null) {
657-
//Create a node list
658-
buf = new ArrayList<>(50);
659-
pending.put(qname, buf);
660-
}
654+
//Is this qname already pending ? Create a node list when not present.
655+
List<NodeProxy> buf = pending.computeIfAbsent(qname, k -> new ArrayList<>(50));
656+
661657
//Add node's proxy to the list
662658
buf.add(proxy);
663659
}

exist-core/src/main/java/org/exist/storage/txn/TransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ private int uncommittedTransaction() {
537537
return 0;
538538
}
539539
},
540-
(a, b) -> a + b
540+
Integer::sum
541541
);
542542

543543
if (uncommittedCount == null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static <T> Optional<T> getOpt(final ParsedArguments parsedArguments, fina
6767
*/
6868
public static <T> List<T> getListOpt(final ParsedArguments parsedArguments, final Argument<List<T>> argument) {
6969
return getOpt(parsedArguments, argument)
70-
.orElseGet(() -> Collections.emptyList());
70+
.orElseGet(Collections::emptyList);
7171
}
7272

7373
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
230230
public static long sizeQuietly(final Collection<Path> paths) {
231231
return paths.stream().map(FileUtils::sizeQuietly)
232232
.filter(size -> size != -1)
233-
.reduce((a, b) -> a + b)
233+
.reduce(Long::sum)
234234
.orElse(-1L);
235235
}
236236

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static PatternFactory getInstance() {
4848
}
4949

5050
public Pattern getPattern(final String pattern) {
51-
return cache.get(pattern, ptn -> Pattern.compile(ptn));
51+
return cache.get(pattern, Pattern::compile);
5252
}
5353

5454
public Pattern getPattern(final String pattern, final int flags) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private static Function<DBBroker, Txn> transaction() {
239239
final boolean joinTransactionIfPresent = System.getProperty(PROP_JOIN_TRANSACTION_IF_PRESENT, "true")
240240
.equalsIgnoreCase("true");
241241
if(joinTransactionIfPresent) {
242-
return (broker) -> broker.continueOrBeginTransaction();
242+
return DBBroker::continueOrBeginTransaction;
243243
} else {
244244
return (broker) -> broker.getBrokerPool().getTransactionManager().beginTransaction();
245245
}

0 commit comments

Comments
 (0)