Statistics
| Revision:

root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.swing / org.gvsig.proj.swing.api / src / main / java / org / gvsig / proj / swing / RecentHistory.java @ 866

History | View | Annotate | Download (2.67 KB)

1
package org.gvsig.proj.swing;
2

    
3
import java.util.Iterator;
4
import java.util.List;
5

    
6
/**
7
 * Stores a collection of objects, removing the oldest objects when the size
8
 * of the collection grows beyond the allowed {@link #getMaxSize() maxSize}.
9
 * 
10
 * @author Cesar Martinez Izquierdo
11
 *
12
 * @param <E> The type of object to be stored
13
 */
14
public interface RecentHistory<E> extends Iterable<E> {
15

    
16
        /**
17
         * Gets the maximum size allowed by this history collection.
18
         * 
19
         * @return
20
         */
21
        int getMaxSize();
22
        
23
    /**
24
     * Returns the number of elements in this collection.
25
     *
26
     * @return the number of elements in this collection
27
     */
28
    int size();
29
    
30
    /**
31
     * Returns <tt>true</tt> if this collection contains no elements.
32
     *
33
     * @return <tt>true</tt> if this collection contains no elements
34
     */
35
    boolean isEmpty();
36
    
37
    /**
38
     * Returns <tt>true</tt> if this collection contains the specified element.
39
     * More formally, returns <tt>true</tt> if and only if this collection
40
     * contains at least one element <tt>e</tt> such that
41
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
42
     *
43
     * @param o element whose presence in this collection is to be tested
44
     * @return <tt>true</tt> if this collection contains the specified
45
     *         element
46
     * @throws ClassCastException if the type of the specified element
47
     *         is incompatible with this collection
48
     *         (<a href="#optional-restrictions">optional</a>)
49
     * @throws NullPointerException if the specified element is null and this
50
     *         collection does not permit null elements
51
     *         (<a href="#optional-restrictions">optional</a>)
52
     */
53
    boolean contains(Object o);
54

    
55
        /**
56
         * Adds an element to the history. If the history grows beyond
57
         * the allowed {@link #getMaxSize() maxSize}, then the oldest
58
         * object of the collection is removed from the history. If the
59
         * added element was already present in the history, its age is
60
         * updated to be considered the most recent object in the collection.
61
         */
62
        boolean add(E element);
63

    
64
        /**
65
         * Returns an iterator over the elements in this collection, ordered according
66
         * the age of the element in the collection (newer objects come first).
67
         * 
68
         * Concurrent changes in the RecentHistory instance do not affect nor modify
69
         * the returned iterator.  
70
         * @return
71
         */
72
        Iterator<E> iterator();
73

    
74
        /**
75
         * Returns the elements in this collection as an unmodifiable List,
76
         * ordered according the age of the element in the collection
77
         * (newer objects come first).
78
         * 
79
         * Concurrent changes in the RecentHistory instance do not affect nor modify
80
         * the returned list. 
81
         *   
82
         * @return
83
         */
84
        List<E> toList();
85
}