1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.collections;
18
19 import java.util.Collection;
20
21 /**
22 * Defines a collection that allows objects to be removed in some well-defined order.
23 * <p>
24 * The removal order can be based on insertion order (eg, a FIFO queue or a
25 * LIFO stack), on access order (eg, an LRU cache), on some arbitrary comparator
26 * (eg, a priority queue) or on any other well-defined ordering.
27 * <p>
28 * Note that the removal order is not necessarily the same as the iteration
29 * order. A <code>Buffer</code> implementation may have equivalent removal
30 * and iteration orders, but this is not required.
31 * <p>
32 * This interface does not specify any behavior for
33 * {@link Object#equals(Object)} and {@link Object#hashCode} methods. It
34 * is therefore possible for a <code>Buffer</code> implementation to also
35 * also implement {@link java.util.List}, {@link java.util.Set} or
36 * {@link Bag}.
37 *
38 * @param <E> the type of the elements in the buffer
39 * @since 2.1
40 * @version $Id: Buffer.java 1361710 2012-07-15 15:00:21Z tn $
41 */
42 public interface Buffer<E> extends Collection<E> {
43
44 /**
45 * Gets and removes the next object from the buffer.
46 *
47 * @return the next object in the buffer, which is also removed
48 * @throws BufferUnderflowException if the buffer is already empty
49 */
50 E remove();
51
52 /**
53 * Gets the next object from the buffer without removing it.
54 *
55 * @return the next object in the buffer, which is not removed
56 * @throws BufferUnderflowException if the buffer is empty
57 */
58 E get();
59
60 }