-<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.HashMap-method-constructor'><span id='Ext-util.HashMap'>/**
-</span></span> * @class Ext.util.HashMap
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>The source code</title>
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+ <style type="text/css">
+ .highlight { display: block; background-color: #ddd; }
+ </style>
+ <script type="text/javascript">
+ function highlight() {
+ document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
+ }
+ </script>
+</head>
+<body onload="prettyPrint(); highlight();">
+ <pre class="prettyprint lang-js"><span id='Ext-util-HashMap'>/**
+</span> * @class Ext.util.HashMap
* <p>
* Represents a collection of a set of key and value pairs. Each key in the HashMap
* must be unique, the same key cannot exist twice. Access to items is provided via
* there is no guarantee when iterating over the items that they will be in any particular
* order. If this is required, then use a {@link Ext.util.MixedCollection}.
* </p>
- * @constructor
- * @param {Object} config The configuration options
*/
Ext.define('Ext.util.HashMap', {
+ mixins: {
+ observable: 'Ext.util.Observable'
+ },
-<span id='Ext-util.HashMap-cfg-keyFn'> /**
+<span id='Ext-util-HashMap-cfg-keyFn'> /**
</span> * @cfg {Function} keyFn A function that is used to retrieve a default key for a passed object.
* A default is provided that returns the <b>id</b> property on the object. This function is only used
* if the add method is called with a single argument.
*/
- mixins: {
- observable: 'Ext.util.Observable'
- },
-
+<span id='Ext-util-HashMap-method-constructor'> /**
+</span> * Creates new HashMap.
+ * @param {Object} config (optional) Config object.
+ */
constructor: function(config) {
- var me = this;
+ config = config || {};
+
+ var me = this,
+ keyFn = config.keyFn;
me.addEvents(
-<span id='Ext-util.HashMap-event-add'> /**
+<span id='Ext-util-HashMap-event-add'> /**
</span> * @event add
* Fires when a new item is added to the hash
* @param {Ext.util.HashMap} this.
* @param {Object} value The value of the added item.
*/
'add',
-<span id='Ext-util.HashMap-event-clear'> /**
+<span id='Ext-util-HashMap-event-clear'> /**
</span> * @event clear
* Fires when the hash is cleared.
* @param {Ext.util.HashMap} this.
*/
'clear',
-<span id='Ext-util.HashMap-event-remove'> /**
+<span id='Ext-util-HashMap-event-remove'> /**
</span> * @event remove
* Fires when an item is removed from the hash.
* @param {Ext.util.HashMap} this.
* @param {Object} value The value of the removed item.
*/
'remove',
-<span id='Ext-util.HashMap-event-replace'> /**
+<span id='Ext-util-HashMap-event-replace'> /**
</span> * @event replace
* Fires when an item is replaced in the hash.
* @param {Ext.util.HashMap} this.
me.mixins.observable.constructor.call(me, config);
me.clear(true);
+
+ if (keyFn) {
+ me.getKey = keyFn;
+ }
},
-<span id='Ext-util.HashMap-method-getCount'> /**
+<span id='Ext-util-HashMap-method-getCount'> /**
</span> * Gets the number of items in the hash.
* @return {Number} The number of items in the hash.
*/
return this.length;
},
-<span id='Ext-util.HashMap-method-getData'> /**
+<span id='Ext-util-HashMap-method-getData'> /**
</span> * Implementation for being able to extract the key from an object if only
* a single argument is passed.
* @private
return [key, value];
},
-<span id='Ext-util.HashMap-method-getKey'> /**
+<span id='Ext-util-HashMap-method-getKey'> /**
</span> * Extracts the key from an object. This is a default implementation, it may be overridden
- * @private
* @param {Object} o The object to get the key from
* @return {String} The key to use.
*/
return o.id;
},
-<span id='Ext-util.HashMap-method-add'> /**
+<span id='Ext-util-HashMap-method-add'> /**
</span> * Adds an item to the collection. Fires the {@link #add} event when complete.
* @param {String} key <p>The key to associate with the item, or the new item.</p>
* <p>If a {@link #getKey} implementation was specified for this HashMap,
}
if (me.containsKey(key)) {
- me.replace(key, value);
+ return me.replace(key, value);
}
data = me.getData(key, value);
return value;
},
-<span id='Ext-util.HashMap-method-replace'> /**
+<span id='Ext-util-HashMap-method-replace'> /**
</span> * Replaces an item in the hash. If the key doesn't exist, the
* {@link #add} method will be used.
* @param {String} key The key of the item.
return value;
},
-<span id='Ext-util.HashMap-method-remove'> /**
+<span id='Ext-util-HashMap-method-remove'> /**
</span> * Remove an item from the hash.
* @param {Object} o The value of the item to remove.
* @return {Boolean} True if the item was successfully removed.
return false;
},
-<span id='Ext-util.HashMap-method-removeAtKey'> /**
+<span id='Ext-util-HashMap-method-removeAtKey'> /**
</span> * Remove an item from the hash.
* @param {String} key The key to remove.
* @return {Boolean} True if the item was successfully removed.
return false;
},
-<span id='Ext-util.HashMap-method-get'> /**
+<span id='Ext-util-HashMap-method-get'> /**
</span> * Retrieves an item with a particular key.
* @param {String} key The key to lookup.
* @return {Object} The value at that key. If it doesn't exist, <tt>undefined</tt> is returned.
return this.map[key];
},
-<span id='Ext-util.HashMap-method-clear'> /**
+<span id='Ext-util-HashMap-method-clear'> /**
</span> * Removes all items from the hash.
* @return {Ext.util.HashMap} this
*/
return me;
},
-<span id='Ext-util.HashMap-method-containsKey'> /**
+<span id='Ext-util-HashMap-method-containsKey'> /**
</span> * Checks whether a key exists in the hash.
* @param {String} key The key to check for.
* @return {Boolean} True if they key exists in the hash.
return this.map[key] !== undefined;
},
-<span id='Ext-util.HashMap-method-contains'> /**
+<span id='Ext-util-HashMap-method-contains'> /**
</span> * Checks whether a value exists in the hash.
* @param {Object} value The value to check for.
* @return {Boolean} True if the value exists in the dictionary.
return this.containsKey(this.findKey(value));
},
-<span id='Ext-util.HashMap-method-getKeys'> /**
+<span id='Ext-util-HashMap-method-getKeys'> /**
</span> * Return all of the keys in the hash.
* @return {Array} An array of keys.
*/
return this.getArray(true);
},
-<span id='Ext-util.HashMap-method-getValues'> /**
+<span id='Ext-util-HashMap-method-getValues'> /**
</span> * Return all of the values in the hash.
* @return {Array} An array of values.
*/
return this.getArray(false);
},
-<span id='Ext-util.HashMap-method-getArray'> /**
+<span id='Ext-util-HashMap-method-getArray'> /**
</span> * Gets either the keys/values in an array from the hash.
* @private
* @param {Boolean} isKey True to extract the keys, otherwise, the value
return arr;
},
-<span id='Ext-util.HashMap-method-each'> /**
+<span id='Ext-util-HashMap-method-each'> /**
</span> * Executes the specified function once for each item in the hash.
* Returning false from the function will cease iteration.
*
return this;
},
-<span id='Ext-util.HashMap-method-clone'> /**
+<span id='Ext-util-HashMap-method-clone'> /**
</span> * Performs a shallow copy on this hash.
* @return {Ext.util.HashMap} The new hash object.
*/
return hash;
},
-<span id='Ext-util.HashMap-method-findKey'> /**
+<span id='Ext-util-HashMap-method-findKey'> /**
</span> * @private
* Find the key for a value.
* @param {Object} value The value to find.
return undefined;
}
});
-</pre></pre></body></html>
\ No newline at end of file
+</pre>
+</body>
+</html>