Code example for PriorityQueue

0
 
  PriorityQueue<InstructionMessage> queue; 
 
  public InstructionQueue() { 
    Comparator<InstructionMessage> comparator = new InstructionMessageComparator(); 
    queue = new PriorityQueue(10, comparator); 
  } 
 
  public int numberOfInstructionMessages() { 
    return queue.size(); 
  } 
 
  public void placeInstructionMessageOntoQueue(InstructionMessage instructionMessage) throws InvalidExceptionMessage { 
    if (!instructionMessage.isValid()) { 
      throw new InvalidExceptionMessage(); 
    } 
    else {       
      queue.add(instructionMessage); 
    } 
  }