File DateTimeEntity.java
has 452 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser;
import java.util.Date;
/*
DateTimeEntity
has 40 methods (exceeds 20 allowed). Consider refactoring. Open
public class DateTimeEntity implements SendableEntityCreatorNoIndex {
public static final String W3CDTF_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
private boolean dirty;
private Long time;
private Byte timeZone = 1;
Method internCalculate
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
private boolean internCalculate(long time, boolean calc) {
long years = time / ONE_YEAR + 1970;
long schaltjahre = ((years - 1) - 1968) / 4 - ((years - 1) - 1900) / 100 + ((years - 1) - 1600) / 400;
long yearMillis = (time - (schaltjahre - 1) * ONE_DAY) % ONE_YEAR;
int year = (int) ((time - schaltjahre * ONE_DAY) / ONE_YEAR) + 1970;
- 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 internCalculate
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
private boolean internCalculate(long time, boolean calc) {
long years = time / ONE_YEAR + 1970;
long schaltjahre = ((years - 1) - 1968) / 4 - ((years - 1) - 1900) / 100 + ((years - 1) - 1600) / 400;
long yearMillis = (time - (schaltjahre - 1) * ONE_DAY) % ONE_YEAR;
int year = (int) ((time - schaltjahre * ONE_DAY) / ONE_YEAR) + 1970;
Method toString
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public String toString(String format) {
initDate();
calculate();
CharacterBuffer sb = new CharacterBuffer();
String sub;
- 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 toString
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
public String toString(String format) {
initDate();
calculate();
CharacterBuffer sb = new CharacterBuffer();
String sub;
Method getValueInMillisecond
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public long getValueInMillisecond(String field) {
if (fields == null || field == null) {
return 0;
}
Object result = fields.get(field);
- 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 getValueInMillisecond
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public long getValueInMillisecond(String field) {
if (fields == null || field == null) {
return 0;
}
Object result = fields.get(field);
Avoid too many return
statements within this method. Open
return value * DateTimeEntity.ONE_SECOND;
Avoid too many return
statements within this method. Open
return value * DateTimeEntity.ONE_HOUR;
Avoid too many return
statements within this method. Open
return value * DateTimeEntity.ONE_DAY;
Avoid too many return
statements within this method. Open
return value * DateTimeEntity.ONE_MINUTE;
Avoid too many return
statements within this method. Open
return value;
Avoid too many return
statements within this method. Open
return 0;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return value * (DateTimeEntity.ONE_DAY / 2);
Method initDate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private void initDate() {
if (items != null && !isInitConstants) {
/* Month */
for (int i = 0; i < 12; i++) {
monthOfYear[i] = items.getText(monthOfYear[i], this, 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
FIXME found Open
/* FIXME Change String to StringContainter */
- Exclude checks
These nested if statements could be combined Open
if ((7 - dayOfWeek) < leftDays) {
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
}
}