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