From 1633c705a10068aa79a4f4a20c2f97529f136c59 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Thu, 15 Apr 2021 21:00:47 +0200 Subject: [PATCH] Use Collection.isEmpty (#10525) Fixes 47 SAT UseCollectionIsEmpty findings. Signed-off-by: Wouter Born --- .../internal/AccountServlet.java | 2 +- .../discovery/SmartHomeDevicesDiscovery.java | 2 +- .../internal/net/SocketChannelSession.java | 2 +- .../handler/AVMFritzButtonHandler.java | 2 +- .../comfoair/internal/ComfoAirHandler.java | 2 +- .../internal/handler/HotWaterHandler.java | 6 ++--- .../device/cosem/CosemObjectType.java | 2 +- .../discovery/EcobeeDiscoveryService.java | 2 +- .../enturno/internal/EnturNoHandler.java | 22 ++++++++++--------- .../hdpowerview/HDPowerViewJUnitTests.java | 4 ++-- .../BiweeklyPresentableCalendarTest.java | 4 ++-- .../handler/JablotronAlarmHandler.java | 4 ++-- .../handler/JablotronJa100FHandler.java | 6 ++--- .../handler/JablotronJa100Handler.java | 6 ++--- .../loxone/internal/LxServerHandler.java | 2 +- .../basic/BasicChannelTypeProvider.java | 6 ++--- .../internal/handler/MiIoBasicHandler.java | 10 ++++----- .../handler/MiIoUnsupportedHandler.java | 2 +- .../miio/internal/robot/RRMapDraw.java | 2 +- .../binding/miio/internal/ReadmeHelper.java | 2 +- .../neohub/internal/NeoHubHandler.java | 2 +- .../handler/NetatmoBridgeHandler.java | 2 +- .../internal/ThermostatHandler.java | 2 +- .../handler/RemoteopenhabBridgeHandler.java | 4 ++-- .../handler/RemoteopenhabThingHandler.java | 2 +- .../internal/SenseBoxAPIConnection.java | 7 +++--- .../internal/handler/ShellyBaseHandler.java | 2 +- .../internal/handler/ShellyLightHandler.java | 2 +- .../phonebook/PhonebookProfileFactory.java | 2 +- .../internal/util/UpnpXMLParser.java | 2 +- .../internal/handler/VigiCruesHandler.java | 2 +- .../volvooncall/internal/dto/Status.java | 2 +- .../esp32/WlanThermoEsp32CommandHandler.java | 6 ++--- .../nano/WlanThermoNanoV1CommandHandler.java | 6 ++--- .../internal/RRD4jPersistenceService.java | 2 +- 35 files changed, 67 insertions(+), 68 deletions(-) diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java index 4ed6d58ee..d81d2a19a 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java @@ -611,7 +611,7 @@ public class AccountServlet extends HttpServlet { if ((stateDeviceSerialNumber == null && device.serialNumber == null) || (stateDeviceSerialNumber != null && stateDeviceSerialNumber.equals(device.serialNumber))) { List pairedDeviceList = state.getPairedDeviceList(); - if (pairedDeviceList.size() > 0) { + if (!pairedDeviceList.isEmpty()) { html.append(""); for (PairedDevice pairedDevice : pairedDeviceList) { html.append("
NameValue
"); diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java index b25cdb286..11f3ba79f 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/discovery/SmartHomeDevicesDiscovery.java @@ -212,7 +212,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService { } Set supportedChildren = SmartHomeDeviceHandler.getSupportedSmartHomeDevices(shg, deviceList); - if (supportedChildren.size() == 0) { + if (supportedChildren.isEmpty()) { // No children with an supported interface continue; } diff --git a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java index 6e35a3b6b..f437eab8a 100644 --- a/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java +++ b/bundles/org.openhab.binding.atlona/src/main/java/org/openhab/binding/atlona/internal/net/SocketChannelSession.java @@ -347,7 +347,7 @@ public class SocketChannelSession implements SocketSession { while (isRunning.get()) { try { // if no listeners, we don't want to start dispatching yet. - if (listeners.size() == 0) { + if (listeners.isEmpty()) { Thread.sleep(250); continue; } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java index 850bb35f0..fbbc62696 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java @@ -137,7 +137,7 @@ public class AVMFritzButtonHandler extends DeviceHandler { } private void updateShortLongPressButton(List buttons) { - ButtonModel shortPressButton = buttons.size() > 0 ? buttons.get(0) : null; + ButtonModel shortPressButton = !buttons.isEmpty() ? buttons.get(0) : null; ButtonModel longPressButton = buttons.size() > 1 ? buttons.get(1) : null; ButtonModel lastPressedButton = shortPressButton != null && (longPressButton == null || shortPressButton.getLastpressedtimestamp() > longPressButton.getLastpressedtimestamp()) diff --git a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java index 8e0d6141a..c384c6626 100644 --- a/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java +++ b/bundles/org.openhab.binding.comfoair/src/main/java/org/openhab/binding/comfoair/internal/ComfoAirHandler.java @@ -87,7 +87,7 @@ public class ComfoAirHandler extends BaseThingHandler { Collection affectedReadCommands = ComfoAirCommandType .getAffectedReadCommands(channelId, keysToUpdate); - if (affectedReadCommands.size() > 0) { + if (!affectedReadCommands.isEmpty()) { Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands); affectedItemsPoller = scheduler.schedule(updateThread, 3, TimeUnit.SECONDS); } diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HotWaterHandler.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HotWaterHandler.java index 223a97a06..403d1aa57 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HotWaterHandler.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/HotWaterHandler.java @@ -82,17 +82,17 @@ public class HotWaterHandler extends DraytonWiserThingHandler { private State getHotWaterDemandState() { final List hotWater = getData().hotWater; - return OnOffType.from(hotWater.size() >= 1 && "ON".equalsIgnoreCase(hotWater.get(0).getHotWaterRelayState())); + return OnOffType.from(!hotWater.isEmpty() && "ON".equalsIgnoreCase(hotWater.get(0).getHotWaterRelayState())); } private State getManualModeState() { final List hotWater = getData().hotWater; - return OnOffType.from(hotWater.size() >= 1 && "MANUAL".equalsIgnoreCase(hotWater.get(0).getMode())); + return OnOffType.from(!hotWater.isEmpty() && "MANUAL".equalsIgnoreCase(hotWater.get(0).getMode())); } private State getSetPointState() { final List hotWater = getData().hotWater; - return OnOffType.from(hotWater.size() >= 1 && "ON".equalsIgnoreCase(hotWater.get(0).getWaterHeatingState())); + return OnOffType.from(!hotWater.isEmpty() && "ON".equalsIgnoreCase(hotWater.get(0).getWaterHeatingState())); } private void setManualMode(final boolean manualMode) throws DraytonWiserApiException { diff --git a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectType.java b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectType.java index 14655ad73..0b921807a 100644 --- a/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectType.java +++ b/bundles/org.openhab.binding.dsmr/src/main/java/org/openhab/binding/dsmr/internal/device/cosem/CosemObjectType.java @@ -240,7 +240,7 @@ public enum CosemObjectType { * @return true if this CosemObjectType support the requested number of values, false otherwise. */ public boolean supportsNrOfValues(int nrOfValues) { - if (repeatingDescriptors.size() == 0) { + if (repeatingDescriptors.isEmpty()) { return nrOfValues == descriptors.size(); } else { /* There are repeating descriptors */ diff --git a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java index 68cdb4621..e3028f64a 100644 --- a/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java +++ b/bundles/org.openhab.binding.ecobee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java @@ -153,7 +153,7 @@ public class EcobeeDiscoveryService extends AbstractDiscoveryService implements private synchronized void discoverSensors() { List thermostatThings = bridgeHandler.getThing().getThings(); - if (thermostatThings.size() == 0) { + if (thermostatThings.isEmpty()) { logger.debug("EcobeeDiscovery: Skipping sensor discovery because there are no thermostat things"); return; } diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java index 2a701eaba..bc990f702 100644 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java @@ -213,37 +213,39 @@ public class EnturNoHandler extends BaseThingHandler { if (processedData.size() > i) { State state = UnDefType.UNDEF; List departures = processedData.get(i).departures; + int departuresCount = departures.size(); List estimatedFlags = processedData.get(i).estimatedFlags; + int esitmatedFlagsCount = estimatedFlags.size(); switch (channelId) { case EnturNoBindingConstants.CHANNEL_DEPARTURE_01: - state = departures.size() > 0 ? getDateTimeTypeState(departures.get(0)) : state; + state = departuresCount > 0 ? getDateTimeTypeState(departures.get(0)) : state; break; case EnturNoBindingConstants.CHANNEL_DEPARTURE_02: - state = departures.size() > 1 ? getDateTimeTypeState(departures.get(1)) : state; + state = departuresCount > 1 ? getDateTimeTypeState(departures.get(1)) : state; break; case EnturNoBindingConstants.CHANNEL_DEPARTURE_03: - state = departures.size() > 2 ? getDateTimeTypeState(departures.get(2)) : state; + state = departuresCount > 2 ? getDateTimeTypeState(departures.get(2)) : state; break; case EnturNoBindingConstants.CHANNEL_DEPARTURE_04: - state = departures.size() > 3 ? getDateTimeTypeState(departures.get(3)) : state; + state = departuresCount > 3 ? getDateTimeTypeState(departures.get(3)) : state; break; case EnturNoBindingConstants.CHANNEL_DEPARTURE_05: - state = departures.size() > 4 ? getDateTimeTypeState(departures.get(4)) : state; + state = departuresCount > 4 ? getDateTimeTypeState(departures.get(4)) : state; break; case EnturNoBindingConstants.ESTIMATED_FLAG_01: - state = estimatedFlags.size() > 0 ? getStringTypeState(estimatedFlags.get(0)) : state; + state = esitmatedFlagsCount > 0 ? getStringTypeState(estimatedFlags.get(0)) : state; break; case EnturNoBindingConstants.ESTIMATED_FLAG_02: - state = estimatedFlags.size() > 1 ? getStringTypeState(estimatedFlags.get(1)) : state; + state = esitmatedFlagsCount > 1 ? getStringTypeState(estimatedFlags.get(1)) : state; break; case EnturNoBindingConstants.ESTIMATED_FLAG_03: - state = estimatedFlags.size() > 2 ? getStringTypeState(estimatedFlags.get(2)) : state; + state = esitmatedFlagsCount > 2 ? getStringTypeState(estimatedFlags.get(2)) : state; break; case EnturNoBindingConstants.ESTIMATED_FLAG_04: - state = estimatedFlags.size() > 3 ? getStringTypeState(estimatedFlags.get(3)) : state; + state = esitmatedFlagsCount > 3 ? getStringTypeState(estimatedFlags.get(3)) : state; break; case EnturNoBindingConstants.ESTIMATED_FLAG_05: - state = estimatedFlags.size() > 4 ? getStringTypeState(estimatedFlags.get(4)) : state; + state = esitmatedFlagsCount > 4 ? getStringTypeState(estimatedFlags.get(4)) : state; break; case EnturNoBindingConstants.CHANNEL_LINE_CODE: state = getStringTypeState(processedData.get(i).lineCode); diff --git a/bundles/org.openhab.binding.hdpowerview/src/test/java/org/openhab/binding/hdpowerview/HDPowerViewJUnitTests.java b/bundles/org.openhab.binding.hdpowerview/src/test/java/org/openhab/binding/hdpowerview/HDPowerViewJUnitTests.java index 7f6891dd3..afa17d571 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/test/java/org/openhab/binding/hdpowerview/HDPowerViewJUnitTests.java +++ b/bundles/org.openhab.binding.hdpowerview/src/test/java/org/openhab/binding/hdpowerview/HDPowerViewJUnitTests.java @@ -168,7 +168,7 @@ public class HDPowerViewJUnitTests { @Nullable List shadesData = shadesX.shadeData; assertNotNull(shadesData); - assertTrue(shadesData.size() > 0); + assertTrue(!shadesData.isEmpty()); @Nullable ShadeData shadeData; shadeData = shadesData.get(0); @@ -198,7 +198,7 @@ public class HDPowerViewJUnitTests { @Nullable List scenesData = scenes.sceneData; assertNotNull(scenesData); - assertTrue(scenesData.size() > 0); + assertTrue(!scenesData.isEmpty()); @Nullable Scene sceneZero = scenesData.get(0); assertNotNull(sceneZero); diff --git a/bundles/org.openhab.binding.icalendar/src/test/java/org/openhab/binding/icalendar/internal/logic/BiweeklyPresentableCalendarTest.java b/bundles/org.openhab.binding.icalendar/src/test/java/org/openhab/binding/icalendar/internal/logic/BiweeklyPresentableCalendarTest.java index 98690a06e..7bdb0e397 100644 --- a/bundles/org.openhab.binding.icalendar/src/test/java/org/openhab/binding/icalendar/internal/logic/BiweeklyPresentableCalendarTest.java +++ b/bundles/org.openhab.binding.icalendar/src/test/java/org/openhab/binding/icalendar/internal/logic/BiweeklyPresentableCalendarTest.java @@ -252,9 +252,9 @@ public class BiweeklyPresentableCalendarTest { events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"), Instant.parse("2020-01-28T16:05:00Z")); assertNotNull(events); - assertTrue(events.size() > 0); + assertTrue(!events.isEmpty()); List cmdTags = events.get(0).commandTags; - assertTrue(cmdTags.size() > 0); + assertTrue(!cmdTags.isEmpty()); CommandTag cmd = cmdTags.get(0); // accept correct, empty or null configuration codes assertTrue(cmd.isAuthorized("abc")); diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java index dcc4503b8..dcdc9efdd 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java @@ -187,7 +187,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler { } List events = sendGetEventHistory(); - if (events != null && events.size() > 0) { + if (events != null && !events.isEmpty()) { JablotronHistoryDataEvent event = events.get(0); updateLastEvent(event); } @@ -221,7 +221,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler { protected void updateEventChannel(String channel) { List events = eventCache.getValue(); - if (events != null && events.size() > 0) { + if (events != null && !events.isEmpty()) { JablotronHistoryDataEvent event = events.get(0); switch (channel) { case CHANNEL_LAST_EVENT_TIME: diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100FHandler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100FHandler.java index 7b4b72f24..21de9c3eb 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100FHandler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100FHandler.java @@ -12,9 +12,7 @@ */ package org.openhab.binding.jablotron.internal.handler; -import static org.openhab.binding.jablotron.JablotronBindingConstants.BINDING_ID; -import static org.openhab.binding.jablotron.JablotronBindingConstants.CACHE_TIMEOUT_MS; -import static org.openhab.binding.jablotron.JablotronBindingConstants.CHANNEL_LAST_CHECK_TIME; +import static org.openhab.binding.jablotron.JablotronBindingConstants.*; import java.util.List; @@ -181,7 +179,7 @@ public class JablotronJa100FHandler extends JablotronAlarmHandler { // update events List events = sendGetEventHistory(); - if (events != null && events.size() > 0) { + if (events != null && !events.isEmpty()) { JablotronHistoryDataEvent event = events.get(0); updateLastEvent(event); } diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java index 8cf74b1a9..8f8be61e3 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java @@ -12,9 +12,7 @@ */ package org.openhab.binding.jablotron.internal.handler; -import static org.openhab.binding.jablotron.JablotronBindingConstants.BINDING_ID; -import static org.openhab.binding.jablotron.JablotronBindingConstants.CACHE_TIMEOUT_MS; -import static org.openhab.binding.jablotron.JablotronBindingConstants.CHANNEL_LAST_CHECK_TIME; +import static org.openhab.binding.jablotron.JablotronBindingConstants.*; import java.util.List; @@ -199,7 +197,7 @@ public class JablotronJa100Handler extends JablotronAlarmHandler { private void updateTemperatureChannel(Channel channel, JablotronServiceDetailSegment segment) { List infos = segment.getSegmentInfos(); - if (infos.size() > 0) { + if (!infos.isEmpty()) { logger.debug("Found value: {} and type: {}", infos.get(0).getValue(), infos.get(0).getType()); updateState(channel.getUID(), QuantityType.valueOf(infos.get(0).getValue(), SIUnits.CELSIUS)); } else { diff --git a/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java b/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java index 17517e2b3..27c887127 100644 --- a/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java +++ b/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxServerHandler.java @@ -487,7 +487,7 @@ public class LxServerHandler extends BaseThingHandler implements LxServerHandler state.setStateValue(update.getValue()); }); - if (perStateUuid.size() == 0) { + if (perStateUuid.isEmpty()) { logger.debug("[{}] State update UUID={} has empty controls table", debugId, update.getUuid()); } } else { diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/BasicChannelTypeProvider.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/BasicChannelTypeProvider.java index c4f2340e2..d4956cc32 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/BasicChannelTypeProvider.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/BasicChannelTypeProvider.java @@ -17,10 +17,10 @@ import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_ID; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -108,8 +108,8 @@ public class BasicChannelTypeProvider implements ChannelTypeProvider { if (category != null) { channelTypeBuilder.withCategory(category); } - final LinkedHashSet tags = miChannel.getTags(); - if (tags != null && tags.size() > 0) { + final Set tags = miChannel.getTags(); + if (tags != null && !tags.isEmpty()) { channelTypeBuilder.withTags(tags); } channelTypes.put(channelTypeUID.getAsString(), channelTypeBuilder.build()); diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java index cefd4469b..e20e4592a 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java @@ -19,10 +19,10 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.TimeUnit; import javax.measure.Unit; @@ -471,8 +471,8 @@ public class MiIoBasicHandler extends MiIoAbstractHandler { ChannelTypeUID channelTypeUID = new ChannelTypeUID(miChannel.getChannelType()); if (channelTypeRegistry.getChannelType(channelTypeUID) != null) { newChannel = newChannel.withType(channelTypeUID); - final LinkedHashSet tags = miChannel.getTags(); - if (tags != null && tags.size() > 0) { + final Set tags = miChannel.getTags(); + if (tags != null && !tags.isEmpty()) { newChannel.withDefaultTags(tags); } } else { @@ -485,8 +485,8 @@ public class MiIoBasicHandler extends MiIoAbstractHandler { if (useGeneratedChannelType) { newChannel = newChannel .withType(new ChannelTypeUID(BINDING_ID, model.toUpperCase().replace(".", "_") + "_" + channel)); - final LinkedHashSet tags = miChannel.getTags(); - if (tags != null && tags.size() > 0) { + final Set tags = miChannel.getTags(); + if (tags != null && !tags.isEmpty()) { newChannel.withDefaultTags(tags); } } diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoUnsupportedHandler.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoUnsupportedHandler.java index 41c67411f..563b7e8cd 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoUnsupportedHandler.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoUnsupportedHandler.java @@ -264,7 +264,7 @@ public class MiIoUnsupportedHandler extends MiIoAbstractHandler { sb.append(supportedChannelList.get(ch)); sb.append("\r\n"); } - if (supportedChannelList.size() > 0) { + if (!supportedChannelList.isEmpty()) { MiIoBasicDevice mbd = createBasicDeviceDb(model, new ArrayList<>(supportedChannelList.keySet())); sb.append("Created experimental database for your device:\r\n"); sb.append(GSONP.toJson(mbd)); diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapDraw.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapDraw.java index a77249d84..388385cac 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapDraw.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapDraw.java @@ -180,7 +180,7 @@ public class RRMapDraw { g2d.draw(new Line2D.Float(xPos, yP, xPos, yP)); } } - if (logger.isDebugEnabled() && roomIds.size() > 0) { + if (logger.isDebugEnabled() && !roomIds.isEmpty()) { StringBuilder sb = new StringBuilder(); for (Integer r : roomIds) { sb.append(" " + r.toString()); diff --git a/bundles/org.openhab.binding.miio/src/test/java/org/openhab/binding/miio/internal/ReadmeHelper.java b/bundles/org.openhab.binding.miio/src/test/java/org/openhab/binding/miio/internal/ReadmeHelper.java index 6366c5121..94d937886 100644 --- a/bundles/org.openhab.binding.miio/src/test/java/org/openhab/binding/miio/internal/ReadmeHelper.java +++ b/bundles/org.openhab.binding.miio/src/test/java/org/openhab/binding/miio/internal/ReadmeHelper.java @@ -166,7 +166,7 @@ public class ReadmeHelper { StateDescriptionDTO stateDescription = channel.getStateDescription(); if (stateDescription != null && stateDescription.getOptions() != null) { final List options = stateDescription.getOptions(); - if (options != null && options.size() > 0) { + if (options != null && !options.isEmpty()) { StringBuilder mapping = new StringBuilder(); mapping.append("Value mapping ["); options.forEach((option) -> { diff --git a/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubHandler.java b/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubHandler.java index c95be4270..67e981b3b 100644 --- a/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubHandler.java +++ b/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubHandler.java @@ -243,7 +243,7 @@ public class NeoHubHandler extends BaseBridgeHandler { @Nullable List devices = deviceData.getDevices(); - if (devices == null || devices.size() == 0) { + if (devices == null || devices.isEmpty()) { logger.warn(MSG_FMT_DEVICE_POLL_ERR, "no devices found"); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); return null; diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoBridgeHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoBridgeHandler.java index 12a8d38ab..61ce9fa85 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoBridgeHandler.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/NetatmoBridgeHandler.java @@ -299,7 +299,7 @@ public class NetatmoBridgeHandler extends BaseBridgeHandler { .map(api -> api.getmeasure(equipmentId, scale, types, moduleId, null, "last", 1, true, false).getBody()) .orElse(null); updateStatus(ThingStatus.ONLINE); - NAMeasureBodyElem element = (data != null && data.size() > 0) ? data.get(0) : null; + NAMeasureBodyElem element = data != null && !data.isEmpty() ? data.get(0) : null; return element != null ? element.getValue().get(0) : Collections.emptyList(); } diff --git a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java index fcedd4764..8addb1754 100644 --- a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java +++ b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java @@ -131,7 +131,7 @@ public class ThermostatHandler extends BaseThingHandler { */ public @Nullable Thermostat tryHandleAndGetUpdatedThermostat() { final LinkedList> updatedValues = this.updatedValues; - if (updatedValues.size() == 0) { + if (updatedValues.isEmpty()) { return null; } this.updatedValues = new LinkedList<>(); diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java index f7ec33b01..a47f233d0 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java @@ -262,7 +262,7 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler logger.debug( "{} channels defined (with {} different channel types) for the thing {} (from {} items including {} groups)", channels.size(), nbChannelTypesCreated, getThing().getUID(), items.size(), nbGroups); - } else if (channels.size() > 0) { + } else if (!channels.isEmpty()) { int nbRemoved = 0; for (Channel channel : channels) { if (getThing().getChannel(channel.getUID()) != null) { @@ -319,7 +319,7 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler Channel channel = getThing().getChannel(item.name); RemoteopenhabStateDescription descr = item.stateDescription; List options = descr == null ? null : descr.options; - if (channel != null && options != null && options.size() > 0) { + if (channel != null && options != null && !options.isEmpty()) { List stateOptions = new ArrayList<>(); for (RemoteopenhabStateOption option : options) { stateOptions.add(new StateOption(option.value, option.label)); diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabThingHandler.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabThingHandler.java index db6335c93..ab29c91b4 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabThingHandler.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabThingHandler.java @@ -158,7 +158,7 @@ public class RemoteopenhabThingHandler extends BaseThingHandler implements Remot .withLabel(channelDTO.label).withDescription(channelDTO.description) .withConfiguration(channelConfig).build()); } - if (channels.size() > 0) { + if (!channels.isEmpty()) { ThingBuilder thingBuilder = editThing(); int nbRemoved = 0; for (Channel channel : channels) { diff --git a/bundles/org.openhab.binding.sensebox/src/main/java/org/openhab/binding/sensebox/internal/SenseBoxAPIConnection.java b/bundles/org.openhab.binding.sensebox/src/main/java/org/openhab/binding/sensebox/internal/SenseBoxAPIConnection.java index 0e14c975b..7ef94fa7a 100644 --- a/bundles/org.openhab.binding.sensebox/src/main/java/org/openhab/binding/sensebox/internal/SenseBoxAPIConnection.java +++ b/bundles/org.openhab.binding.sensebox/src/main/java/org/openhab/binding/sensebox/internal/SenseBoxAPIConnection.java @@ -80,17 +80,18 @@ public class SenseBoxAPIConnection { if (loc.getGeometry() != null) { List locationData = loc.getGeometry().getData(); if (locationData != null) { + int locationDataCount = locationData.size(); SenseBoxLocation location = new SenseBoxLocation(); - if (locationData.size() > 0) { + if (locationDataCount > 0) { location.setLongitude(locationData.get(0)); } - if (locationData.size() > 1) { + if (locationDataCount > 1) { location.setLatitude(locationData.get(1)); } - if (locationData.size() > 2) { + if (locationDataCount > 2) { location.setHeight(locationData.get(2)); } diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java index 25d6b4302..5307e6a37 100755 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java @@ -949,7 +949,7 @@ public class ShellyBaseHandler extends BaseThingHandler implements ShellyDeviceL public boolean updateWakeupReason(@Nullable List valueArray) { boolean changed = false; - if ((valueArray != null) && (valueArray.size() > 0)) { + if (valueArray != null && !valueArray.isEmpty()) { String reason = getString((String) valueArray.get(0)); String newVal = valueArray.toString(); changed = updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_WAKEUP, getStringType(reason)); diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java index ebc220e65..0d6e0b9b7 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyLightHandler.java @@ -492,7 +492,7 @@ public class ShellyLightHandler extends ShellyBaseHandler { logger.debug("{}: Setting effect to {}", thingName, newCol.effect); parms.put(SHELLY_COLOR_EFFECT, newCol.effect.toString()); } - if (parms.size() > 0) { + if (!parms.isEmpty()) { logger.debug("{}: Send light settings: {}", thingName, parms); api.setLightParms(lightId, parms); updateCurrentColors(lightId, newCol); diff --git a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java index 779331554..5ccfc737f 100644 --- a/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java +++ b/bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/phonebook/PhonebookProfileFactory.java @@ -130,7 +130,7 @@ public class PhonebookProfileFactory implements ProfileFactory, ProfileTypeProvi thingName + " - " + phonebook.getName())) .collect(Collectors.toList()); - if (parameterOptions.size() > 0) { + if (!parameterOptions.isEmpty()) { parameterOptions.add(new ParameterOption(thingUid, thingName)); } diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpXMLParser.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpXMLParser.java index 8d4b109f5..8f6174e38 100644 --- a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpXMLParser.java +++ b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpXMLParser.java @@ -375,7 +375,7 @@ public class UpnpXMLParser { entries.add(new UpnpEntry(id, refId, parentId, upnpClass.toString()).withTitle(title.toString()) .withAlbum(album.toString()).withAlbumArtUri(albumArtUri.toString()) .withCreator(creator.toString()) - .withArtist(artistList.size() > 0 ? artistList.get(0) : artist.toString()) + .withArtist(!artistList.isEmpty() ? artistList.get(0) : artist.toString()) .withPublisher(publisher.toString()).withGenre(genre.toString()).withTrackNumber(trackNumberVal) .withResList(resList)); diff --git a/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java b/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java index bd6097c48..4a9dcff9b 100644 --- a/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java +++ b/bundles/org.openhab.binding.vigicrues/src/main/java/org/openhab/binding/vigicrues/internal/handler/VigiCruesHandler.java @@ -243,7 +243,7 @@ public class VigiCruesHandler extends BaseThingHandler { } private void updateRelativeMeasure(String channelId, List> reference, double value) { - if (reference.size() > 0) { + if (!reference.isEmpty()) { double percent = value / reference.get(0).doubleValue() * 100; updateQuantity(channelId, percent, Units.PERCENT); } diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/Status.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/Status.java index a0f0a086b..7c70f6872 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/Status.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/dto/Status.java @@ -92,7 +92,7 @@ public class Status extends VocAnswer { } public boolean aFailedBulb() { - return bulbFailures.size() > 0; + return !bulbFailures.isEmpty(); } /* diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index d5a8f3fc4..b229d958b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -91,7 +91,7 @@ public class WlanThermoEsp32CommandHandler { } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList != null && channelList.size() > 0 && channelId < channelList.size()) { + if (channelList != null && !channelList.isEmpty() && channelId < channelList.size()) { Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -176,7 +176,7 @@ public class WlanThermoEsp32CommandHandler { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId < channelList.size()) { + if (!channelList.isEmpty() && channelId < channelList.size()) { Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -283,7 +283,7 @@ public class WlanThermoEsp32CommandHandler { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId < channelList.size()) { + if (!channelList.isEmpty() && channelId < channelList.size()) { Channel channel = channelList.get(channelId); if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.getTemp() != 999) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 9c30f4bf8..d5a88d893 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -81,7 +81,7 @@ public class WlanThermoNanoV1CommandHandler { } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId < channelList.size()) { + if (!channelList.isEmpty() && channelId < channelList.size()) { Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -165,7 +165,7 @@ public class WlanThermoNanoV1CommandHandler { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId < channelList.size()) { + if (!channelList.isEmpty() && channelId < channelList.size()) { Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -266,7 +266,7 @@ public class WlanThermoNanoV1CommandHandler { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId < channelList.size()) { + if (!channelList.isEmpty() && channelId < channelList.size()) { Channel channel = channelList.get(channelId); if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.getTemp() != 999) { diff --git a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java index 3eea5aa2e..4f9365837 100644 --- a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java +++ b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java @@ -671,7 +671,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { public boolean isValid() { // a valid configuration must be initialized // and contain at least one function - return (isInitialized && (archives.size() > 0)); + return isInitialized && !archives.isEmpty(); } @Override