]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/context/IContext.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / context / IContext.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 package org.simantics.utils.datastructures.context;\r
14 \r
15 import java.util.Collection;\r
16 \r
17 import org.simantics.utils.threads.IThreadWorkQueue;\r
18 \r
19 /**\r
20  * Observable container.\r
21  * \r
22  * TODO: add addAll() method\r
23  * \r
24  * @see Context for implementation\r
25  * \r
26  * @author Toni Kalajainen\r
27  * @param <E>\r
28  */\r
29 public interface IContext<E> {\r
30         \r
31         /**\r
32          * Put an item to the context. \r
33          * @param item\r
34          */\r
35         void add(E item);\r
36         \r
37         /**\r
38          * Remove an item from the context.\r
39          * @param item \r
40          * @return true if was found and removed\r
41          */\r
42         boolean remove(E item); \r
43 \r
44         /**\r
45          * Checks whether an item is in the context\r
46          * @param item an item\r
47          * @return true if context contains an item\r
48          */\r
49         boolean contains(E item);\r
50 \r
51         /**\r
52          * Clears all items from the context.\r
53          */\r
54         void clear();\r
55 \r
56         /**\r
57          * Get all items by class\r
58      * @param <R>\r
59          * @param clazz\r
60          * @return collection \r
61          */\r
62         <R extends E> Collection<R> getItemsByClass(Class<R> clazz);\r
63         \r
64         /**\r
65          * Get a single item by class. \r
66          * (Convenience method)\r
67          * \r
68          * @param <R>\r
69          * @param clazz\r
70          * @return the item \r
71          * @throws RuntimeException if single interactor was not found\r
72          */\r
73         <R extends E> R getSingleItem(Class<R> clazz);\r
74         \r
75         /**\r
76          * Checks that the context has the item by the class\r
77          * @param <R>\r
78          * @param clazz\r
79          * @return <code>true</code> if contained\r
80          */\r
81         <R> boolean containsItemByClass(Class<R> clazz);\r
82 \r
83         /**\r
84          * Get a single item by class. \r
85          * (Convenience method)\r
86          * \r
87          * @param <R>\r
88          * @param clazz\r
89          * @return the item or <code>null</code>\r
90          * @throws RuntimeException if more than one items were found\r
91          */\r
92         <R extends E> R getAtMostOneItemOfClass(Class<R> clazz);\r
93         \r
94         /**\r
95          * Get a snapshot of all the items\r
96          * @return ordered list of items. The highest priority item is the last element.\r
97          */\r
98         E[] toArray();\r
99         \r
100         /**\r
101          * add listener\r
102          * @param listener\r
103          */\r
104         void addContextListener(IContextListener<E> listener);\r
105         \r
106         /**\r
107          * remove listener\r
108          * @param listener\r
109          */\r
110         void removeContextListener(IContextListener<E> listener);\r
111         \r
112         /**\r
113          * add listener\r
114      * @param thread thread\r
115          * @param listener\r
116          */\r
117         void addContextListener(IThreadWorkQueue thread, IContextListener<E> listener);\r
118         \r
119         /**\r
120          * remove listener\r
121          * @param thread thread\r
122          * @param listener\r
123          */\r
124         void removeContextListener(IThreadWorkQueue thread, IContextListener<E> listener);\r
125         \r
126 }\r