]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/context/IContext.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/context/IContext.java
new file mode 100644 (file)
index 0000000..5c5ff8b
--- /dev/null
@@ -0,0 +1,126 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+\r
+package org.simantics.utils.datastructures.context;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.utils.threads.IThreadWorkQueue;\r
+\r
+/**\r
+ * Observable container.\r
+ * \r
+ * TODO: add addAll() method\r
+ * \r
+ * @see Context for implementation\r
+ * \r
+ * @author Toni Kalajainen\r
+ * @param <E>\r
+ */\r
+public interface IContext<E> {\r
+       \r
+       /**\r
+        * Put an item to the context. \r
+        * @param item\r
+        */\r
+       void add(E item);\r
+       \r
+       /**\r
+        * Remove an item from the context.\r
+        * @param item \r
+        * @return true if was found and removed\r
+        */\r
+       boolean remove(E item); \r
+\r
+       /**\r
+        * Checks whether an item is in the context\r
+        * @param item an item\r
+        * @return true if context contains an item\r
+        */\r
+       boolean contains(E item);\r
+\r
+       /**\r
+        * Clears all items from the context.\r
+        */\r
+       void clear();\r
+\r
+       /**\r
+        * Get all items by class\r
+     * @param <R>\r
+        * @param clazz\r
+        * @return collection \r
+        */\r
+       <R extends E> Collection<R> getItemsByClass(Class<R> clazz);\r
+       \r
+       /**\r
+        * Get a single item by class. \r
+        * (Convenience method)\r
+        * \r
+        * @param <R>\r
+        * @param clazz\r
+        * @return the item \r
+        * @throws RuntimeException if single interactor was not found\r
+        */\r
+       <R extends E> R getSingleItem(Class<R> clazz);\r
+       \r
+       /**\r
+        * Checks that the context has the item by the class\r
+        * @param <R>\r
+        * @param clazz\r
+        * @return <code>true</code> if contained\r
+        */\r
+       <R> boolean containsItemByClass(Class<R> clazz);\r
+\r
+       /**\r
+        * Get a single item by class. \r
+        * (Convenience method)\r
+        * \r
+        * @param <R>\r
+        * @param clazz\r
+        * @return the item or <code>null</code>\r
+        * @throws RuntimeException if more than one items were found\r
+        */\r
+       <R extends E> R getAtMostOneItemOfClass(Class<R> clazz);\r
+       \r
+       /**\r
+        * Get a snapshot of all the items\r
+        * @return ordered list of items. The highest priority item is the last element.\r
+        */\r
+       E[] toArray();\r
+       \r
+       /**\r
+        * add listener\r
+        * @param listener\r
+        */\r
+       void addContextListener(IContextListener<E> listener);\r
+       \r
+       /**\r
+        * remove listener\r
+        * @param listener\r
+        */\r
+       void removeContextListener(IContextListener<E> listener);\r
+       \r
+       /**\r
+        * add listener\r
+     * @param thread thread\r
+        * @param listener\r
+        */\r
+       void addContextListener(IThreadWorkQueue thread, IContextListener<E> listener);\r
+       \r
+       /**\r
+        * remove listener\r
+        * @param thread thread\r
+        * @param listener\r
+        */\r
+       void removeContextListener(IThreadWorkQueue thread, IContextListener<E> listener);\r
+       \r
+}\r