Method checkValues
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
private int checkValues(Object v1, Object v2) {
if (v1 instanceof String) {
String valueA = (String) v1;
if (v2 != null) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method checkValues
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
private int checkValues(Object v1, Object v2) {
if (v1 instanceof String) {
String valueA = (String) v1;
if (v2 != null) {
Method checkIntern
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private int checkIntern(Object o1, Object o2) {
/* SAME OBJECT MUST BE 0 */
if (o2 == null) {
if (o1 == null) {
return 0;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method compareValue
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public int compareValue(Object o1, Object o2) {
if (VALUES.equals(column)) {
return checkValues(o1, o2);
}
if (map != null) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return v1.compareTo(v2);
Avoid too many return
statements within this method. Open
return -1;
Avoid too many return
statements within this method. Open
return owner.indexOf(o1) - owner.indexOf(o2);
Avoid too many return
statements within this method. Open
return ((Comparable<Object>) v2).compareTo(v1);
Avoid too many return
statements within this method. Open
return checkValues(v2, v1) * -1;
Avoid too many return
statements within this method. Open
return -1;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return -1;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return -1;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return 1;
These nested if statements could be combined Open
if (v2 instanceof Comparable<?>) {
return ((Comparable<Object>) v2).compareTo(v1);
}
- Read upRead up
- Exclude checks
CollapsibleIfStatements
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
Example:
void bar() {
if (x) { // original implementation
if (y) {
// do stuff
}
}
}
void bar() {
if (x && y) { // optimized implementation
// do stuff
}
}