Use Collection.isEmpty (#10525)

Fixes 47 SAT UseCollectionIsEmpty findings.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-04-15 21:00:47 +02:00 committed by GitHub
parent 7a22d65406
commit 1633c705a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 67 additions and 68 deletions

View File

@ -611,7 +611,7 @@ public class AccountServlet extends HttpServlet {
if ((stateDeviceSerialNumber == null && device.serialNumber == null) if ((stateDeviceSerialNumber == null && device.serialNumber == null)
|| (stateDeviceSerialNumber != null && stateDeviceSerialNumber.equals(device.serialNumber))) { || (stateDeviceSerialNumber != null && stateDeviceSerialNumber.equals(device.serialNumber))) {
List<PairedDevice> pairedDeviceList = state.getPairedDeviceList(); List<PairedDevice> pairedDeviceList = state.getPairedDeviceList();
if (pairedDeviceList.size() > 0) { if (!pairedDeviceList.isEmpty()) {
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>"); html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
for (PairedDevice pairedDevice : pairedDeviceList) { for (PairedDevice pairedDevice : pairedDeviceList) {
html.append("<tr><td>"); html.append("<tr><td>");

View File

@ -212,7 +212,7 @@ public class SmartHomeDevicesDiscovery extends AbstractDiscoveryService {
} }
Set<SmartHomeDevice> supportedChildren = SmartHomeDeviceHandler.getSupportedSmartHomeDevices(shg, Set<SmartHomeDevice> supportedChildren = SmartHomeDeviceHandler.getSupportedSmartHomeDevices(shg,
deviceList); deviceList);
if (supportedChildren.size() == 0) { if (supportedChildren.isEmpty()) {
// No children with an supported interface // No children with an supported interface
continue; continue;
} }

View File

@ -347,7 +347,7 @@ public class SocketChannelSession implements SocketSession {
while (isRunning.get()) { while (isRunning.get()) {
try { try {
// if no listeners, we don't want to start dispatching yet. // if no listeners, we don't want to start dispatching yet.
if (listeners.size() == 0) { if (listeners.isEmpty()) {
Thread.sleep(250); Thread.sleep(250);
continue; continue;
} }

View File

@ -137,7 +137,7 @@ public class AVMFritzButtonHandler extends DeviceHandler {
} }
private void updateShortLongPressButton(List<ButtonModel> buttons) { private void updateShortLongPressButton(List<ButtonModel> 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 longPressButton = buttons.size() > 1 ? buttons.get(1) : null;
ButtonModel lastPressedButton = shortPressButton != null && (longPressButton == null ButtonModel lastPressedButton = shortPressButton != null && (longPressButton == null
|| shortPressButton.getLastpressedtimestamp() > longPressButton.getLastpressedtimestamp()) || shortPressButton.getLastpressedtimestamp() > longPressButton.getLastpressedtimestamp())

View File

@ -87,7 +87,7 @@ public class ComfoAirHandler extends BaseThingHandler {
Collection<ComfoAirCommand> affectedReadCommands = ComfoAirCommandType Collection<ComfoAirCommand> affectedReadCommands = ComfoAirCommandType
.getAffectedReadCommands(channelId, keysToUpdate); .getAffectedReadCommands(channelId, keysToUpdate);
if (affectedReadCommands.size() > 0) { if (!affectedReadCommands.isEmpty()) {
Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands); Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands);
affectedItemsPoller = scheduler.schedule(updateThread, 3, TimeUnit.SECONDS); affectedItemsPoller = scheduler.schedule(updateThread, 3, TimeUnit.SECONDS);
} }

View File

@ -82,17 +82,17 @@ public class HotWaterHandler extends DraytonWiserThingHandler<HotWaterData> {
private State getHotWaterDemandState() { private State getHotWaterDemandState() {
final List<HotWaterDTO> hotWater = getData().hotWater; final List<HotWaterDTO> 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() { private State getManualModeState() {
final List<HotWaterDTO> hotWater = getData().hotWater; final List<HotWaterDTO> 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() { private State getSetPointState() {
final List<HotWaterDTO> hotWater = getData().hotWater; final List<HotWaterDTO> 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 { private void setManualMode(final boolean manualMode) throws DraytonWiserApiException {

View File

@ -240,7 +240,7 @@ public enum CosemObjectType {
* @return true if this CosemObjectType support the requested number of values, false otherwise. * @return true if this CosemObjectType support the requested number of values, false otherwise.
*/ */
public boolean supportsNrOfValues(int nrOfValues) { public boolean supportsNrOfValues(int nrOfValues) {
if (repeatingDescriptors.size() == 0) { if (repeatingDescriptors.isEmpty()) {
return nrOfValues == descriptors.size(); return nrOfValues == descriptors.size();
} else { } else {
/* There are repeating descriptors */ /* There are repeating descriptors */

View File

@ -153,7 +153,7 @@ public class EcobeeDiscoveryService extends AbstractDiscoveryService implements
private synchronized void discoverSensors() { private synchronized void discoverSensors() {
List<Thing> thermostatThings = bridgeHandler.getThing().getThings(); List<Thing> thermostatThings = bridgeHandler.getThing().getThings();
if (thermostatThings.size() == 0) { if (thermostatThings.isEmpty()) {
logger.debug("EcobeeDiscovery: Skipping sensor discovery because there are no thermostat things"); logger.debug("EcobeeDiscovery: Skipping sensor discovery because there are no thermostat things");
return; return;
} }

View File

@ -213,37 +213,39 @@ public class EnturNoHandler extends BaseThingHandler {
if (processedData.size() > i) { if (processedData.size() > i) {
State state = UnDefType.UNDEF; State state = UnDefType.UNDEF;
List<String> departures = processedData.get(i).departures; List<String> departures = processedData.get(i).departures;
int departuresCount = departures.size();
List<String> estimatedFlags = processedData.get(i).estimatedFlags; List<String> estimatedFlags = processedData.get(i).estimatedFlags;
int esitmatedFlagsCount = estimatedFlags.size();
switch (channelId) { switch (channelId) {
case EnturNoBindingConstants.CHANNEL_DEPARTURE_01: case EnturNoBindingConstants.CHANNEL_DEPARTURE_01:
state = departures.size() > 0 ? getDateTimeTypeState(departures.get(0)) : state; state = departuresCount > 0 ? getDateTimeTypeState(departures.get(0)) : state;
break; break;
case EnturNoBindingConstants.CHANNEL_DEPARTURE_02: case EnturNoBindingConstants.CHANNEL_DEPARTURE_02:
state = departures.size() > 1 ? getDateTimeTypeState(departures.get(1)) : state; state = departuresCount > 1 ? getDateTimeTypeState(departures.get(1)) : state;
break; break;
case EnturNoBindingConstants.CHANNEL_DEPARTURE_03: case EnturNoBindingConstants.CHANNEL_DEPARTURE_03:
state = departures.size() > 2 ? getDateTimeTypeState(departures.get(2)) : state; state = departuresCount > 2 ? getDateTimeTypeState(departures.get(2)) : state;
break; break;
case EnturNoBindingConstants.CHANNEL_DEPARTURE_04: case EnturNoBindingConstants.CHANNEL_DEPARTURE_04:
state = departures.size() > 3 ? getDateTimeTypeState(departures.get(3)) : state; state = departuresCount > 3 ? getDateTimeTypeState(departures.get(3)) : state;
break; break;
case EnturNoBindingConstants.CHANNEL_DEPARTURE_05: case EnturNoBindingConstants.CHANNEL_DEPARTURE_05:
state = departures.size() > 4 ? getDateTimeTypeState(departures.get(4)) : state; state = departuresCount > 4 ? getDateTimeTypeState(departures.get(4)) : state;
break; break;
case EnturNoBindingConstants.ESTIMATED_FLAG_01: case EnturNoBindingConstants.ESTIMATED_FLAG_01:
state = estimatedFlags.size() > 0 ? getStringTypeState(estimatedFlags.get(0)) : state; state = esitmatedFlagsCount > 0 ? getStringTypeState(estimatedFlags.get(0)) : state;
break; break;
case EnturNoBindingConstants.ESTIMATED_FLAG_02: case EnturNoBindingConstants.ESTIMATED_FLAG_02:
state = estimatedFlags.size() > 1 ? getStringTypeState(estimatedFlags.get(1)) : state; state = esitmatedFlagsCount > 1 ? getStringTypeState(estimatedFlags.get(1)) : state;
break; break;
case EnturNoBindingConstants.ESTIMATED_FLAG_03: case EnturNoBindingConstants.ESTIMATED_FLAG_03:
state = estimatedFlags.size() > 2 ? getStringTypeState(estimatedFlags.get(2)) : state; state = esitmatedFlagsCount > 2 ? getStringTypeState(estimatedFlags.get(2)) : state;
break; break;
case EnturNoBindingConstants.ESTIMATED_FLAG_04: case EnturNoBindingConstants.ESTIMATED_FLAG_04:
state = estimatedFlags.size() > 3 ? getStringTypeState(estimatedFlags.get(3)) : state; state = esitmatedFlagsCount > 3 ? getStringTypeState(estimatedFlags.get(3)) : state;
break; break;
case EnturNoBindingConstants.ESTIMATED_FLAG_05: case EnturNoBindingConstants.ESTIMATED_FLAG_05:
state = estimatedFlags.size() > 4 ? getStringTypeState(estimatedFlags.get(4)) : state; state = esitmatedFlagsCount > 4 ? getStringTypeState(estimatedFlags.get(4)) : state;
break; break;
case EnturNoBindingConstants.CHANNEL_LINE_CODE: case EnturNoBindingConstants.CHANNEL_LINE_CODE:
state = getStringTypeState(processedData.get(i).lineCode); state = getStringTypeState(processedData.get(i).lineCode);

View File

@ -168,7 +168,7 @@ public class HDPowerViewJUnitTests {
@Nullable @Nullable
List<ShadeData> shadesData = shadesX.shadeData; List<ShadeData> shadesData = shadesX.shadeData;
assertNotNull(shadesData); assertNotNull(shadesData);
assertTrue(shadesData.size() > 0); assertTrue(!shadesData.isEmpty());
@Nullable @Nullable
ShadeData shadeData; ShadeData shadeData;
shadeData = shadesData.get(0); shadeData = shadesData.get(0);
@ -198,7 +198,7 @@ public class HDPowerViewJUnitTests {
@Nullable @Nullable
List<Scene> scenesData = scenes.sceneData; List<Scene> scenesData = scenes.sceneData;
assertNotNull(scenesData); assertNotNull(scenesData);
assertTrue(scenesData.size() > 0); assertTrue(!scenesData.isEmpty());
@Nullable @Nullable
Scene sceneZero = scenesData.get(0); Scene sceneZero = scenesData.get(0);
assertNotNull(sceneZero); assertNotNull(sceneZero);

View File

@ -252,9 +252,9 @@ public class BiweeklyPresentableCalendarTest {
events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"), events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"),
Instant.parse("2020-01-28T16:05:00Z")); Instant.parse("2020-01-28T16:05:00Z"));
assertNotNull(events); assertNotNull(events);
assertTrue(events.size() > 0); assertTrue(!events.isEmpty());
List<CommandTag> cmdTags = events.get(0).commandTags; List<CommandTag> cmdTags = events.get(0).commandTags;
assertTrue(cmdTags.size() > 0); assertTrue(!cmdTags.isEmpty());
CommandTag cmd = cmdTags.get(0); CommandTag cmd = cmdTags.get(0);
// accept correct, empty or null configuration codes // accept correct, empty or null configuration codes
assertTrue(cmd.isAuthorized("abc")); assertTrue(cmd.isAuthorized("abc"));

View File

@ -187,7 +187,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler {
} }
List<JablotronHistoryDataEvent> events = sendGetEventHistory(); List<JablotronHistoryDataEvent> events = sendGetEventHistory();
if (events != null && events.size() > 0) { if (events != null && !events.isEmpty()) {
JablotronHistoryDataEvent event = events.get(0); JablotronHistoryDataEvent event = events.get(0);
updateLastEvent(event); updateLastEvent(event);
} }
@ -221,7 +221,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler {
protected void updateEventChannel(String channel) { protected void updateEventChannel(String channel) {
List<JablotronHistoryDataEvent> events = eventCache.getValue(); List<JablotronHistoryDataEvent> events = eventCache.getValue();
if (events != null && events.size() > 0) { if (events != null && !events.isEmpty()) {
JablotronHistoryDataEvent event = events.get(0); JablotronHistoryDataEvent event = events.get(0);
switch (channel) { switch (channel) {
case CHANNEL_LAST_EVENT_TIME: case CHANNEL_LAST_EVENT_TIME:

View File

@ -12,9 +12,7 @@
*/ */
package org.openhab.binding.jablotron.internal.handler; package org.openhab.binding.jablotron.internal.handler;
import static org.openhab.binding.jablotron.JablotronBindingConstants.BINDING_ID; import static org.openhab.binding.jablotron.JablotronBindingConstants.*;
import static org.openhab.binding.jablotron.JablotronBindingConstants.CACHE_TIMEOUT_MS;
import static org.openhab.binding.jablotron.JablotronBindingConstants.CHANNEL_LAST_CHECK_TIME;
import java.util.List; import java.util.List;
@ -181,7 +179,7 @@ public class JablotronJa100FHandler extends JablotronAlarmHandler {
// update events // update events
List<JablotronHistoryDataEvent> events = sendGetEventHistory(); List<JablotronHistoryDataEvent> events = sendGetEventHistory();
if (events != null && events.size() > 0) { if (events != null && !events.isEmpty()) {
JablotronHistoryDataEvent event = events.get(0); JablotronHistoryDataEvent event = events.get(0);
updateLastEvent(event); updateLastEvent(event);
} }

View File

@ -12,9 +12,7 @@
*/ */
package org.openhab.binding.jablotron.internal.handler; package org.openhab.binding.jablotron.internal.handler;
import static org.openhab.binding.jablotron.JablotronBindingConstants.BINDING_ID; import static org.openhab.binding.jablotron.JablotronBindingConstants.*;
import static org.openhab.binding.jablotron.JablotronBindingConstants.CACHE_TIMEOUT_MS;
import static org.openhab.binding.jablotron.JablotronBindingConstants.CHANNEL_LAST_CHECK_TIME;
import java.util.List; import java.util.List;
@ -199,7 +197,7 @@ public class JablotronJa100Handler extends JablotronAlarmHandler {
private void updateTemperatureChannel(Channel channel, JablotronServiceDetailSegment segment) { private void updateTemperatureChannel(Channel channel, JablotronServiceDetailSegment segment) {
List<JablotronServiceDetailSegmentInfo> infos = segment.getSegmentInfos(); List<JablotronServiceDetailSegmentInfo> infos = segment.getSegmentInfos();
if (infos.size() > 0) { if (!infos.isEmpty()) {
logger.debug("Found value: {} and type: {}", infos.get(0).getValue(), infos.get(0).getType()); 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)); updateState(channel.getUID(), QuantityType.valueOf(infos.get(0).getValue(), SIUnits.CELSIUS));
} else { } else {

View File

@ -487,7 +487,7 @@ public class LxServerHandler extends BaseThingHandler implements LxServerHandler
state.setStateValue(update.getValue()); state.setStateValue(update.getValue());
}); });
if (perStateUuid.size() == 0) { if (perStateUuid.isEmpty()) {
logger.debug("[{}] State update UUID={} has empty controls table", debugId, update.getUuid()); logger.debug("[{}] State update UUID={} has empty controls table", debugId, update.getUuid());
} }
} else { } else {

View File

@ -17,10 +17,10 @@ import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_ID;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
@ -108,8 +108,8 @@ public class BasicChannelTypeProvider implements ChannelTypeProvider {
if (category != null) { if (category != null) {
channelTypeBuilder.withCategory(category); channelTypeBuilder.withCategory(category);
} }
final LinkedHashSet<String> tags = miChannel.getTags(); final Set<String> tags = miChannel.getTags();
if (tags != null && tags.size() > 0) { if (tags != null && !tags.isEmpty()) {
channelTypeBuilder.withTags(tags); channelTypeBuilder.withTags(tags);
} }
channelTypes.put(channelTypeUID.getAsString(), channelTypeBuilder.build()); channelTypes.put(channelTypeUID.getAsString(), channelTypeBuilder.build());

View File

@ -19,10 +19,10 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.measure.Unit; import javax.measure.Unit;
@ -471,8 +471,8 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
ChannelTypeUID channelTypeUID = new ChannelTypeUID(miChannel.getChannelType()); ChannelTypeUID channelTypeUID = new ChannelTypeUID(miChannel.getChannelType());
if (channelTypeRegistry.getChannelType(channelTypeUID) != null) { if (channelTypeRegistry.getChannelType(channelTypeUID) != null) {
newChannel = newChannel.withType(channelTypeUID); newChannel = newChannel.withType(channelTypeUID);
final LinkedHashSet<String> tags = miChannel.getTags(); final Set<String> tags = miChannel.getTags();
if (tags != null && tags.size() > 0) { if (tags != null && !tags.isEmpty()) {
newChannel.withDefaultTags(tags); newChannel.withDefaultTags(tags);
} }
} else { } else {
@ -485,8 +485,8 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
if (useGeneratedChannelType) { if (useGeneratedChannelType) {
newChannel = newChannel newChannel = newChannel
.withType(new ChannelTypeUID(BINDING_ID, model.toUpperCase().replace(".", "_") + "_" + channel)); .withType(new ChannelTypeUID(BINDING_ID, model.toUpperCase().replace(".", "_") + "_" + channel));
final LinkedHashSet<String> tags = miChannel.getTags(); final Set<String> tags = miChannel.getTags();
if (tags != null && tags.size() > 0) { if (tags != null && !tags.isEmpty()) {
newChannel.withDefaultTags(tags); newChannel.withDefaultTags(tags);
} }
} }

View File

@ -264,7 +264,7 @@ public class MiIoUnsupportedHandler extends MiIoAbstractHandler {
sb.append(supportedChannelList.get(ch)); sb.append(supportedChannelList.get(ch));
sb.append("\r\n"); sb.append("\r\n");
} }
if (supportedChannelList.size() > 0) { if (!supportedChannelList.isEmpty()) {
MiIoBasicDevice mbd = createBasicDeviceDb(model, new ArrayList<>(supportedChannelList.keySet())); MiIoBasicDevice mbd = createBasicDeviceDb(model, new ArrayList<>(supportedChannelList.keySet()));
sb.append("Created experimental database for your device:\r\n"); sb.append("Created experimental database for your device:\r\n");
sb.append(GSONP.toJson(mbd)); sb.append(GSONP.toJson(mbd));

View File

@ -180,7 +180,7 @@ public class RRMapDraw {
g2d.draw(new Line2D.Float(xPos, yP, xPos, yP)); g2d.draw(new Line2D.Float(xPos, yP, xPos, yP));
} }
} }
if (logger.isDebugEnabled() && roomIds.size() > 0) { if (logger.isDebugEnabled() && !roomIds.isEmpty()) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Integer r : roomIds) { for (Integer r : roomIds) {
sb.append(" " + r.toString()); sb.append(" " + r.toString());

View File

@ -166,7 +166,7 @@ public class ReadmeHelper {
StateDescriptionDTO stateDescription = channel.getStateDescription(); StateDescriptionDTO stateDescription = channel.getStateDescription();
if (stateDescription != null && stateDescription.getOptions() != null) { if (stateDescription != null && stateDescription.getOptions() != null) {
final List<OptionsValueListDTO> options = stateDescription.getOptions(); final List<OptionsValueListDTO> options = stateDescription.getOptions();
if (options != null && options.size() > 0) { if (options != null && !options.isEmpty()) {
StringBuilder mapping = new StringBuilder(); StringBuilder mapping = new StringBuilder();
mapping.append("Value mapping ["); mapping.append("Value mapping [");
options.forEach((option) -> { options.forEach((option) -> {

View File

@ -243,7 +243,7 @@ public class NeoHubHandler extends BaseBridgeHandler {
@Nullable @Nullable
List<? extends AbstractRecord> devices = deviceData.getDevices(); List<? extends AbstractRecord> devices = deviceData.getDevices();
if (devices == null || devices.size() == 0) { if (devices == null || devices.isEmpty()) {
logger.warn(MSG_FMT_DEVICE_POLL_ERR, "no devices found"); logger.warn(MSG_FMT_DEVICE_POLL_ERR, "no devices found");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
return null; return null;

View File

@ -299,7 +299,7 @@ public class NetatmoBridgeHandler extends BaseBridgeHandler {
.map(api -> api.getmeasure(equipmentId, scale, types, moduleId, null, "last", 1, true, false).getBody()) .map(api -> api.getmeasure(equipmentId, scale, types, moduleId, null, "last", 1, true, false).getBody())
.orElse(null); .orElse(null);
updateStatus(ThingStatus.ONLINE); 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(); return element != null ? element.getValue().get(0) : Collections.emptyList();
} }

View File

@ -131,7 +131,7 @@ public class ThermostatHandler extends BaseThingHandler {
*/ */
public @Nullable Thermostat tryHandleAndGetUpdatedThermostat() { public @Nullable Thermostat tryHandleAndGetUpdatedThermostat() {
final LinkedList<SimpleImmutableEntry<String, Command>> updatedValues = this.updatedValues; final LinkedList<SimpleImmutableEntry<String, Command>> updatedValues = this.updatedValues;
if (updatedValues.size() == 0) { if (updatedValues.isEmpty()) {
return null; return null;
} }
this.updatedValues = new LinkedList<>(); this.updatedValues = new LinkedList<>();

View File

@ -262,7 +262,7 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
logger.debug( logger.debug(
"{} channels defined (with {} different channel types) for the thing {} (from {} items including {} groups)", "{} channels defined (with {} different channel types) for the thing {} (from {} items including {} groups)",
channels.size(), nbChannelTypesCreated, getThing().getUID(), items.size(), nbGroups); channels.size(), nbChannelTypesCreated, getThing().getUID(), items.size(), nbGroups);
} else if (channels.size() > 0) { } else if (!channels.isEmpty()) {
int nbRemoved = 0; int nbRemoved = 0;
for (Channel channel : channels) { for (Channel channel : channels) {
if (getThing().getChannel(channel.getUID()) != null) { if (getThing().getChannel(channel.getUID()) != null) {
@ -319,7 +319,7 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
Channel channel = getThing().getChannel(item.name); Channel channel = getThing().getChannel(item.name);
RemoteopenhabStateDescription descr = item.stateDescription; RemoteopenhabStateDescription descr = item.stateDescription;
List<RemoteopenhabStateOption> options = descr == null ? null : descr.options; List<RemoteopenhabStateOption> options = descr == null ? null : descr.options;
if (channel != null && options != null && options.size() > 0) { if (channel != null && options != null && !options.isEmpty()) {
List<StateOption> stateOptions = new ArrayList<>(); List<StateOption> stateOptions = new ArrayList<>();
for (RemoteopenhabStateOption option : options) { for (RemoteopenhabStateOption option : options) {
stateOptions.add(new StateOption(option.value, option.label)); stateOptions.add(new StateOption(option.value, option.label));

View File

@ -158,7 +158,7 @@ public class RemoteopenhabThingHandler extends BaseThingHandler implements Remot
.withLabel(channelDTO.label).withDescription(channelDTO.description) .withLabel(channelDTO.label).withDescription(channelDTO.description)
.withConfiguration(channelConfig).build()); .withConfiguration(channelConfig).build());
} }
if (channels.size() > 0) { if (!channels.isEmpty()) {
ThingBuilder thingBuilder = editThing(); ThingBuilder thingBuilder = editThing();
int nbRemoved = 0; int nbRemoved = 0;
for (Channel channel : channels) { for (Channel channel : channels) {

View File

@ -80,17 +80,18 @@ public class SenseBoxAPIConnection {
if (loc.getGeometry() != null) { if (loc.getGeometry() != null) {
List<Double> locationData = loc.getGeometry().getData(); List<Double> locationData = loc.getGeometry().getData();
if (locationData != null) { if (locationData != null) {
int locationDataCount = locationData.size();
SenseBoxLocation location = new SenseBoxLocation(); SenseBoxLocation location = new SenseBoxLocation();
if (locationData.size() > 0) { if (locationDataCount > 0) {
location.setLongitude(locationData.get(0)); location.setLongitude(locationData.get(0));
} }
if (locationData.size() > 1) { if (locationDataCount > 1) {
location.setLatitude(locationData.get(1)); location.setLatitude(locationData.get(1));
} }
if (locationData.size() > 2) { if (locationDataCount > 2) {
location.setHeight(locationData.get(2)); location.setHeight(locationData.get(2));
} }

View File

@ -949,7 +949,7 @@ public class ShellyBaseHandler extends BaseThingHandler implements ShellyDeviceL
public boolean updateWakeupReason(@Nullable List<Object> valueArray) { public boolean updateWakeupReason(@Nullable List<Object> valueArray) {
boolean changed = false; boolean changed = false;
if ((valueArray != null) && (valueArray.size() > 0)) { if (valueArray != null && !valueArray.isEmpty()) {
String reason = getString((String) valueArray.get(0)); String reason = getString((String) valueArray.get(0));
String newVal = valueArray.toString(); String newVal = valueArray.toString();
changed = updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_WAKEUP, getStringType(reason)); changed = updateChannel(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_WAKEUP, getStringType(reason));

View File

@ -492,7 +492,7 @@ public class ShellyLightHandler extends ShellyBaseHandler {
logger.debug("{}: Setting effect to {}", thingName, newCol.effect); logger.debug("{}: Setting effect to {}", thingName, newCol.effect);
parms.put(SHELLY_COLOR_EFFECT, newCol.effect.toString()); parms.put(SHELLY_COLOR_EFFECT, newCol.effect.toString());
} }
if (parms.size() > 0) { if (!parms.isEmpty()) {
logger.debug("{}: Send light settings: {}", thingName, parms); logger.debug("{}: Send light settings: {}", thingName, parms);
api.setLightParms(lightId, parms); api.setLightParms(lightId, parms);
updateCurrentColors(lightId, newCol); updateCurrentColors(lightId, newCol);

View File

@ -130,7 +130,7 @@ public class PhonebookProfileFactory implements ProfileFactory, ProfileTypeProvi
thingName + " - " + phonebook.getName())) thingName + " - " + phonebook.getName()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (parameterOptions.size() > 0) { if (!parameterOptions.isEmpty()) {
parameterOptions.add(new ParameterOption(thingUid, thingName)); parameterOptions.add(new ParameterOption(thingUid, thingName));
} }

View File

@ -375,7 +375,7 @@ public class UpnpXMLParser {
entries.add(new UpnpEntry(id, refId, parentId, upnpClass.toString()).withTitle(title.toString()) entries.add(new UpnpEntry(id, refId, parentId, upnpClass.toString()).withTitle(title.toString())
.withAlbum(album.toString()).withAlbumArtUri(albumArtUri.toString()) .withAlbum(album.toString()).withAlbumArtUri(albumArtUri.toString())
.withCreator(creator.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) .withPublisher(publisher.toString()).withGenre(genre.toString()).withTrackNumber(trackNumberVal)
.withResList(resList)); .withResList(resList));

View File

@ -243,7 +243,7 @@ public class VigiCruesHandler extends BaseThingHandler {
} }
private void updateRelativeMeasure(String channelId, List<QuantityType<?>> reference, double value) { private void updateRelativeMeasure(String channelId, List<QuantityType<?>> reference, double value) {
if (reference.size() > 0) { if (!reference.isEmpty()) {
double percent = value / reference.get(0).doubleValue() * 100; double percent = value / reference.get(0).doubleValue() * 100;
updateQuantity(channelId, percent, Units.PERCENT); updateQuantity(channelId, percent, Units.PERCENT);
} }

View File

@ -92,7 +92,7 @@ public class Status extends VocAnswer {
} }
public boolean aFailedBulb() { public boolean aFailedBulb() {
return bulbFailures.size() > 0; return !bulbFailures.isEmpty();
} }
/* /*

View File

@ -91,7 +91,7 @@ public class WlanThermoEsp32CommandHandler {
} }
} else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) {
int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; 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); Channel channel = channelList.get(channelId);
switch (channelUID.getIdWithoutGroup()) { switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_NAME: case CHANNEL_NAME:
@ -176,7 +176,7 @@ public class WlanThermoEsp32CommandHandler {
if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) {
int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; 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); Channel channel = channelList.get(channelId);
switch (channelUID.getIdWithoutGroup()) { switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_NAME: case CHANNEL_NAME:
@ -283,7 +283,7 @@ public class WlanThermoEsp32CommandHandler {
if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) {
int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; 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); Channel channel = channelList.get(channelId);
if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) {
if (channel.getTemp() != 999) { if (channel.getTemp() != 999) {

View File

@ -81,7 +81,7 @@ public class WlanThermoNanoV1CommandHandler {
} }
} else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) {
int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; 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); Channel channel = channelList.get(channelId);
switch (channelUID.getIdWithoutGroup()) { switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_NAME: case CHANNEL_NAME:
@ -165,7 +165,7 @@ public class WlanThermoNanoV1CommandHandler {
if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) {
int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; 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); Channel channel = channelList.get(channelId);
switch (channelUID.getIdWithoutGroup()) { switch (channelUID.getIdWithoutGroup()) {
case CHANNEL_NAME: case CHANNEL_NAME:
@ -266,7 +266,7 @@ public class WlanThermoNanoV1CommandHandler {
if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { if (channelUID.getId().startsWith(CHANNEL_PREFIX)) {
int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; 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); Channel channel = channelList.get(channelId);
if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) {
if (channel.getTemp() != 999) { if (channel.getTemp() != 999) {

View File

@ -671,7 +671,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService {
public boolean isValid() { // a valid configuration must be initialized public boolean isValid() { // a valid configuration must be initialized
// and contain at least one function // and contain at least one function
return (isInitialized && (archives.size() > 0)); return isInitialized && !archives.isEmpty();
} }
@Override @Override