Пример #1
0
  @Override
  public void run() {
    while (threadRunFlag) {
      if (queue.isEmpty()) {
        System.out.println("wait add new Data to upload thread!");
        synchronized (this) {
          try {
            wait();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }

      } else {
        Entity entity = (Entity) queue.remove();
        System.out.println("current upload is:" + entity.toString());
        System.out.println("list size i s :" + queue.size());

        try {
          Thread.sleep(300);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
Пример #2
0
 /**
  * Returns an array of movies in the same order they they are in the queue but shares no data with
  * the actual queue.
  *
  * @pre
  * @post the array of movies will be returned in the order fo the queue
  * @return the array of movies
  */
 public Movie[] displayMoviesAtHome() {
   @SuppressWarnings("deprecation")
   MyQueue<Movie> cloneOfP = new MyQueue<Movie>(atHomeQueue);
   Movie[] movieList = new Movie[cloneOfP.getSize()];
   int i = 0;
   while (!cloneOfP.isEmpty()) {
     movieList[i] = cloneOfP.dequeue();
     i++;
   }
   return movieList;
 }
Пример #3
0
 public static void main(String[] args) {
   Solution34 sol34 = new Solution34();
   int[] values = new int[] {11, 34, 2, 6, 23, 5, 10};
   System.out.print("Create the queue: ");
   MyQueue queue = sol34.new MyQueue(values);
   sol34.printOutQueue(values);
   System.out.print("Remove three elements: ");
   for (int i = 0; i < 3; i++) {
     System.out.print(queue.remove() + "  ");
   }
   System.out.println();
   System.out.print("Peek the next element: ");
   System.out.print(queue.peek());
   System.out.println();
   System.out.print("Add one element 0 and print out all current queue: ");
   queue.add(0);
   while (!queue.isEmpty()) {
     System.out.print(queue.remove() + "  ");
   }
 }