Skip to content

Commit

Permalink
Use Collection.isEmpty (openhab#10525)
Browse files Browse the repository at this point in the history
Fixes 47 SAT UseCollectionIsEmpty findings.

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn authored and thinkingstone committed Nov 7, 2021
1 parent 8ca51ce commit 8c1ec3e
Show file tree
Hide file tree
Showing 35 changed files with 67 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ private void renderBluetoothMacChannel(Connection connection, Device device, Str
if ((stateDeviceSerialNumber == null && device.serialNumber == null)
|| (stateDeviceSerialNumber != null && stateDeviceSerialNumber.equals(device.serialNumber))) {
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>");
for (PairedDevice pairedDevice : pairedDeviceList) {
html.append("<tr><td>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ synchronized void setSmartHomeDevices(List<SmartHomeBaseDevice> deviceList) {
}
Set<SmartHomeDevice> supportedChildren = SmartHomeDeviceHandler.getSupportedSmartHomeDevices(shg,
deviceList);
if (supportedChildren.size() == 0) {
if (supportedChildren.isEmpty()) {
// No children with an supported interface
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public void run() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void updateBattery(BatteryModel batteryModel) {
}

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 lastPressedButton = shortPressButton != null && (longPressButton == null
|| shortPressButton.getLastpressedtimestamp() > longPressButton.getLastpressedtimestamp())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
Collection<ComfoAirCommand> affectedReadCommands = ComfoAirCommandType
.getAffectedReadCommands(channelId, keysToUpdate);

if (affectedReadCommands.size() > 0) {
if (!affectedReadCommands.isEmpty()) {
Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands);
affectedItemsPoller = scheduler.schedule(updateThread, 3, TimeUnit.SECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ private State getHotWaterOverride() {

private State getHotWaterDemandState() {
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() {
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() {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Entry<String, CosemValueDescriptor<?>> getDescriptor(int idx) {
* @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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private DiscoveryResult createThermostatDiscoveryResult(ThingUID thermostatUID,

private synchronized void discoverSensors() {
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");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,37 +213,39 @@ private void updateDirectionChannel(ChannelUID channelUID, int i) {
if (processedData.size() > i) {
State state = UnDefType.UNDEF;
List<String> departures = processedData.get(i).departures;
int departuresCount = departures.size();
List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void testOnlineCommunication() {
@Nullable
List<ShadeData> shadesData = shadesX.shadeData;
assertNotNull(shadesData);
assertTrue(shadesData.size() > 0);
assertTrue(!shadesData.isEmpty());
@Nullable
ShadeData shadeData;
shadeData = shadesData.get(0);
Expand Down Expand Up @@ -198,7 +198,7 @@ public void testOnlineCommunication() {
@Nullable
List<Scene> scenesData = scenes.sceneData;
assertNotNull(scenesData);
assertTrue(scenesData.size() > 0);
assertTrue(!scenesData.isEmpty());
@Nullable
Scene sceneZero = scenesData.get(0);
assertNotNull(sceneZero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ public void testCommandTagCode() {
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<CommandTag> 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected synchronized boolean updateAlarmStatus() {
}

List<JablotronHistoryDataEvent> events = sendGetEventHistory();
if (events != null && events.size() > 0) {
if (events != null && !events.isEmpty()) {
JablotronHistoryDataEvent event = events.get(0);
updateLastEvent(event);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ protected void updateLastEvent(JablotronHistoryDataEvent event) {

protected void updateEventChannel(String channel) {
List<JablotronHistoryDataEvent> 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -181,7 +179,7 @@ protected synchronized boolean updateAlarmStatus() {

// update events
List<JablotronHistoryDataEvent> events = sendGetEventHistory();
if (events != null && events.size() > 0) {
if (events != null && !events.isEmpty()) {
JablotronHistoryDataEvent event = events.get(0);
updateLastEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -199,7 +197,7 @@ private void processThermostat(JablotronServiceDetailSegment segment) {

private void updateTemperatureChannel(Channel channel, JablotronServiceDetailSegment segment) {
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());
updateState(channel.getUID(), QuantityType.valueOf(infos.get(0).getValue(), SIUnits.CELSIUS));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ private void updateStateValue(LxStateUpdate update) {

state.setStateValue(update.getValue());
});
if (perStateUuid.size() == 0) {
if (perStateUuid.isEmpty()) {
logger.debug("[{}] State update UUID={} has empty controls table", debugId, update.getUuid());
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
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;
Expand Down Expand Up @@ -108,8 +108,8 @@ public void addChannelType(MiIoBasicChannel miChannel, String model) {
if (category != null) {
channelTypeBuilder.withCategory(category);
}
final LinkedHashSet<String> tags = miChannel.getTags();
if (tags != null && tags.size() > 0) {
final Set<String> tags = miChannel.getTags();
if (tags != null && !tags.isEmpty()) {
channelTypeBuilder.withTags(tags);
}
channelTypes.put(channelTypeUID.getAsString(), channelTypeBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
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;
Expand Down Expand Up @@ -471,8 +471,8 @@ private boolean buildChannelStructure(String deviceName) {
ChannelTypeUID channelTypeUID = new ChannelTypeUID(miChannel.getChannelType());
if (channelTypeRegistry.getChannelType(channelTypeUID) != null) {
newChannel = newChannel.withType(channelTypeUID);
final LinkedHashSet<String> tags = miChannel.getTags();
if (tags != null && tags.size() > 0) {
final Set<String> tags = miChannel.getTags();
if (tags != null && !tags.isEmpty()) {
newChannel.withDefaultTags(tags);
}
} else {
Expand All @@ -485,8 +485,8 @@ private boolean buildChannelStructure(String deviceName) {
if (useGeneratedChannelType) {
newChannel = newChannel
.withType(new ChannelTypeUID(BINDING_ID, model.toUpperCase().replace(".", "_") + "_" + channel));
final LinkedHashSet<String> tags = miChannel.getTags();
if (tags != null && tags.size() > 0) {
final Set<String> tags = miChannel.getTags();
if (tags != null && !tags.isEmpty()) {
newChannel.withDefaultTags(tags);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void finishChannelTest() {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void drawMap(Graphics2D g2d, float scale) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static String readmeOptionMapping(MiIoBasicChannel channel, String model)
StateDescriptionDTO stateDescription = channel.getStateDescription();
if (stateDescription != null && stateDescription.getOptions() != null) {
final List<OptionsValueListDTO> 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) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public synchronized NeoHubReturnResult toNeoHubSendChannelValue(String commandSt

@Nullable
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");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public List<Float> getStationMeasureResponses(String equipmentId, @Nullable Stri
.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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void handleThermostatRefresh(Thermostat thermostat) {
*/
public @Nullable Thermostat tryHandleAndGetUpdatedThermostat() {
final LinkedList<SimpleImmutableEntry<String, Command>> updatedValues = this.updatedValues;
if (updatedValues.size() == 0) {
if (updatedValues.isEmpty()) {
return null;
}
this.updatedValues = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private boolean createChannels(List<RemoteopenhabItem> items, boolean replace) {
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) {
Expand Down Expand Up @@ -319,7 +319,7 @@ private void setStateOptions(List<RemoteopenhabItem> items) {
Channel channel = getThing().getChannel(item.name);
RemoteopenhabStateDescription descr = item.stateDescription;
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<>();
for (RemoteopenhabStateOption option : options) {
stateOptions.add(new StateOption(option.value, option.label));
Expand Down
Loading

0 comments on commit 8c1ec3e

Please sign in to comment.