]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/prioritystack/IPriorityStack.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / prioritystack / IPriorityStack.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.utils.datastructures.prioritystack;
17
18 import org.simantics.utils.threads.IThreadWorkQueue;
19
20
21 /**
22  * Stack of interactor layers
23  * @param <E> type of stack items
24  */
25 public interface IPriorityStack<E> {
26         
27         /**
28          * Put an item to the stack 
29          * to the top of the stack.
30          * @param item
31          * @param priority 
32          */
33         void add(E item, int priority);
34
35         /**
36          * Get priority of an item.
37          * Priority affects the event handing, hint overriding and to the paint order of 
38          * the interactor.
39          * 
40          * @param item the item
41          * @return priority of the interactor or <code>null</code> if item does not exist 
42          */
43         Integer getPriority(E item);
44         
45         /**
46          * Remove item
47          * @param item
48          * @return true if was found and removed
49          */
50         boolean remove(E item); 
51
52         /**
53          * Checks whether an item is in the stack
54          * @param item
55          * @return true if stack contains the specified item
56          */
57         boolean contains(E item);
58
59     /**
60      * Get all items by class. All items assignable to the specified class are
61      * returned.
62      * 
63      * @param <R>
64      * @param clazz
65      * @return all items assignable to the specified class
66      */
67         <R extends E> R[] getItemsByClass(Class<R> clazz);
68
69     /**
70      * Get a single item by class. (Convenience method)
71      * 
72      * @param <R>
73      * @param clazz
74      * @return a single item of the specified class
75      * @throws RuntimeException if single item was not found or if multiple
76      *         matching items were found
77      */
78         <R extends E> R getSingleItem(Class<R> clazz);
79         
80         /**
81          * Get a snapshot of all the items
82          * @return ordered list of items. The highest priority item is the last element.
83          */
84         E[] toArray();
85         
86         /**
87          * add listener
88          * @param thread
89          * @param listener
90          */
91         void addStackListener(IThreadWorkQueue thread, IPriorityStackListener<E> listener);
92         
93         /**
94          * remove listener
95          * @param thread
96          * @param listener
97          */
98         void removeStackListener(IThreadWorkQueue thread, IPriorityStackListener<E> listener);
99
100         /**
101          * add listener
102          * @param listener
103          */
104         void addStackListener(IPriorityStackListener<E> listener);
105         
106         /**
107          * remove listener
108          * @param listener
109          */
110         void removeStackListener(IPriorityStackListener<E> listener);
111         
112 }