Method setValueItem
has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
public SimpleKeyValueList<K, V> setValueItem(Object key, Object value) {
int pos = indexOf(key);
if (pos >= 0) {
this.setValue(pos, (V) value);
- 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
File SimpleKeyValueList.java
has 537 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser.list;
/*
NetworkParser
The MIT License
SimpleKeyValueList
has 49 methods (exceeds 20 allowed). Consider refactoring. Open
public class SimpleKeyValueList<K, V> extends AbstractArray<K> implements Map<K, V>, Iterable<Entry<K, V>> {
private Comparator<Object> cpr;
public SimpleKeyValueList() {
super();
Method setValueItem
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
public SimpleKeyValueList<K, V> setValueItem(Object key, Object value) {
int pos = indexOf(key);
if (pos >= 0) {
this.setValue(pos, (V) value);
Method replaceAllValues
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
@Override
public void replaceAllValues(Object key, String search, String replace) {
if (key == null) {
return;
}
- 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 withKeyValueString
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public SimpleKeyValueList<K, V> withKeyValueString(String keyValue, Class<?> valueType) {
int pos = 0, start;
String key, value;
char item;
do {
- 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 increment
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public SimpleKeyValueList<K, V> increment(K key) {
Object value = this.get(key);
if (value == null) {
setValueItem(key, 1);
return this;
Method increment
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public SimpleKeyValueList<K, V> increment(K key) {
Object value = this.get(key);
if (value == null) {
setValueItem(key, 1);
return this;
- 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 withKeyValueString
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public SimpleKeyValueList<K, V> withKeyValueString(String keyValue, Class<?> valueType) {
int pos = 0, start;
String key, value;
char item;
do {
Avoid deeply nested control flow statements. Open
if (list.size() >= id) {
if (value == null) {
list.remove(id);
} else {
list.set(id, value);
Avoid deeply nested control flow statements. Open
if (id == -2) {
id = list.size() - 1;
}
Avoid too many return
statements within this method. Open
return this;
Avoid too many return
statements within this method. Open
return this;
Method addToKeyValue
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public SimpleKeyValueList<K, V> addToKeyValue(Object key, Number value) {
int pos = hasKeyAndPos(key);
if (pos < 0) {
return this;
}
- 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 getBoolean
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public boolean getBoolean(K key) throws SimpleException {
Object value = get(key);
if (Boolean.FALSE.equals(value) || (value instanceof String && "false".equalsIgnoreCase((String) value))) {
return false;
- 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
Ensure you override both equals() and hashCode() Open
public boolean equals(Object obj) {
- Read upRead up
- Exclude checks
OverrideBothEqualsAndHashcode
Since: PMD 0.4
Priority: Medium
Categories: Style
Remediation Points: 50000
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
Example:
public class Bar { // poor, missing a hashcode() method
public boolean equals(Object o) {
// do some comparison
}
}
public class Baz { // poor, missing an equals() method
public int hashCode() {
// return some hash value
}
}
public class Foo { // perfect, both methods provided
public boolean equals(Object other) {
// do some comparison
}
public int hashCode() {
// return some hash value
}
}