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,

  1. $map[$key]=$value; // add a key-value pair
  2. unset($map[$key]); // remove the value with the specified key
  3. if(isset($map[$key])) // if the map contains the key
  4. 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.

To extend TMap by doing additional operations with each added or removed item, you can override addedItem and removedItem. You can also override canAddItem and canRemoveItem to control whether to add or remove a particular item.

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

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

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

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:
clear (line 160)

Removes all items in the map.

  • access: public
void clear ()
contains (line 170)
  • 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:
copyFrom (line 189)

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 95)
  • return: the number of items in the map
  • access: public
integer getCount ()
getIterator (line 87)

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 103)
  • return: the key list
  • access: public
array getKeys ()
getReadOnly (line 69)
  • return: whether this map is read-only or not. Defaults to false.
  • access: public
boolean getReadOnly ()
itemAt (line 114)

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:
mergeWith (line 208)

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

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

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

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

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

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:
setReadOnly (line 77)
  • access: protected
void setReadOnly (boolean $value)
  • boolean $value: whether this list is read-only or not
toArray (line 178)
  • 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 Mon, 01 May 2006 23:04:07 -0400 by phpDocumentor 1.3.0RC4