## 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

Note, count($map) will always return 1. You should use getCount() to determine the number of items in the map.

- since: 3.0
- version: $Revision: $ $Date: $
- author: Qiang Xue <qiang.xue@gmail.com>

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

    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 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 54)

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 121)

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 155)

Removes all items in the map.

- access: public

void clear ()
contains (line 165)

- 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 184)

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

getCount (line 90)

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

integer getCount ()
getIterator (line 82)

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 98)

- return: the key list
- access: public

array getKeys ()
getReadOnly (line 64)

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

boolean getReadOnly ()
itemAt (line 109)

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 203)

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 220)

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 231)

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 242)

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 252)

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 135)

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 72)

- access: protected

void setReadOnly (boolean $value)

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

toArray (line 173)

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

array toArray ()

#### Inherited Methods

Inherited From TComponent

> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> 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, 04 Jun 2006 18:59:53 -0400 by phpDocumentor 1.3.0RC4