Class TMap

Description

Implements interfaces:

  • IteratorAggregate (internal interface)
  • ArrayAccess (internal interface)
  • Countable (internal interface)

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
  5.  $n=count($map);  // returns the number of items in the map

  • author: Qiang Xue <qiang.xue@gmail.com>
  • version: $Id: TMap.php 2996 2011-06-20 15:24:57Z ctrlaltca@gmail.com $
  • since: 3.0

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

TComponent
   |
   --TMap
Direct descendents
Class Description
TAttributeCollection TAttributeCollection class
TPriorityMap TPriorityMap 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.

  • throws: TInvalidDataTypeException If data is not null and neither an array nor an iterator.
  • access: public
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

Redefined in descendants as:
add (line 130)

Adds an item into the map.

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

  • throws: TInvalidOperationException if the map is read-only
  • access: public
void add (mixed $key, mixed $value)
  • mixed $key: key
  • mixed $value: value

Redefined in descendants as:
  • TAttributeCollection::add() : Adds an item into the map.
  • TPriorityMap::add() : Adds an item into the map. A third parameter may be used to set the priority of the item within the map. Priority is primarily used during when flattening the map into an array where order may be and important factor of the key-value pairs within the array.
clear (line 164)

Removes all items in the map.

  • access: public
void clear ()

Redefined in descendants as:
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:
copyFrom (line 193)

Copies iterable data into the map.

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

  • throws: TInvalidDataTypeException If data is neither an array nor an iterator.
  • access: public
void copyFrom (mixed $data)
  • mixed $data: the data to be copied from, must be an array or object implementing Traversable

Redefined in descendants as:
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 ()

Implementation of:
Countable::count

Redefined in descendants as:
getCount (line 99)
  • return: the number of items in the map
  • access: public
integer getCount ()

Redefined in descendants as:
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 ()

Implementation of:
IteratorAggregate::getIterator

Redefined in descendants as:
getKeys (line 107)
  • return: the key list
  • access: public
array getKeys ()

Redefined in descendants as:
getReadOnly (line 63)
  • return: whether this map is read-only or not. Defaults to false.
  • access: public
boolean getReadOnly ()

Redefined in descendants as:
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:
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.

  • throws: TInvalidDataTypeException If data is neither an array nor an iterator.
  • access: public
void mergeWith (mixed $data)
  • mixed $data: the data to be merged with, must be an array or object implementing Traversable

Redefined in descendants as:
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

Implementation of:
ArrayAccess::offsetExists

Redefined in descendants as:
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.

Implementation of:
ArrayAccess::offsetGet

Redefined in descendants as:
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

Implementation of:
ArrayAccess::offsetSet

Redefined in descendants as:
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

Implementation of:
ArrayAccess::offsetUnset

Redefined in descendants as:
remove (line 144)

Removes an item from the map by its key.

  • return: the removed value, null if no such key exists.
  • throws: TInvalidOperationException if the map is read-only
  • access: public
mixed remove (mixed $key)
  • mixed $key: the key of the item to be removed

Redefined in descendants as:
setReadOnly (line 71)
  • access: protected
void setReadOnly (boolean $value)
  • boolean $value: whether this list is read-only or not

Redefined in descendants as:
toArray (line 182)
  • return: the list of items in array
  • access: public
array toArray ()

Redefined in descendants as:
  • TPriorityMap::toArray() : When the map is flattened into an array, the priorities are taken into account and elements of the map are ordered in the array according to their priority.

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::__call()
TComponent::__get()
TComponent::__set()
TComponent::__sleep()
TComponent::__wakeup()

Documentation generated on Mon, 25 Jun 2012 14:38:41 +0200 by phpDocumentor 1.4.3