Kuangcp/JavaBase

View on GitHub
algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.java

Summary

Maintainability
D
1 day
Test Coverage

File TimeWheel.java has 274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package com.github.kuangcp.time.wheel;

import lombok.extern.slf4j.Slf4j;

import java.time.Duration;
Severity: Minor
Found in algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.java - About 2 hrs to fix

    Method pushTimeWheel has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        private void pushTimeWheel(int seconds) {
            Map<ChronoUnit, Integer> tempIndex = new HashMap<>(sortedSlots.size());
            for (int i = 0; i < sortedSlots.size(); i++) {
                ChronoUnit unit = sortedSlots.get(i);
                Integer threshold = slots.get(unit);
    Severity: Minor
    Found in algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.java - About 2 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 pushTimeWheel has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private void pushTimeWheel(int seconds) {
            Map<ChronoUnit, Integer> tempIndex = new HashMap<>(sortedSlots.size());
            for (int i = 0; i < sortedSlots.size(); i++) {
                ChronoUnit unit = sortedSlots.get(i);
                Integer threshold = slots.get(unit);

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

          private boolean insertWheel(String id, Duration delay) {
              long days = delay.toDays();
              if (days > 30) {
                  log.warn("out of timeWheel max delay bound");
                  return false;

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

          public void start() {
              master.execute(() -> {
                  while (!stop) {
                      long currentMills = System.currentTimeMillis();
                      try {

        Method insertWheel has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private boolean insertWheel(String id, Duration delay) {
                long days = delay.toDays();
                if (days > 30) {
                    log.warn("out of timeWheel max delay bound");
                    return false;

          Method removeAndAdd has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              private void removeAndAdd(ChronoUnit unit, int index) {
                  LinkedList<TaskNode>[] lists = wheels.get(unit);
                  LinkedList<TaskNode> list = lists[index];
                  if (Objects.nonNull(list) && !list.isEmpty()) {
                      List<TaskNode> nodes = list.toList();

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

              public void printWheel() {
                  log.info("sec:{} min:{} hour:{}", this.currentSecond.get(), this.currentMinute.get(),
                          this.currentHour.get());
                  for (ChronoUnit unit : wheels.keySet()) {
                      LinkedList[] lists = wheels.get(unit);
          Severity: Minor
          Found in algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.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

          Avoid too many return statements within this method.
          Open

                      return insertWheel(ChronoUnit.SECONDS, this.currentSecond.get() + seconds, node);
          Severity: Major
          Found in algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.java - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return insertWheel(ChronoUnit.SECONDS, this.currentSecond.get() + 1, node);
            Severity: Major
            Found in algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.java - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return false;
              Severity: Major
              Found in algorithms/src/main/java/com/github/kuangcp/time/wheel/TimeWheel.java - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status