Skip to content

Commit

Permalink
Prevent compiler warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Wouter Born <github@maindrain.net>
  • Loading branch information
wborn committed Jan 14, 2024
1 parent 66f64af commit 4a52de9
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -154,7 +155,8 @@ public Collection<String> getTypes() {
return obj;
}

Map<String, Object> objects = objectCache.computeIfAbsent(scriptIdentifier, k -> new HashMap<>());
Map<String, Object> objects = Objects
.requireNonNull(objectCache.computeIfAbsent(scriptIdentifier, k -> new HashMap<>()));

obj = objects.get(type);
if (obj != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -377,7 +378,8 @@ private Rule resolveRuleByTemplate(Rule rule) {
*/
private void updateRuleTemplateMapping(String templateUID, String ruleUID, boolean resolved) {
synchronized (this) {
Set<String> ruleUIDs = mapTemplateToRules.computeIfAbsent(templateUID, k -> new HashSet<>());
Set<String> ruleUIDs = Objects
.requireNonNull(mapTemplateToRules.computeIfAbsent(templateUID, k -> new HashSet<>()));
if (resolved) {
ruleUIDs.remove(ruleUID);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -252,7 +253,7 @@ protected void importFile(String parserType, URL url) {
}
} else {
synchronized (urls) {
List<URL> value = urls.computeIfAbsent(parserType, k -> new ArrayList<>());
List<URL> value = Objects.requireNonNull(urls.computeIfAbsent(parserType, k -> new ArrayList<>()));
value.add(url);
}
logger.debug("Parser {} not available", parserType, new Exception());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.service.WatchService;
Expand All @@ -35,8 +36,8 @@ public static void initializeWatchService(String watchingDir, AbstractFileProvid
WatchService watchService) {
AutomationWatchService aws = null;
synchronized (WATCH_SERVICES) {
Map<String, AutomationWatchService> watchers = WATCH_SERVICES.computeIfAbsent(provider,
k -> new HashMap<>());
Map<String, AutomationWatchService> watchers = Objects
.requireNonNull(WATCH_SERVICES.computeIfAbsent(provider, k -> new HashMap<>()));
if (watchers.get(watchingDir) == null) {
aws = new AutomationWatchService(provider, watchService, watchingDir);
watchers.put(watchingDir, aws);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -78,22 +79,15 @@ public final synchronized void addAll(Bundle bundle, Collection<T_OBJECT> object
if (objectList.isEmpty()) {
return;
}
List<T_OBJECT> objects = acquireObjects(bundle);
if (objects == null) {
return;
}
List<T_OBJECT> objects = Objects
.requireNonNull(bundleObjectMap.computeIfAbsent(bundle, k -> new CopyOnWriteArrayList<>()));
objects.addAll(objectList);
for (T_OBJECT object : objectList) {
// just make sure no old entry remains in the cache
removeCachedEntries(object);
}
}

private @Nullable List<T_OBJECT> acquireObjects(Bundle bundle) {
List<T_OBJECT> objects = bundleObjectMap.computeIfAbsent(bundle, k -> new CopyOnWriteArrayList<>());
return objects;
}

/**
* Gets the object with the given key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -88,13 +89,14 @@ private void createItemChannelLink(String context, String itemName, String chann
}
ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUIDObject, configuration);

Set<String> itemNames = contextMap.computeIfAbsent(context, k -> new HashSet<>());
Set<String> itemNames = Objects.requireNonNull(contextMap.computeIfAbsent(context, k -> new HashSet<>()));
itemNames.add(itemName);
if (previousItemNames != null) {
previousItemNames.remove(itemName);
}

Set<ItemChannelLink> links = itemChannelLinkMap.computeIfAbsent(itemName, k -> new HashSet<>());
Set<ItemChannelLink> links = Objects
.requireNonNull(itemChannelLinkMap.computeIfAbsent(itemName, k -> new HashSet<>()));
if (!links.contains(itemChannelLink)) {
links.add(itemChannelLink);
notifyListenersAboutAddedElement(itemChannelLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -264,7 +265,8 @@ protected ServiceRegistration<?> registerService(final Object service, final Str
}

private void saveServiceRegistration(final String interfaceName, final ServiceRegistration<?> srvReg) {
List<ServiceRegistration<?>> regs = registeredServices.computeIfAbsent(interfaceName, k -> new ArrayList<>());
List<ServiceRegistration<?>> regs = Objects
.requireNonNull(registeredServices.computeIfAbsent(interfaceName, k -> new ArrayList<>()));
regs.add(srvReg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -73,10 +74,10 @@ private void toLinkAdded(final L element) {
try {
Set<L> set;

set = itemNameToLink.computeIfAbsent(itemName, k -> new HashSet<>());
set = Objects.requireNonNull(itemNameToLink.computeIfAbsent(itemName, k -> new HashSet<>()));
set.add(element);

set = linkedUidToLink.computeIfAbsent(linkedUid, k -> new HashSet<>());
set = Objects.requireNonNull(linkedUidToLink.computeIfAbsent(linkedUid, k -> new HashSet<>()));
set.add(element);
} finally {
toLinkLock.writeLock().unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -86,7 +87,8 @@ public void recordCallEnd(Invocation invocation) {
@Override
public void enqueue(Invocation invocation) {
synchronized (queues) {
Queue<Invocation> queue = queues.computeIfAbsent(invocation.getIdentifier(), k -> new LinkedList<>());
Queue<Invocation> queue = Objects
.requireNonNull(queues.computeIfAbsent(invocation.getIdentifier(), k -> new LinkedList<>()));
queue.add(invocation);
}
trigger(invocation.getIdentifier());
Expand Down

0 comments on commit 4a52de9

Please sign in to comment.