Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use isEmpty instead of 0 comparisons #3999

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -518,7 +518,7 @@ private Response getServiceItemList(@Nullable String serviceId) {
private Response deletePersistenceItemData(@Nullable String serviceId, String itemName, @Nullable String timeBegin,
@Nullable String timeEnd) {
// For deleting, we must specify a service id - don't use the default service
if (serviceId == null || serviceId.length() == 0) {
if (serviceId == null || serviceId.isEmpty()) {
logger.debug("Persistence service must be specified for delete operations.");
return JSONResponse.createErrorResponse(Status.BAD_REQUEST,
"Persistence service must be specified for delete operations.");
Expand Down Expand Up @@ -598,7 +598,7 @@ private Response putItemState(@Nullable String serviceId, String itemName, Strin
}

ZonedDateTime dateTime = null;
if (time != null && time.length() != 0) {
if (time != null && !time.isEmpty()) {
dateTime = convertTime(time);
}
if (dateTime == null || dateTime.toEpochSecond() == 0) {
Expand Down
Expand Up @@ -92,7 +92,7 @@ private WriteRequestJsonUtilities() {
*/
public static Collection<ModbusWriteRequestBlueprint> fromJson(int unitId, String jsonString) {
JsonArray jsonArray = JsonParser.parseString(jsonString).getAsJsonArray();
if (jsonArray.size() == 0) {
if (jsonArray.isEmpty()) {
return new LinkedList<>();
}
Deque<ModbusWriteRequestBlueprint> writes = new LinkedList<>();
Expand Down Expand Up @@ -173,7 +173,7 @@ private static ModbusWriteRequestBlueprint constructBluerint(int unitId, @Nullab
}
// fall-through to WRITE_MULTIPLE_COILS
case WRITE_MULTIPLE_COILS:
if (valuesElem.size() == 0) {
if (valuesElem.isEmpty()) {
throw new IllegalArgumentException("Must provide at least one coil");
} else if (valuesElem.size() > ModbusConstants.MAX_BITS_WRITE_COUNT) {
throw new IllegalArgumentException(
Expand Down
Expand Up @@ -55,7 +55,7 @@ public class MqttBrokerConnectionConfig {
*/
public String getBrokerID() {
final String name = this.name;
if (name != null && name.length() > 0) {
if (name != null && !name.isEmpty()) {
return name;
} else {
StringBuilder b = new StringBuilder();
Expand Down
Expand Up @@ -267,7 +267,7 @@ public void removeModelRepositoryChangeListener(ModelRepositoryChangeListener li
.append(MessageFormat.format("[{0},{1}]: {2}\n", Integer.toString(diagnostic.getLine()),
Integer.toString(diagnostic.getColumn()), diagnostic.getMessage()));
}
if (criticalErrors.length() > 0) {
if (!criticalErrors.isEmpty()) {
return criticalErrors.toString();
}

Expand Down
Expand Up @@ -134,7 +134,7 @@ public String getMessage() {

int i = 1;
for (ScriptError e : getErrors()) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append('\n');
}
sb.append(" ");
Expand Down
Expand Up @@ -736,7 +736,7 @@ private String transform(String label, boolean matchTransform, @Nullable String

@Override
public @Nullable Widget getWidget(Sitemap sitemap, String id) {
if (id.length() > 0) {
if (!id.isEmpty()) {
// see if the id is an itemName and try to get the widget for it
Widget w = getWidget(id);
if (w == null) {
Expand Down
Expand Up @@ -336,7 +336,7 @@ public ExpireConfig(Item item, String configString, Map<String, Object> configur
ignoreStateUpdates = getBooleanConfigValue(configuration, CONFIG_IGNORE_STATE_UPDATES);
ignoreCommands = getBooleanConfigValue(configuration, CONFIG_IGNORE_COMMANDS);

if ((stateOrCommand != null) && (stateOrCommand.length() > 0)) {
if ((stateOrCommand != null) && (!stateOrCommand.isEmpty())) {
if (stateOrCommand.startsWith(COMMAND_PREFIX)) {
String commandString = stateOrCommand.substring(COMMAND_PREFIX.length());
expireCommand = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandString);
Expand Down
Expand Up @@ -129,7 +129,7 @@ public class StringUtils {
final String delimiter = "_";
StringBuilder capitalizedFully = new StringBuilder();
for (String splitStr : str.split(delimiter)) {
if (splitStr.length() > 0) {
if (!splitStr.isEmpty()) {
capitalizedFully.append(splitStr.substring(0, 1).toUpperCase());
}
if (splitStr.length() > 1) {
Expand Down
Expand Up @@ -249,7 +249,7 @@ private boolean areThreadsFromPoolRunning(String poolName) {
for (int i = 0; i < n; i++) {
// we can only test if name is at least one character,
// otherwise there will be threads found (handles poolName="")
if (poolName.length() > 0) {
if (!poolName.isEmpty()) {
if (l[i].getName().startsWith(poolName)) {
// enable printout to see threads
// System.out.println("areThreadsFromPoolRunning: " +
Expand Down
Expand Up @@ -141,7 +141,7 @@ public void parametersWithOptionsAndFiltersShouldLoadProperly() throws Exception
private String join(Collection<?> elements, String separator) {
StringBuilder sb = new StringBuilder();
for (Object element : elements) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append(separator);
}
if (element != null) {
Expand Down