package tpnote;
import java.util.Objects;

public class PriorityManager {
  private static final int MAX_PRIORITY = 5;
  
  private static void checkPriority(int priority) {
    if (priority < 0 || priority >= MAX_PRIORITY) {
      throw new IllegalArgumentException("invalid priority " + priority);
    }
  }
  
  /**
   * Add a code with a given priority.
   * @param priority a priority between 0 and 5.
   * @param code a code
   * 
   * @throws IllegalArgumentException if the priority is not in its range
   * @throws NullPointerException is the code is null
   * @throws IllegalStateException if a code with the same priority was already added.
   */
  public void add(int priority, XXX code) {
    checkPriority(priority);
    Objects.requireNonNull(code);
    //TODO
  }
  
  /**
   * Execute in one thread all the codes added by {@link #add(int, XXX)}
   * in ascending order of their priority.
   * After that, all the codes are forgotten and the {@link PriorityManager} can be reused.
   */
  public void executeAll() {
    //TODO
  }
  
  public static void main(String[] args) {
    PriorityManager manager = new PriorityManager();
    manager.add(3, () -> System.out.println("hello 2"));
    manager.add(1, () -> System.out.println("hello 1"));
    manager.executeAll();
  }
}
