## Class TMap

Description

Implements interfaces:

TMap class

TMap implements a collection that takes key-value pairs.

You can access, add or remove an item with a key by using itemAt, add, and remove. To get the number of the items in the map, use getCount. TMap can also be used like a regular array as follows,

     $map[$key]=$value; // add a key-value pair
      unset($map[$key]); // remove the value with the specified key
      if(isset($map[$key])) // if the map contains the key
      foreach($map as $key=>$value) // traverse the items in the map
      $n=count($map);  // returns the number of items in the map

- since: 3.0
- version: $Id: TMap.php 1398 2006-09-08 19:31:03Z xue $
- author: Qiang Xue <qiang.xue@gmail.com>

Located in /Collections/TMap.php (line 35)

    TComponent
       |
       --TMap

Direct descendents

Class | Description
--- | ---
TAttributeCollection | TAttributeCollection class

Method Summary
TMap __construct ([array|Iterator $data = null], [boolean $readOnly = false])
void add (mixed $key, mixed $value)
void clear ()
boolean contains (mixed $key)
void copyFrom (mixed $data)
integer count ()
integer getCount ()
Iterator getIterator ()
array getKeys ()
boolean getReadOnly ()
mixed itemAt (mixed $key)
void mergeWith (mixed $data)
boolean offsetExists (mixed $offset)
mixed offsetGet (integer $offset)
void offsetSet (integer $offset, mixed $item)
void offsetUnset (mixed $offset)
mixed remove (mixed $key)
void setReadOnly (boolean $value)
array toArray ()
Methods
Constructor __construct (line 53)

Constructor.

Initializes the list with an array or an iterable object.

- access: public
- throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.

TMap __construct ([array|Iterator $data = null], [boolean $readOnly = false])

- array|Iterator $data: the intial data. Default is null, meaning no initialization.
- boolean $readOnly: whether the list is read-only

add (line 130)

Adds an item into the map.

Note, if the specified key already exists, the old value will be overwritten.

- access: public
- throws: TInvalidOperationException if the map is read-only

void add (mixed $key, mixed $value)

- mixed $key: key
- mixed $value: value

Redefined in descendants as:

- TAttributeCollection::add() : Adds an item into the map.

clear (line 164)

Removes all items in the map.

- access: public

void clear ()
contains (line 174)

- return: whether the map contains an item with the specified key
- access: public

boolean contains (mixed $key)

- mixed $key: the key

Redefined in descendants as:

- TAttributeCollection::contains() : Returns whether the specified is in the map.

copyFrom (line 193)

Copies iterable data into the map.

Note, existing data in the map will be cleared first.

- access: public
- throws: TInvalidDataTypeException If data is neither an array nor an iterator.

void copyFrom (mixed $data)

- mixed $data: the data to be copied from, must be an array or object implementing Traversable

count (line 91)

Returns the number of items in the map.

This method is required by Countable interface.

- return: number of items in the map.
- access: public

integer count ()
getCount (line 99)

- return: the number of items in the map
- access: public

integer getCount ()
getIterator (line 81)

Returns an iterator for traversing the items in the list.

This method is required by the interface IteratorAggregate.

- return: an iterator for traversing the items in the list.
- access: public

Iterator getIterator ()
getKeys (line 107)

- return: the key list
- access: public

array getKeys ()
getReadOnly (line 63)

- return: whether this map is read-only or not. Defaults to false.
- access: public

boolean getReadOnly ()
itemAt (line 118)

Returns the item with the specified key.

This method is exactly the same as offsetGet.

- return: the element at the offset, null if no element is found at the offset
- access: public

mixed itemAt (mixed $key)

- mixed $key: the key

Redefined in descendants as:

- TAttributeCollection::itemAt() : Returns the item with the specified key.

mergeWith (line 212)

Merges iterable data into the map.

Existing data in the map will be kept and overwritten if the keys are the same.

- access: public
- throws: TInvalidDataTypeException If data is neither an array nor an iterator.

void mergeWith (mixed $data)

- mixed $data: the data to be merged with, must be an array or object implementing Traversable

offsetExists (line 229)

Returns whether there is an element at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

boolean offsetExists (mixed $offset)

- mixed $offset: the offset to check on

offsetGet (line 240)

Returns the element at the specified offset.

This method is required by the interface ArrayAccess.

- return: the element at the offset, null if no element is found at the offset
- access: public

mixed offsetGet (integer $offset)

- integer $offset: the offset to retrieve element.

offsetSet (line 251)

Sets the element at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

void offsetSet (integer $offset, mixed $item)

- integer $offset: the offset to set element
- mixed $item: the element value

offsetUnset (line 261)

Unsets the element at the specified offset.

This method is required by the interface ArrayAccess.

- access: public

void offsetUnset (mixed $offset)

- mixed $offset: the offset to unset element

remove (line 144)

Removes an item from the map by its key.

- return: the removed value, null if no such key exists.
- access: public
- throws: TInvalidOperationException if the map is read-only

mixed remove (mixed $key)

- mixed $key: the key of the item to be removed

Redefined in descendants as:

- TAttributeCollection::remove() : Removes an item from the map by its key.

setReadOnly (line 71)

- access: protected

void setReadOnly (boolean $value)

- boolean $value: whether this list is read-only or not

toArray (line 182)

- return: the list of items in array
- access: public

array toArray ()

#### Inherited Methods

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Documentation generated on Sun, 14 Jan 2007 21:43:25 -0500 by phpDocumentor 1.3.0RC4