Skip to content

Commit 7aa17a6

Browse files
Rohit Singh BhojakRohit Singh Bhojak
Rohit Singh Bhojak
authored and
Rohit Singh Bhojak
committed
Refactor Java code to comply with SonarCloud rule S1155
Replaced instances of collection.size() < 1 with collection.isEmpty(), and collection.size() >= 1 with !collection.isEmpty().
1 parent c1610a0 commit 7aa17a6

File tree

10 files changed

+17
-12
lines changed

10 files changed

+17
-12
lines changed

java/code/src/com/redhat/rhn/frontend/action/configuration/sdc/FileListConfirmSubmitAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ActionForward importFile(ActionMapping mapping, ActionForm formIn,
102102
RhnSet set = RhnSetDecl.CONFIG_IMPORT_FILE_NAMES.get(user);
103103
Set cfnids = getCfnids(set);
104104
//if they don't have a set, don't do anything.
105-
if (cfnids.size() < 1) {
105+
if (cfnids.isEmpty()) {
106106
return createErrorMessage(request, mapping, formIn, server.getId(),
107107
"sdcfilelist.jsp.noSelected");
108108
}
@@ -173,7 +173,7 @@ private ActionForward createRevisionAction(HttpServletRequest request, ActionFor
173173
RhnSet set = RhnSetDecl.CONFIG_FILE_NAMES.get(user);
174174
Set revisions = getCrids(set, sid);
175175
//if they don't have a set, don't do anything.
176-
if (revisions.size() < 1) {
176+
if (revisions.isEmpty()) {
177177
return createErrorMessage(request, mapping, form, sid,
178178
"sdcfilelist.jsp.noSelected");
179179
}

java/code/src/com/redhat/rhn/frontend/action/configuration/sdc/FileListSubmitAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public ActionForward goToConfirm(ActionMapping mapping,
9393
HttpServletRequest request,
9494
HttpServletResponse response) {
9595
//They didn't select anything. Tell them to select something.
96-
if (updateSet(request).size() < 1) {
96+
if (updateSet(request).isEmpty()) {
9797
ActionErrors errors = new ActionErrors();
9898
errors.add(ActionMessages.GLOBAL_MESSAGE,
9999
new ActionMessage("sdcfilelist.jsp.noSelected"));

java/code/src/com/redhat/rhn/frontend/action/systems/SPMigrationAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public ActionForward execute(ActionMapping actionMapping,
282282
request.setAttribute(LATEST_SP, true);
283283
return forward;
284284
}
285-
else if (migrationTargets.size() >= 1) {
285+
else if (!migrationTargets.isEmpty()) {
286286
// At least one target available
287287
logger.debug("Found at least one migration target");
288288
request.setAttribute(TARGET_PRODUCTS, migrationTargets);

java/code/src/com/redhat/rhn/frontend/xmlrpc/user/UserHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ public int addAssignedSystemGroups(User loggedInUser, String login, List<String>
996996
User targetUser = XmlRpcUserHelper.getInstance().lookupTargetUser(
997997
loggedInUser, login);
998998

999-
if (sgNames == null || sgNames.size() < 1) {
999+
if (sgNames == null || sgNames.isEmpty()) {
10001000
throw new IllegalArgumentException("no servergroup names supplied");
10011001
}
10021002

java/code/src/com/redhat/rhn/manager/action/ActionManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static Action lookupAction(User user, Long aid) {
233233
params.put("org_id", user.getOrg().getId());
234234
params.put("aid", aid);
235235
params.put("include_orphans", user.hasRole(RoleFactory.ORG_ADMIN) ? "Y" : "N");
236-
if (m.execute(params).size() < 1) {
236+
if (m.execute(params).isEmpty()) {
237237
returnedAction = null;
238238
}
239239

@@ -577,7 +577,7 @@ public static Action createConfigUploadAction(User user, Set filenames, Server s
577577
}
578578

579579
//if this is a pointless action, don't do it.
580-
if (a.getConfigFileNameAssociations().size() < 1) {
580+
if (a.getConfigFileNameAssociations().isEmpty()) {
581581
return null;
582582
}
583583

java/code/src/com/redhat/rhn/manager/audit/CVEAuditManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public static List<RankedChannel> addRelevantMigrationProductChannels(
519519

520520
// ...if it has a target with that base product...
521521
List<SUSEProductDto> targets = findAllTargetProducts(suseProductID);
522-
if (log.isDebugEnabled() && targets.size() <= 0) {
522+
if (log.isDebugEnabled() && targets.isEmpty()) {
523523
log.debug("No target products found for {}", suseProductID);
524524
}
525525
for (SUSEProductDto target : targets) {
@@ -552,7 +552,7 @@ public static List<RankedChannel> addRelevantMigrationProductChannels(
552552

553553
// ...if it has a source with that base product...
554554
List<SUSEProductDto> sources = findAllSourceProducts(suseProductID);
555-
if (log.isDebugEnabled() && sources.size() <= 0) {
555+
if (log.isDebugEnabled() && sources.isEmpty()) {
556556
log.debug("No source products found for {}", suseProductID);
557557
}
558558
for (SUSEProductDto source : sources) {

java/code/src/com/redhat/rhn/manager/system/SystemManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ public static boolean isAvailableToUser(User user, Long sid) {
23272327
Map<String, Object> params = new HashMap<>();
23282328
params.put("uid", user.getId());
23292329
params.put("sid", sid);
2330-
return m.execute(params).size() >= 1;
2330+
return !m.execute(params).isEmpty();
23312331
}
23322332

23332333
/**

java/code/src/com/suse/manager/webui/controllers/SSOController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static Object getACS(Request request, Response response) {
109109

110110
final Collection<String> keys = attributes.keySet();
111111

112-
if (keys.contains((String) "uid") && attributes.get("uid").size() >= 1) {
112+
if (keys.contains((String) "uid") && !attributes.get("uid").isEmpty()) {
113113
final Optional uidOpt = Optional.ofNullable(attributes.get("uid").get(0));
114114
if (uidOpt.isPresent()) {
115115
final User user = UserFactory.lookupByLogin(String.valueOf(uidOpt.get()));

java/code/src/com/suse/utils/Lists.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private static <T> List<List<T>> combinations(List<List<T>> acc, List<T> list)
5050
* @return cartesian product of the input
5151
*/
5252
public static <T> List<List<T>> combinations(List<List<T>> lists) {
53-
if (lists.size() < 1) {
53+
if (lists.isEmpty()) {
5454
return new ArrayList<>();
5555
}
5656
else {

java/spacewalk-java.changes

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
-------------------------------------------------------------------
2+
Tue Mar 18 16:01:30 UTC 2025 - Rohit Singh Bhojak <rohit@localhost>
3+
4+
- Fixed SonarCloud Rule S1155 violations (gh#uyuni-project/uyuni#9947)
5+
16
-------------------------------------------------------------------
27
Thu Mar 06 19:57:20 CET 2025 - [email protected]
38

0 commit comments

Comments
 (0)