Kuangcp/JavaBase

View on GitHub
algorithms/src/main/java/com/github/kuangcp/parser/expression/Expression.java

Summary

Maintainability
F
4 days
Test Coverage

Method wordAnalysis has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

    public static List<ExpressionWord> wordAnalysis(String expressionStr) {
        String expStrNoSpace = remove(expressionStr, ' '); //去除目标表达式中的空格字符
        char[] exChar = expStrNoSpace.toCharArray();
        List<ExpressionWord> expressionWord = new ArrayList<>();
        for (int i = 0; i < exChar.length; i++) {

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

    public static List<ExpressionWord> wordAnalysis(String expressionStr) {
        String expStrNoSpace = remove(expressionStr, ' '); //去除目标表达式中的空格字符
        char[] exChar = expStrNoSpace.toCharArray();
        List<ExpressionWord> expressionWord = new ArrayList<>();
        for (int i = 0; i < exChar.length; i++) {

    File Expression.java has 350 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    package com.github.kuangcp.parser.expression;
    
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.List;

      Method getPostfix has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public static List<ExpressionWord> getPostfix(Expression expression) {
              List<ExpressionWord> midfix = expression.getWord();  //获取中缀表达式的经过词法分析器分析的结果集
              List<ExpressionWord> result = new ArrayList<>();   //存储后缀表达式结果的List集合
              Stack<ExpressionWord> operationStack = new Stack<>();  //操作符栈
      
      

      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

      Expression has 22 methods (exceeds 20 allowed). Consider refactoring.
      Open

      public class Expression {
      
          private String expression;  //算术表达式字符串
          private final List<ExpressionWord> expressionWord; //存储表达式词法分析所得的单词与该单词所对应的种别编码的集合
          private int index;  //读取词法分析器的字符游标

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

            public static BigDecimal expCalculate(Expression expression) {
                List<ExpressionWord> postfix = getPostfix(expression);  //获取表达式的后缀表达式
                Stack<BigDecimal> result = new Stack<>();  //操作数栈
                if (postfix != null && postfix.size() > 0) {
                    for (int i = 0; i < postfix.size(); i++) {

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

            public static List<ExpressionWord> getPostfix(Expression expression) {
                List<ExpressionWord> midfix = expression.getWord();  //获取中缀表达式的经过词法分析器分析的结果集
                List<ExpressionWord> result = new ArrayList<>();   //存储后缀表达式结果的List集合
                Stack<ExpressionWord> operationStack = new Stack<>();  //操作符栈
        
        

          Method expCalculate has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static BigDecimal expCalculate(Expression expression) {
                  List<ExpressionWord> postfix = getPostfix(expression);  //获取表达式的后缀表达式
                  Stack<BigDecimal> result = new Stack<>();  //操作数栈
                  if (postfix != null && postfix.size() > 0) {
                      for (int i = 0; i < postfix.size(); i++) {

            Consider simplifying this complex logical expression.
            Open

                                if (('a' <= exChar[i] && exChar[i] <= 'z') || ('A' <= exChar[i] && exChar[i] <= 'Z') || exChar[i] == '_' || ('0' <= exChar[i] && exChar[i] <= '9')) {
                                    sb.append('.');
                                    i = getI(exChar, i, sb);
                                } else {
                                    throw new RuntimeException("词法错误!");

              Method getI has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static int getI(char[] exChar, int i, StringBuilder sb) {
                      while (('a' <= exChar[i] && exChar[i] <= 'z') || ('A' <= exChar[i] && exChar[i] <= 'Z') || exChar[i] == '_' || ('0' <= exChar[i] && exChar[i] <= '9')) {
                          if (i == exChar.length - 1) {
                              sb.append(exChar[i]);
                              break;

              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

              Consider simplifying this complex logical expression.
              Open

                          if (exChar[i] == '+' || exChar[i] == '-' || exChar[i] == '*' || exChar[i] == '/' || exChar[i] == '(' || exChar[i] == ')') {
                              StringBuilder sb = new StringBuilder();
                              sb.append(exChar[i]);
                              switch (exChar[i]) {
                                  case '+':

                Method E1 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    private void E1() {
                        if (sym == 1) {
                            next();
                            T();
                            E1();

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

                    private void F() {
                        if (sym == 5) {
                            next();
                        } else if (sym == 6) {
                            next();

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

                    private void T1() {
                        if (sym == 3) {
                            next();
                            F();
                            T1();

                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

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

                                if (i == exChar.length - 1) {
                                    switch (exChar[i]) {
                                        case '+':
                                            expressionWord.add(new ExpressionWord("+", 1));
                                            break;
                algorithms/src/main/java/com/github/kuangcp/parser/expression/Expression.java on lines 122..148

                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 146.

                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 (i == exChar.length - 1) {
                                    switch (exChar[i]) {
                                        case '+':
                                            expressionWord.add(new ExpressionWord("+", 1));
                                            break;
                algorithms/src/main/java/com/github/kuangcp/parser/expression/Expression.java on lines 80..106

                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 146.

                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 (('a' <= exChar[i] && exChar[i] <= 'z') || ('A' <= exChar[i] && exChar[i] <= 'Z') || exChar[i] == '_' || ('0' <= exChar[i] && exChar[i] <= '9')) {
                algorithms/src/main/java/com/github/kuangcp/parser/expression/Expression.java on lines 170..170

                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 88.

                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

                        while (('a' <= exChar[i] && exChar[i] <= 'z') || ('A' <= exChar[i] && exChar[i] <= 'Z') || exChar[i] == '_' || ('0' <= exChar[i] && exChar[i] <= '9')) {
                algorithms/src/main/java/com/github/kuangcp/parser/expression/Expression.java on lines 72..72

                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 88.

                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

                        while (b && exChar[i] <= '9') {
                            if (i == exChar.length - 1) {
                                sb.append(exChar[i]);
                                break;
                            } else {
                algorithms/src/main/java/com/github/kuangcp/parser/expression/Expression.java on lines 170..178

                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 52.

                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