Method decodeValue
has a Cognitive Complexity of 78 (exceeds 5 allowed). Consider refactoring. Open
public Object decodeValue(byte type, Buffer buffer, int end, MapEntity map) {
if (buffer == null || buffer.remaining() < 1) {
return null;
}
if (type == ByteTokener.DATATYPE_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 decodeValue
has 149 lines of code (exceeds 25 allowed). Consider refactoring. Open
public Object decodeValue(byte type, Buffer buffer, int end, MapEntity map) {
if (buffer == null || buffer.remaining() < 1) {
return null;
}
if (type == ByteTokener.DATATYPE_NULL) {
File ByteTokener.java
has 397 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser.bytes;
/*
NetworkParser
The MIT License
Method encodeValue
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public ByteItem encodeValue(Object value, MapEntity filter) {
ByteEntity msgEntity = new ByteEntity();
if (msgEntity.setValues(value)) {
return msgEntity;
} else {
- 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 encode
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
@Override
public ByteItem encode(Object entity, MapEntity map) {
SendableEntityCreator creator = getCreatorClass(entity);
if (creator == null) {
return 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 decodeClazz
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public Object decodeClazz(Buffer buffer, SendableEntityCreator eventCreater, MapEntity map) {
if (eventCreater == null) {
ByteMessage e = new ByteMessage();
if (buffer != null)
e.withValue(buffer.array(-1, true));
- 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 encode
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public ByteItem encode(Object entity, MapEntity map) {
SendableEntityCreator creator = getCreatorClass(entity);
if (creator == null) {
return null;
Method addClazzType
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private boolean addClazzType(ByteList msg, String clazzName, MapEntity map) {
if (map == null || clazzName == null) {
return false;
}
try {
- 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 encodeValue
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public ByteItem encodeValue(Object value, MapEntity filter) {
ByteEntity msgEntity = new ByteEntity();
if (msgEntity.setValues(value)) {
return msgEntity;
} else {
Method addClazzType
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private boolean addClazzType(ByteList msg, String clazzName, MapEntity map) {
if (map == null || clazzName == null) {
return false;
}
try {
Method decodeClazz
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public Object decodeClazz(Buffer buffer, SendableEntityCreator eventCreater, MapEntity map) {
if (eventCreater == null) {
ByteMessage e = new ByteMessage();
if (buffer != null)
e.withValue(buffer.array(-1, true));
Avoid deeply nested control flow statements. Open
for (Iterator<?> i = list.iterator(); i.hasNext();) {
Object item = i.next();
eventCreater.setValue(entity, property, item, SendableEntityCreator.NEW);
}
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return new Date(buffer.getLong());
Avoid too many return
statements within this method. Open
return decodeClazz(buffer, eventCreater, map);
Avoid too many return
statements within this method. Open
return values;
Avoid too many return
statements within this method. Open
return values;
Avoid too many return
statements within this method. Open
return Short.valueOf(buffer.getShort());
Avoid too many return
statements within this method. Open
return buffer.array(len, false);
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return decodeClazz(buffer, eventCreater, map);
Avoid too many return
statements within this method. Open
return "";
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return values;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return Float.valueOf(buffer.getFloat());
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return decodeClazz(buffer, eventCreater, map);
Avoid too many return
statements within this method. Open
return decodeClazz(buffer, eventCreater, map);
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return new String(buffer.array(len, false), getCharset());
Avoid too many return
statements within this method. Open
return decodeClazz(buffer, eventCreater, map);
Avoid too many return
statements within this method. Open
return Long.valueOf(buffer.getLong());
Avoid too many return
statements within this method. Open
return Integer.valueOf(buffer.getInt());
Avoid too many return
statements within this method. Open
return Double.valueOf(buffer.getDouble());
Avoid too many return
statements within this method. Open
return map.getVisitedObjects(pos);
Avoid too many return
statements within this method. Open
return map.getVisitedObjects(pos);
These nested if statements could be combined Open
if (clazzName.substring(0, pos).equals(lastClazz.substring(0, pos))) {
byte[] bytes = clazzName.substring(pos + 1).getBytes(getCharset());
msg.add(new ByteEntity().withValue(DATATYPE_CLAZZPACKAGE, bytes));
return true;
}
- 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
}
}