Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scheduler Pattern] (Add) scheduler pattern #76 #2794

Closed
wants to merge 4 commits into from

Conversation

tiennm99
Copy link
Contributor

I just implemented common and easy to understand disciplines: First Come First Served, Priority scheduling, Shortest remaining time first, Round-robin scheduling. It would be great if someone were generous enough to implement more complicated disciplines.

@tiennm99
Copy link
Contributor Author

CheckStyle stricts too many things, I think it's inconvenient

@tiennm99
Copy link
Contributor Author

Sorry but I think I can't improve my code to fit CheckStyle. Maybe it will be good for professional, but not for me.
Because we want a simple demo Application, I write something like this:

public class Main {
  public static void main(String[] args) {
    Map<Integer, List<Task>> tasks = new HashMap<>();
    tasks.put(0, List.of(new Task(1, 3), new Task(2, 2), new Task(3, 4)));

    TaskScheduler scheduler = new FirstComeFirstServedScheduler();
    Simulator simulator = new Simulator(scheduler, tasks, 1, 100);
    simulator.simulate();
  }
}

Then CheckStyle blocks me with these errors:

[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[7,1] (design) HideUtilityClassConstructor: Utility classes should not have a public or default constructor.
[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[8,3] (javadoc) MissingJavadocMethod: Missing a Javadoc comment.
[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[8,27] (misc) FinalParameters: Parameter args should be final.
[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[10,38] (coding) MagicNumber: '3' is a magic number.
[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[10,67] (coding) MagicNumber: '3' is a magic number.
[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[10,70] (coding) MagicNumber: '4' is a magic number.
[ERROR] src\main\java\com\iluwatar\scheduler\Main.java:[13,62] (coding) MagicNumber: '100' is a magic number.

So I must refactor my code to:

public final class Main {

  /** Task 1 id. */
  private static final int TASK1_ID = 1;

  /** Task 1 priority. */
  private static final int TASK1_PRIORITY = 3;

  /** Task 2 id. */
  private static final int TASK2_ID = 2;

  /** Task 2 priority. */
  private static final int TASK2_PRIORITY = 2;

  /** Task 3 id. */
  private static final int TASK3_ID = 3;

  /** Task 3 priority. */
  private static final int TASK3_PRIORITY = 4;

  /** Simulator delta time. */
  private static final int SIMULATOR_DELTA_TIME = 1;

  /** Simulator end time. */
  private static final int SIMULATOR_END_TIME = 100;

  private Main() {
    // do nothing, just for private constructor
  }

  /**
   * Program entry point.
   *
   * @param args args
   */
  public static void main(final String[] args) {
    Map<Integer, List<Task>> tasks = new HashMap<>();
    Task task1 = new Task(TASK1_ID, TASK1_PRIORITY);
    Task task2 = new Task(TASK2_ID, TASK2_PRIORITY);
    Task task3 = new Task(TASK3_ID, TASK3_PRIORITY);
    tasks.put(0, List.of(task1, task2, task3));

    TaskScheduler scheduler = new FirstComeFirstServedScheduler();
    Simulator simulator = new Simulator(scheduler,
        tasks,
        SIMULATOR_DELTA_TIME,
        SIMULATOR_END_TIME);
    simulator.simulate();
  }
}

I think this code is weird, it's too long and not easy to read.
And I'm not good enough to fix it. So I will close this PR.
Hope you find some better one to help you implement this. Sorry for can not help you.

@tiennm99 tiennm99 closed this Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant