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