//==================================================================================================
// D a t a _ s t r u c t u r e                                                                 Java
// E x t e n s i o n
// E x t e n d a b l e M a p
//                                                                                By Bruno Bachelet
//==================================================================================================
// Copyright (c) 1999-2016
// Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net
//
// This file is part of the B++ Library. This library is free software; you can redistribute it
// and/or modify it under the terms of the GNU Library General Public License as published by the
// Free Software Foundation; either version 2 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 Library General Public License for more details (http://www.gnu.org).

/*DESCRIPTION*/
/* This module provides a class to manage a map (i.e. an object that maps keys to values) of
   extendable objects. */

// Package //---------------------------------------------------------------------------------------
package bpp.data_structure.extension;

// Importation //-----------------------------------------------------------------------------------
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("unchecked")

// E x t e n d a b l e M a p  Class //--------------------------------------------------------------
/*CLASS ExtendableMap */
/* Represents a map of extendable objects. It allows to manage the additional properties of these
   objets through property maps. */
public class ExtendableMap extends ExtendableContainer implements Map {
 //---------------------------------------------------------------------------------------Attributes
 protected Map atMap; // Map object that is actually wrapped.
 //--------------------------------------------------------------------------------------Constructor
 /*METHOD ExtendableMap */ /* Builds an extendable map around an existing map. */
 public ExtendableMap(Map agMap) {
  super();
  atMap=agMap;
 }
 //--------------------------------------------------------------------------------------------Clear
 /*METHOD ExtendableMap */ /* Removes all the mappings from the map. */
 public void clear() {
  Iterator lcIterator = iterator();

  while (lcIterator.hasNext()) detachProperties((ExtendableObject)lcIterator.next());
  atMap.clear();
 }
 //--------------------------------------------------------------------------------------ContainsKey
 /*METHOD ExtendableMap */
 /* Returns <CODE>true</CODE> if the map contains a mapping for the specified key. */
 public boolean containsKey(Object agKey) { return (atMap.containsKey(agKey)); }
 //------------------------------------------------------------------------------------ContainsValue
 /*METHOD ExtendableMap */
 /* Returns <CODE>true</CODE> if the container maps one or more keys to the specified value. */
 public boolean containsValue(Object agValue) { return (atMap.containsValue(agValue)); }
 //-----------------------------------------------------------------------------------------EntrySet
 /*METHOD ExtendableMap */ /* Returns a set of the mappings contained in the map. */
 public Set entrySet() { return (atMap.entrySet()); }
 //-------------------------------------------------------------------------------------------Equals
 /*METHOD ExtendableMap */ /* Compares the specified object with the map for equality. */
 public boolean equals(Object agObject) { return (atMap.equals(agObject)); }
 //----------------------------------------------------------------------------------------------Get
 /*METHOD ExtendableMap */ /* Returns the value to which the container maps the specified key. */
 public Object get(Object agKey) { return (atMap.get(agKey)); }
 //-----------------------------------------------------------------------------------------HashCode
 /*METHOD ExtendableMap */ /* Returns the hash code value for the map. */
 public int hashCode() { return (atMap.hashCode()); }
 //------------------------------------------------------------------------------------------IsEmpty
 /*METHOD ExtendableMap */ /* Returns <CODE>true</CODE> if the map contains no mapping. */
 public boolean isEmpty() { return (atMap.isEmpty()); }
 //-----------------------------------------------------------------------------------------Iterator
 /*METHOD ExtendableMap */ /* Returns an iterator over the values contained in the map. */
 public Iterator iterator() { return (atMap.values().iterator()); }
 //-------------------------------------------------------------------------------------------KeySet
 /*METHOD ExtendableMap */ /* Returns a set of the keys contained in the map. */
 public Set keySet() { return (atMap.keySet()); }
 //----------------------------------------------------------------------------------------------Put
 /*METHOD ExtendableMap */ /* Associates the specified value with the specified key in the map. */
 public Object put(Object agKey,Object agValue) {
  attachProperties((ExtendableObject)agValue);
  return (atMap.put(agKey,agValue));
 }
 //-------------------------------------------------------------------------------------------PutAll
 /*METHOD ExtendableMap */
 /* Copies all the mappings from the specified map to this map. <B>Not implemented yet.</B> */
 public void putAll(Map agMap) { atMap.putAll(agMap); }
 //-------------------------------------------------------------------------------------------Remove
 /*METHOD ExtendableMap */
 /* Removes the mapping for the specified key from the map, if it is present. */
 public Object remove(Object agKey) {
  detachProperties((ExtendableObject)atMap.get(agKey));
  return (atMap.remove(agKey));
 }
 //---------------------------------------------------------------------------------------------Size
 /*METHOD ExtendableMap */ /* Returns the number of mappings in the map. */
 public int size() { return (atMap.size()); }
 //-------------------------------------------------------------------------------------------Values
 /*METHOD ExtendableMap */ /* Returns a collection of the values contained in the map. */
 public Collection values() { return (atMap.values()); }
}

// End //-------------------------------------------------------------------------------------------