SiLeBAT/FSK-Lab

View on GitHub
org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java

Summary

Maintainability
F
3 days
Test Coverage

Method look4ParentNode has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

    private DefaultMutableTreeNode look4ParentNode(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final String code, final int[] cutSystem) {
        DefaultMutableTreeNode result = null;
        String key;
        if (cutSystem == null) {
            for (int i=code.length()-1;i>=0;i--) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 7 hrs to fix

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 setTable has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

      @SuppressWarnings("unchecked")
    private void setTable(final MyTable myT) {
        if (myT != null) {
            root = new DefaultMutableTreeNode(new MyDBTreeNode(0, "", "Codes", false, -1));            
        // Erst die Codetypen
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 4 hrs to fix

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 readDB has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    private void readDB(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final int codeSystemNum, final DefaultMutableTreeNode root, final String sql, final String tablename_codeSystem, int[] cutSystem) {
        myIDs[codeSystemNum].clear(); myCodes.clear();
        try {
              ResultSet rs = DBKernel.getResultSet(sql, false);
              if (rs.first()) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 4 hrs to fix

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 MyDBTreeModel.java has 328 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*******************************************************************************
 * Copyright (c) 2015 Federal Institute for Risk Assessment (BfR), Germany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 3 hrs to fix

Method setTable has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      @SuppressWarnings("unchecked")
    private void setTable(final MyTable myT) {
        if (myT != null) {
            root = new DefaultMutableTreeNode(new MyDBTreeNode(0, "", "Codes", false, -1));            
        // Erst die Codetypen
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 1 hr to fix

Method look4ParentNode has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private DefaultMutableTreeNode look4ParentNode(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final String code, final int[] cutSystem) {
        DefaultMutableTreeNode result = null;
        String key;
        if (cutSystem == null) {
            for (int i=code.length()-1;i>=0;i--) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 1 hr to fix

Method readDB has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private void readDB(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final int codeSystemNum, final DefaultMutableTreeNode root, final String sql, final String tablename_codeSystem, int[] cutSystem) {
        myIDs[codeSystemNum].clear(); myCodes.clear();
        try {
              ResultSet rs = DBKernel.getResultSet(sql, false);
              if (rs.first()) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 1 hr to fix

Method checkFilter has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    void checkFilter(final String filter) {
        this.filter = filter;
        if (filter.length() > 0) {
            setInvisible(root);
            StringTokenizer tok = new StringTokenizer(filter);
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 1 hr to fix

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 getTreeNode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    DefaultMutableTreeNode getTreeNode(final int id, final int codeSystemNum) {
        DefaultMutableTreeNode result = null;
        LinkedHashMap<Integer, DefaultMutableTreeNode>[] theIDs = (filter.length() > 0) ? myFilterIDs : myIDs;
        if (codeSystemNum >= 0 && codeSystemNum < theIDs.length) {
            result = theIDs[codeSystemNum].get(id);
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 1 hr to fix

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 checkVisibility has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    private void checkVisibility(final DefaultMutableTreeNode node, final String[] filter) {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode unfilteredChildNode = (DefaultMutableTreeNode) node.getChildAt(i);
            int j;
            for (j=0;j<filter.length;j++) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 55 mins to fix

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 populateFilteredNode has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    private void populateFilteredNode(final DefaultMutableTreeNode unfilteredNode, final DefaultMutableTreeNode filteredNode) {
    for (int i = 0; i < unfilteredNode.getChildCount(); i++) {
        DefaultMutableTreeNode unfilteredChildNode = (DefaultMutableTreeNode) unfilteredNode.getChildAt(i);

      if (((MyDBTreeNode) unfilteredChildNode.getUserObject()).isVisible()) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 55 mins to fix

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 createDTMN has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      private void createDTMN(String codeVec, MyTable myT, int lfd, int[] cutSystem) {
            boolean doIt = (showOnly == null);
            if (!doIt) {
                for (int j=0;j<showOnly.length;j++) {
                    if (showOnly[j] != null && showOnly[j].equals(codeVec)) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 45 mins to fix

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 readDB has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    private void readDB(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final int codeSystemNum, final DefaultMutableTreeNode root, final String sql, final String tablename_codeSystem, int[] cutSystem) {
Severity: Minor
Found in org.hsh.bfr.db/src/org/hsh/bfr/db/gui/dbtree/MyDBTreeModel.java - About 45 mins to fix

Refactor this method to reduce its Cognitive Complexity from 28 to the 15 allowed.
Open

    private void readDB(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final int codeSystemNum, final DefaultMutableTreeNode root, final String sql, final String tablename_codeSystem, int[] cutSystem) {

Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

See

Refactor this method to reduce its Cognitive Complexity from 48 to the 15 allowed.
Open

    private DefaultMutableTreeNode look4ParentNode(final LinkedHashMap<String, DefaultMutableTreeNode> myCodes, final String code, final int[] cutSystem) {

Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

See

Refactor this method to reduce its Cognitive Complexity from 28 to the 15 allowed.
Open

    private void setTable(final MyTable myT) {

Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

See

Define a constant instead of duplicating this literal "CodeSystem" 3 times.
Open

            String sql = "SELECT DISTINCT(" + DBKernel.delimitL("CodeSystem") + ") FROM " + DBKernel.delimitL(DBKernel.getCodesName(myT.getTablename()));

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

public void run() {
  prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
  execute("action1");
  release("action1");
}

@SuppressWarning("all")                            // Compliant - annotations are excluded
private void method1() { /* ... */ }
@SuppressWarning("all")
private void method2() { /* ... */ }

public String method3(String a) {
  System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
  return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
}

Compliant Solution

private static final String ACTION_1 = "action1";  // Compliant

public void run() {
  prepare(ACTION_1);                               // Compliant
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Define a constant instead of duplicating this literal "Basis" 3 times.
Open

                String sql = "SELECT " + DBKernel.delimitL("Code") + "," + DBKernel.delimitL("Basis") + "," + DBKernel.delimitL(myT.getFieldNames()[0]) +

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

public void run() {
  prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
  execute("action1");
  release("action1");
}

@SuppressWarning("all")                            // Compliant - annotations are excluded
private void method1() { /* ... */ }
@SuppressWarning("all")
private void method2() { /* ... */ }

public String method3(String a) {
  System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
  return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
}

Compliant Solution

private static final String ACTION_1 = "action1";  // Compliant

public void run() {
  prepare(ACTION_1);                               // Compliant
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.
Open

    public void addTreeModelListener(final TreeModelListener l) {}

There are several reasons for a method not to have a method body:

  • It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
  • It is not yet, or never will be, supported. In this case an UnsupportedOperationException should be thrown.
  • The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.

Noncompliant Code Example

public void doSomething() {
}

public void doSomethingElse() {
}

Compliant Solution

@Override
public void doSomething() {
  // Do nothing because of X and Y.
}

@Override
public void doSomethingElse() {
  throw new UnsupportedOperationException();
}

Exceptions

Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.

public abstract class Animal {
  void speak() {  // default implementation ignored
  }
}

Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.
Open

    public void valueForPathChanged(final TreePath path, final Object newvalue) {}

There are several reasons for a method not to have a method body:

  • It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
  • It is not yet, or never will be, supported. In this case an UnsupportedOperationException should be thrown.
  • The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.

Noncompliant Code Example

public void doSomething() {
}

public void doSomethingElse() {
}

Compliant Solution

@Override
public void doSomething() {
  // Do nothing because of X and Y.
}

@Override
public void doSomethingElse() {
  throw new UnsupportedOperationException();
}

Exceptions

Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.

public abstract class Animal {
  void speak() {  // default implementation ignored
  }
}

Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.
Open

    public void removeTreeModelListener(final TreeModelListener l) {}

There are several reasons for a method not to have a method body:

  • It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
  • It is not yet, or never will be, supported. In this case an UnsupportedOperationException should be thrown.
  • The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.

Noncompliant Code Example

public void doSomething() {
}

public void doSomethingElse() {
}

Compliant Solution

@Override
public void doSomething() {
  // Do nothing because of X and Y.
}

@Override
public void doSomethingElse() {
  throw new UnsupportedOperationException();
}

Exceptions

Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.

public abstract class Animal {
  void speak() {  // default implementation ignored
  }
}

There are no issues that match your filters.

Category
Status