/*!
  @header ECKeyToListMap
  @abstract Module of Encore
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 Oliver Langer

  Author: Oliver Langer

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

  <pre>
  -------------------------------------------------------------------------
  Modification history

  29.10.05 ola     initial version
  22.08.06 ola     license changed
  -------------------------------------------------------------------------
  </pre>
*/

#if !defined(__ECKeyToListMap_H)
#define __ECKeyToListMap_H

#include <Foundation/Foundation.h>
#include <Encore/ECObject.h>
#include <Encore/ECIterator.h>
#include <Encore/ECExceptions.h>
#include <Encore/ECArrayIterator.h>
#include <Encore/ECEmptyIterator.h>

/*!
 * @class ECKeyToListMap
 * @abstract This class implements mapping key --> list, where a key uniquely
 *   maps to a list of items. The main purpose of this class is to support 
 *   operations like add(list_key, item), where item has to be added to the
 *   list selected by the given key.
 */
@interface ECKeyToListMap : ECObject <NSCoding> {
  @private 
    NSMutableDictionary *keyToArrayDictionary;
}

- init;
- (void) dealloc;


/* operations belonging to NSCoding: */
- (void) encodeWithCoder: (NSCoder *) aCoder;
- (id) initWithCoder: (NSCoder *) aDecoder;


- (BOOL) isEqual: (id) object;
- (unsigned) hash;


/*!
 * @method addListItem
 * @abstract adds an item to a list which is identified by "aKey". If the 
 *   list does not exist then it will be created.
 * @param aListItem item to add
 * @param aKey corresponding key identifying the list
 * @throws ECIllegalArgumentException if an item equal to the specified one
 *   already exists in the specified list.
 * @result self
 */
- addListItem: (id) aListItem forKey: (id) aKey;

/*!
 * @method allKeys
 * @result returns the keys of all lists
 */
- (id <ECIterator>) allKeys;


/*!
 * @method existsListItem
 * @param aListItem item to look for
 * @param aKey key identifying a list
 * @return YES if the specified item exists in the specified list
 */
- (BOOL) existsListItem: (id) aListItem forKey: (id) aKey;


/*!
 * @method listItemsOfKey
 * @param aKey key specifying a list
 * @result returns all items of the specified list
 */
- (id <ECIterator>) listItemsOfKey: (id) aKey;


/*!
 * @method removeListItem
 * @abstract removes the specified item. Does nothing if the item does not 
 *   exist.
 * @param aListItem item to remove
 * @param aKey specifies the list
 * @result self
 */
- removeListItem: (id) aListItem forKey: (id) aKey;

@end
#endif
