1 /* 2 * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved. 3 */ 4 package com.tc.util.concurrent; 5 6 import java.util.NoSuchElementException; 7 8 /** 9 * A generic queue interface similar to the java.util.Queue interface in the JDK 1.5 API NOTE: the interface is not 10 * complete with respect to the JDK version. Feel free to complete it if you'd like 11 * 12 * @author orion 13 */ 14 public interface Queue { 15 /** 16 * @return true iff this queue is empty (ie. contains no elements) 17 */ 18 boolean isEmpty(); 19 20 /** 21 * Retrieves and removes the head of this queue, or null if this queue is empty. 22 * 23 * @return the head of this queue, or null if this queue is empty. 24 */ 25 Object element(); 26 27 /** 28 * Inserts the specified element into this queue, if possible 29 * 30 * @param o the element to insert. 31 * @return true if it was possible to add the element to this queue, else false 32 */ 33 boolean offer(Object o); 34 35 /** 36 * Retrieves, but does not remove, the head of this queue, returning null if this queue is empty. 37 * 38 * @return the head of this queue, or null if this queue is empty. 39 */ 40 Object peek(); 41 42 /** 43 * Retrieves and removes the head of this queue, or null if this queue is empty. 44 * 45 * @return the head of this queue, or null if this queue is empty. 46 */ 47 Object poll(); 48 49 /** 50 * Retrieves and removes the head of this queue. This method differs from the poll method in that it throws an 51 * exception if this queue is empty. 52 * 53 * @return the head of this queue. 54 * @throws NoSuchElementException if this queue is empty. 55 */ 56 Object remove(); 57 }