SiLeBAT/FSK-Lab

View on GitHub
de.bund.bfr.knime.fsklab.nodes/src/de/bund/bfr/knime/fsklab/v2_0/joiner/JoinerNodeUtil.java

Summary

Maintainability
F
6 days
Test Coverage

Method generateJoinerRelationAdvanced has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

  public static List<JoinRelationAdvanced> generateJoinerRelationAdvanced(FskPortObject portObject,
      LinkedHashMap<String, Object[]> originalNamesMap, List<Parameter> topLevelJoinedModelParams, List<JoinRelation> joinRelations,
       AtomicInteger index, List<JoinRelationAdvanced> joinRelationList, LinkedHashMap<String, String> ModelsToSuffixMap, List<JoinRelation> foundRelation) {
    if (joinRelationList == null) {
      joinRelationList = new ArrayList<>();

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

package de.bund.bfr.knime.fsklab.v2_0.joiner;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

Method generateColorMap has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  public static LinkedHashMap<String, Object[]> generateColorMap(FskPortObject portObject,
      LinkedHashMap<String, Object[]> originalNamesMap, List<Parameter> topLevelJoinedModelParams, 
       AtomicInteger index, AtomicInteger generatedColorInt) {
    
    if (originalNamesMap == null) {

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

  public static void createAllPossibleSimulations(FskPortObject firstFskObj,
      FskPortObject secondFskObj, CombinedFskPortObject outObj) {

    int indexFirst = 0;
    int indexSecond = 0;

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 generateJoinerRelationAdvanced has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public static List<JoinRelationAdvanced> generateJoinerRelationAdvanced(FskPortObject portObject,
      LinkedHashMap<String, Object[]> originalNamesMap, List<Parameter> topLevelJoinedModelParams, List<JoinRelation> joinRelations,
       AtomicInteger index, List<JoinRelationAdvanced> joinRelationList, LinkedHashMap<String, String> ModelsToSuffixMap, List<JoinRelation> foundRelation) {
    if (joinRelationList == null) {
      joinRelationList = new ArrayList<>();

Method removeJoinedParameters has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  public static void removeJoinedParameters(JoinRelation[] relations, FskPortObject outfskPort) {
    if (outfskPort instanceof CombinedFskPortObject) {
      if (relations != null)
        for (JoinRelation relation : relations) {

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

  public static void addIdentifierToParametersForCombinedObject(FskPortObject portObject,
      String suffix, int suffixInsertionIndex,
      final Map<String, List<String>> unModifiedParamsNames,
      Map<String, Map<String, String>> old_new_pramsMap)
      throws JsonMappingException, JsonProcessingException {

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

  public static LinkedHashMap<String, String> getTopLevelParameterNames(FskPortObject portObject,
      LinkedHashMap<String, String> toplevelOutputParameters,
      LinkedHashMap<String, String> originalNamesMap, String suffix) {
    if (originalNamesMap == null) {
      originalNamesMap = new LinkedHashMap<String, String>();

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

  public static String findSuffix(List<String> listOfParameter) {
    List<String> trailingNums = extractNumber(listOfParameter);
    int longestStringIndex = 0;
    int longestString = 0;
    for(int x = 0; x < trailingNums.size(); x++) {

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 generateColorMap has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public static LinkedHashMap<String, Object[]> generateColorMap(FskPortObject portObject,
      LinkedHashMap<String, Object[]> originalNamesMap, List<Parameter> topLevelJoinedModelParams, 
       AtomicInteger index, AtomicInteger generatedColorInt) {
    
    if (originalNamesMap == null) {

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

  private static void adaptRelationNames(CombinedFskPortObject portObject, String suffix, int suffixInsertionIndex,
      Map<String, String> old_new_pramsMap) {
    Map<String, String> mapInversed = old_new_pramsMap.entrySet().stream()
        .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey,
            // choose the second value in the case of key duplication

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 adaptRelationNames has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private static void adaptRelationNames(CombinedFskPortObject portObject, String suffix, int suffixInsertionIndex,
      Map<String, String> old_new_pramsMap) {
    Map<String, String> mapInversed = old_new_pramsMap.entrySet().stream()
        .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey,
            // choose the second value in the case of key duplication

Method addIdentifierToParametersForCombinedObject has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public static void addIdentifierToParametersForCombinedObject(FskPortObject portObject,
      String suffix, int suffixInsertionIndex,
      final Map<String, List<String>> unModifiedParamsNames,
      Map<String, Map<String, String>> old_new_pramsMap)
      throws JsonMappingException, JsonProcessingException {

Method createAllPossibleSimulations has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public static void createAllPossibleSimulations(FskPortObject firstFskObj,
      FskPortObject secondFskObj, CombinedFskPortObject outObj) {

    int indexFirst = 0;
    int indexSecond = 0;

Method findSuffix has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public static String findSuffix(List<String> listOfParameter) {
    List<String> trailingNums = extractNumber(listOfParameter);
    int longestStringIndex = 0;
    int longestString = 0;
    for(int x = 0; x < trailingNums.size(); x++) {

Method generateJoinerRelationAdvanced has 8 arguments (exceeds 4 allowed). Consider refactoring.
Open

  public static List<JoinRelationAdvanced> generateJoinerRelationAdvanced(FskPortObject portObject,
      LinkedHashMap<String, Object[]> originalNamesMap, List<Parameter> topLevelJoinedModelParams, List<JoinRelation> joinRelations,
       AtomicInteger index, List<JoinRelationAdvanced> joinRelationList, LinkedHashMap<String, String> ModelsToSuffixMap, List<JoinRelation> foundRelation) {

Avoid deeply nested control flow statements.
Open

            if (b2)
              iter.remove();

Method addIdentifierToParametersForCombinedObject has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  public static void addIdentifierToParametersForCombinedObject(FskPortObject portObject,
      String suffix, int suffixInsertionIndex,
      final Map<String, List<String>> unModifiedParamsNames,
      Map<String, Map<String, String>> old_new_pramsMap)

Method addIdentifierToParametersAndStoreInMap has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  private static void addIdentifierToParametersAndStoreInMap(FskPortObject portObject,
      String suffix, int suffixInsertionIndex,
      final Map<String, List<String>> unModifiedParamsNames,
      Map<String, Map<String, String>> old_new_pramsMap) {

Method generateColorMap has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  public static LinkedHashMap<String, Object[]> generateColorMap(FskPortObject portObject,
      LinkedHashMap<String, Object[]> originalNamesMap, List<Parameter> topLevelJoinedModelParams, 
       AtomicInteger index, AtomicInteger generatedColorInt) {

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

  public static void createAllPossibleSimulations(FskPortObject firstFskObj,

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 20 to the 15 allowed.
Open

  public static LinkedHashMap<String, Object[]> generateColorMap(FskPortObject portObject,

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 42 to the 15 allowed.
Open

  public static List<JoinRelationAdvanced> generateJoinerRelationAdvanced(FskPortObject portObject,

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

Save and re-use this "Random".
Open

        Random r = new Random();

Creating a new Random object each time a random value is needed is inefficient and may produce numbers which are not random depending on the JDK. For better efficiency and randomness, create a single Random, then store, and reuse it.

The Random() constructor tries to set the seed with a distinct value every time. However there is no guarantee that the seed will be random or even uniformly distributed. Some JDK will use the current time as seed, which makes the generated numbers not random at all.

This rule finds cases where a new Random is created each time a method is invoked and assigned to a local random variable.

Noncompliant Code Example

public void doSomethingCommon() {
  Random rand = new Random();  // Noncompliant; new instance created with each invocation
  int rValue = rand.nextInt();
  //...

Compliant Solution

private Random rand = SecureRandom.getInstanceStrong();  // SecureRandom is preferred to Random

public void doSomethingCommon() {
  int rValue = this.rand.nextInt();
  //...

Exceptions

A class which uses a Random in its constructor or in a static main function and nowhere else will be ignored by this rule.

See

Identical blocks of code found in 2 locations. Consider refactoring.
Open

  public static void createAllPossibleSimulations(FskPortObject firstFskObj,
      FskPortObject secondFskObj, CombinedFskPortObject outObj) {

    int indexFirst = 0;
    int indexSecond = 0;
de.bund.bfr.knime.fsklab.deprecatednodes/src-1_9_0/de/bund/bfr/knime/fsklab/v1_9/joiner/JoinerNodeUtil.java on lines 181..230

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 262.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    if (outfskPort instanceof CombinedFskPortObject) {
      if (relations != null)
        for (JoinRelation relation : relations) {

          Iterator<Parameter> iter = SwaggerUtil.getParameter(outfskPort.modelMetadata).iterator();
de.bund.bfr.knime.fsklab.deprecatednodes/src-1_9_0/de/bund/bfr/knime/fsklab/v1_9/joiner/JoinerNodeUtil.java on lines 258..274

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 79.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

  public static void createDefaultSimulation(FskPortObject fskObj) {

    if (SwaggerUtil.getModelMath(fskObj.modelMetadata) != null) {

      List<Parameter> combinedModelParameters = SwaggerUtil.getParameter(fskObj.modelMetadata);
de.bund.bfr.knime.fsklab.deprecatednodes/src-1_9_0/de/bund/bfr/knime/fsklab/v1_9/joiner/JoinerNodeUtil.java on lines 239..250

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 66.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

  public static FskSimulation makeIndividualSimulation(FskSimulation combinedSim, String suffix) {
    FskSimulation fskSimulation = new FskSimulation(combinedSim.getName());

    combinedSim.getParameters().forEach((pId, pValue) -> {
      if (pId.endsWith(suffix))
de.bund.bfr.knime.fsklab.deprecatednodes/src-1_9_0/de/bund/bfr/knime/fsklab/v1_9/joiner/JoinerNodeUtil.java on lines 55..64

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 65.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    if (portObject instanceof CombinedFskPortObject) {
      originalNamesMap =
          getTopLevelParameterNames(((CombinedFskPortObject) portObject).getFirstFskPortObject(),
              toplevelOutputParameters, originalNamesMap, suffix + JoinerNodeModel.SUFFIX_FIRST);
      originalNamesMap =
de.bund.bfr.knime.fsklab.nodes/src/de/bund/bfr/knime/fsklab/v2_0/runner/RunnerNodeModel.java on lines 408..415

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 58.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  public static void saveOutputVariable(Map<String, String> originalOutputParameters,
      ScriptHandler handler, ExecutionContext exec) {


    // save output to the official name (with all the suffixes) so it doesn't get overwritten by
de.bund.bfr.knime.fsklab.deprecatednodes/src-1_9_0/de/bund/bfr/knime/fsklab/v1_9/joiner/JoinerNodeUtil.java on lines 75..92

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 50.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

There are no issues that match your filters.

Category
Status