Java Reference
In-Depth Information
1 package weiss.util;
2
3 /**
4 * Queue interface.
5 */
6 public interface Queue<AnyType> extends Collection<AnyType>
7 {
8 /**
9 * Returns but does not remove the item at the "front"
10 * of the queue.
11 * @return the front item of null if the queue is empty.
12 * @throws NoSuchElementException if the queue is empty.
13 */
14 AnyType element( );
15
16 /**
17 * Returns and removes the item at the "front"
18 * of the queue.
19 * @return the front item.
20 * @throws NoSuchElementException if the queue is empty.
21 */
22 AnyType remove( );
23 }
figure 6.28
Possible Queue
interface
1 package weiss.util;
2
3 /**
4 * Set interface.
5 */
6 public interface Set<AnyType> extends Collection<AnyType>
7 {
8 }
figure 6.29
Possible Set interface
LinkedList . A library implementation of Set is expected to efficiently support
contains . Similarly, the Collection remove method (which has as a parameter a
specified object, not a specified index) for a List is inefficient because it is
implied that the first thing remove must do is to find the item being removed;
essentially this makes remove at least as difficult as contains . For a Set , remove is
expected to also be efficiently implemented. And finally, add is expected to
have an efficient implementation. There is no Java syntax that can be used to
specify that an operation must meet a time constraint or may not contain
duplicates; thus Figure 6.29 illustrates that the Set interface does little more
than declare a type.
Search WWH ::




Custom Search