Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TMap

TComponent
   |
   --TMap

Direct Known Sub-classes:

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

Since: 3.0
Author: Qiang Xue <qiang.xue@gmail.com>

Constructor Summary
public
__construct Array
Constructor.

Method Summary
void
add ( mixed $key, mixed $value)
Adds an item into the map.
void
clear ()
Removes all items in the map.
boolean
contains ( mixed $key)
void
copyFrom ( mixed $data)
Copies iterable data into the map.
integer
count ()
Returns the number of items in the map.
integer
Iterator
Returns an iterator for traversing the items in the list.
array
getKeys ()
boolean
mixed
itemAt ( mixed $key)
Returns the item with the specified key.
void
mergeWith ( mixed $data)
Merges iterable data into the map.
boolean
offsetExists ( mixed $offset)
Returns whether there is an element at the specified offset.
mixed
offsetGet ( integer $offset)
Returns the element at the specified offset.
void
offsetSet ( integer $offset, mixed $item)
Sets the element at the specified offset.
void
offsetUnset ( mixed $offset)
Unsets the element at the specified offset.
mixed
remove ( mixed $key)
Removes an item from the map by its key.
protected  void
setReadOnly ( boolean $value)
array
toArray ()
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()

Constructor Details

__construct

public __construct Array

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.

Method Details

add

public void add (mixed $key , mixed $value )

Adds an item into the map.

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

Input
mixed$keykey
mixed$valuevalue
Output
Exception
throwsTInvalidOperationException if the map is read-only

clear

public void clear ()

Removes all items in the map.

Output
Exception

contains

public boolean contains (mixed $key )

Input
mixed$keythe key
Output
boolean whether the map contains an item with the specified key
Exception

copyFrom

public void copyFrom (mixed $data )

Copies iterable data into the map.

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

Input
mixed$datathe data to be copied from, must be an array or object implementing Traversable
Output
Exception
throwsTInvalidDataTypeException If data is neither an array nor an iterator.

count

public integer count ()

Returns the number of items in the map.

This method is required by Countable interface.

Output
integer number of items in the map.
Exception

getCount

public integer getCount ()

Output
integer the number of items in the map
Exception

getIterator

public Iterator getIterator ()

Returns an iterator for traversing the items in the list.

This method is required by the interface IteratorAggregate.

Output
Iterator an iterator for traversing the items in the list.
Exception

getKeys

public array getKeys ()

Output
array the key list
Exception

getReadOnly

public boolean getReadOnly ()

Output
boolean whether this map is read-only or not. Defaults to false.
Exception

itemAt

public mixed itemAt (mixed $key )

Returns the item with the specified key.

This method is exactly the same as offsetGet.

Input
mixed$keythe key
Output
mixed the element at the offset, null if no element is found at the offset
Exception

mergeWith

public void mergeWith (mixed $data )

Merges iterable data into the map.

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

Input
mixed$datathe data to be merged with, must be an array or object implementing Traversable
Output
Exception
throwsTInvalidDataTypeException If data is neither an array nor an iterator.

offsetExists

public boolean offsetExists (mixed $offset )

Returns whether there is an element at the specified offset.

This method is required by the interface ArrayAccess.

Input
mixed$offsetthe offset to check on
Output
Exception

offsetGet

public mixed offsetGet (integer $offset )

Returns the element at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer$offsetthe offset to retrieve element.
Output
mixed the element at the offset, null if no element is found at the offset
Exception

offsetSet

public void offsetSet (integer $offset , mixed $item )

Sets the element at the specified offset.

This method is required by the interface ArrayAccess.

Input
integer$offsetthe offset to set element
mixed$itemthe element value
Output
Exception

offsetUnset

public void offsetUnset (mixed $offset )

Unsets the element at the specified offset.

This method is required by the interface ArrayAccess.

Input
mixed$offsetthe offset to unset element
Output
Exception

remove

public mixed remove (mixed $key )

Removes an item from the map by its key.

Input
mixed$keythe key of the item to be removed
Output
mixed the removed value, null if no such key exists.
Exception
throwsTInvalidOperationException if the map is read-only

setReadOnly

protected void setReadOnly (boolean $value )

Input
boolean$valuewhether this list is read-only or not
Output
Exception

toArray

public array toArray ()

Output
array the list of items in array
Exception