You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is code duplication in the DefaultRedisList methods. Specifically, the usage of listOps.rightPush/leftPush followed by a call to cap() is repeated in multiple places. This can be refactored to enhance code maintainability and readability.
@Overridepublicvoidadd(intindex, Eelement) {
if (index == 0) {
listOps.leftPush(element);
cap();
return;
}
intsize = size();
if (index == size()) {
listOps.rightPush(element);
cap();
return;
}
if (index < 0 || index > size) {
thrownewIndexOutOfBoundsException();
}
thrownewIllegalArgumentException("Redis supports insertion only at the beginning or the end of the list");
}
Proposed Solution:
To enhance consistency and readability, I propose refactoring the method names to addFirst and addLast. This will provide a clear indication of where the element is being added, compared to the more generic add.
AS-IS
@Overridepublicvoidadd(intindex, Eelement) {
if (index == 0) {
listOps.leftPush(element);
cap();
return;
}
intsize = size();
if (index == size()) {
listOps.rightPush(element);
cap();
return;
}
if (index < 0 || index > size) {
thrownewIndexOutOfBoundsException();
}
thrownewIllegalArgumentException("Redis supports insertion only at the beginning or the end of the list");
}
TO-BE
@Overridepublicvoidadd(intindex, Eelement) {
if (index == 0) {
addFirst(element);
return;
}
intsize = size();
if (index == size()) {
addLast(element);
return;
}
if (index < 0 || index > size) {
thrownewIndexOutOfBoundsException();
}
thrownewIllegalArgumentException("Redis supports insertion only at the beginning or the end of the list");
}
The text was updated successfully, but these errors were encountered:
There is code duplication in the DefaultRedisList methods. Specifically, the usage of listOps.rightPush/leftPush followed by a call to cap() is repeated in multiple places. This can be refactored to enhance code maintainability and readability.
Proposed Solution:
To enhance consistency and readability, I propose refactoring the method names to addFirst and addLast. This will provide a clear indication of where the element is being added, compared to the more generic add.
AS-IS
TO-BE
The text was updated successfully, but these errors were encountered: