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