Skip to content

Commit 08dd224

Browse files
committed
improve impl
1 parent 79a5801 commit 08dd224

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

src/main/java/de/rwth/idsg/steve/ocpp/ws/SessionContextStoreImpl.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ public SessionContextStoreImpl(WsSessionSelectStrategy wsSessionSelectStrategy)
4141
public void add(String chargeBoxId, WebSocketSession session, ScheduledFuture pingSchedule) {
4242
SessionContext context = new SessionContext(session, pingSchedule, DateTime.now());
4343

44-
Deque<SessionContext> endpointDeque = lookupTable.get(chargeBoxId);
45-
if (endpointDeque == null) {
46-
final Deque<SessionContext> emptyDeque = new ArrayDeque<>();
47-
endpointDeque = lookupTable.putIfAbsent(chargeBoxId, emptyDeque);
48-
if (endpointDeque == null) {
49-
endpointDeque = emptyDeque;
50-
}
51-
}
44+
Deque<SessionContext> endpointDeque = lookupTable.computeIfAbsent(chargeBoxId, str -> new ArrayDeque<>());
5245
endpointDeque.addLast(context); // Adding at the end
46+
5347
log.debug("A new SessionContext is stored for chargeBoxId '{}'. Store size: {}",
5448
chargeBoxId, endpointDeque.size());
5549
}

0 commit comments

Comments
 (0)