PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TPriorityMap

TMap class

TMap implements a collection that takes key-value pairs.

You can access, add or remove an item with a key by using TPriorityMap::itemAt(), TPriorityMap::add(), and TPriorityMap::remove(). To get the number of the items in the map, use TPriorityMap::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
TComponent
Extended by TMap implements IteratorAggregate, ArrayAccess, Countable
Extended by TPriorityMap
Package: System\Collections
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Collections/TPriorityMap.php
Methods summary
public
# __construct( map|array|Iterator|TPriorityMap $data = null, boolean $readOnly = false, numeric $defaultPriority = 10, integer $precision = 8 )

Constructor. Initializes the array with an array or an iterable object.

Constructor. Initializes the array with an array or an iterable object.

Parameters

$data
map|array|Iterator|TPriorityMap
the intial data. Default is null, meaning no initialization.
$readOnly
boolean
whether the list is read-only
$defaultPriority
numeric
the default priority of items without specified priorities.
$precision
integer
the precision of the numeric priorities

Throws

TInvalidDataTypeException
If data is not null and neither an array nor an iterator.

Overrides

TMap::__construct()
public boolean
# getReadOnly( )

Returns

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

Overrides

TMap::getReadOnly()
protected
# setReadOnly( boolean $value )

Parameters

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

Overrides

TMap::setReadOnly()
public numeric
# getDefaultPriority( )

Returns

numeric
gets the default priority of inserted items without a specified priority
protected
# setDefaultPriority( numeric $value )

This must be called internally or when instantiated.

This must be called internally or when instantiated.

Parameters

$value
numeric
sets the default priority of inserted items without a specified priority
public integer
# getPrecision( )

Returns

integer
The precision of numeric priorities, defaults to 8
protected
# setPrecision( integer $value )

This must be called internally or when instantiated.

This must be called internally or when instantiated.

Parameters

$value
integer
The precision of numeric priorities.
public Iterator
# getIterator( )

Returns an iterator for traversing the items in the map. This method is required by the interface IteratorAggregate.

Returns an iterator for traversing the items in the map. This method is required by the interface IteratorAggregate.

Returns

Iterator
an iterator for traversing the items in the map.

Overrides

TMap::getIterator()
protected
# sortPriorities( )

Orders the priority list internally.

Orders the priority list internally.

protected array
# flattenPriorities( )

This flattens the priority map into a flat array [0,...,n-1]

This flattens the priority map into a flat array [0,...,n-1]

Returns

array
array of items in the list in priority and index order
public integer
# count( )

Returns the number of items in the map. This method is required by Countable interface.

Returns the number of items in the map. This method is required by Countable interface.

Returns

integer
number of items in the map.

Overrides

TMap::count()
public integer
# getCount( )

Returns

integer
the number of items in the map

Overrides

TMap::getCount()
public integer
# getPriorityCount( numeric $priority = null )

Gets the number of items at a priority within the map.

Gets the number of items at a priority within the map.

Parameters

$priority
numeric
optional priority at which to count items. if no parameter, it will be set to the default TPriorityMap::getDefaultPriority()

Returns

integer
the number of items in the map at the specified priority
public array
# getPriorities( )

This returns a list of the priorities within this map, ordered lowest to highest.

This returns a list of the priorities within this map, ordered lowest to highest.

Returns

array
the array of priority numerics in decreasing priority order
public array
# getKeys( )

Returns the keys within the map ordered through the priority of each key-value pair

Returns the keys within the map ordered through the priority of each key-value pair

Returns

array
the key list

Overrides

TMap::getKeys()
public mixed
# itemAt( mixed $key, mixed $priority = false )

Returns the item with the specified key. If a priority is specified, only items within that specific priority will be selected

Returns the item with the specified key. If a priority is specified, only items within that specific priority will be selected

Parameters

$key
mixed
the key
$priority
mixed
the priority. null is the default priority, false is any priority, and numeric is a specific priority. default: false, any priority.

Returns

mixed
the element at the offset, null if no element is found at the offset

Overrides

TMap::itemAt()
public numeric
# setPriorityAt( mixed $key, numeric|null $priority = null )

This changes an item's priority. Specify the item and the new priority. This method is exactly the same as TPriorityMap::offsetGet().

This changes an item's priority. Specify the item and the new priority. This method is exactly the same as TPriorityMap::offsetGet().

Parameters

$key
mixed
the key
$priority
numeric|null
the priority. default: null, filled in with the default priority numeric.

Returns

numeric
old priority of the item
public array
# itemsAtPriority( numeric $priority = null )

Gets all the items at a specific priority.

Gets all the items at a specific priority.

Parameters

$priority
numeric
priority of the items to get. Defaults to null, filled in with the default priority, if left blank.

Returns

array
all items at priority in index order, null if there are no items at that priority
public numeric
# priorityOf( mixed $item )

Returns the priority of a particular item within the map. This searches the map for the item.

Returns the priority of a particular item within the map. This searches the map for the item.

Parameters

$item
mixed
item to look for within the map

Returns

numeric
priority of the item in the map
public numeric
# priorityAt( integer $key )

Retutrns the priority of an item at a particular flattened index.

Retutrns the priority of an item at a particular flattened index.

Parameters

$key
integer
index of the item within the map

Returns

numeric
priority of the item in the map
public numeric
# add( mixed $key, mixed $value, numeric|null $priority = null )

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. Note, if the specified key already exists, the old value will be overwritten. No duplicate keys are allowed regardless of priority.

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. Note, if the specified key already exists, the old value will be overwritten. No duplicate keys are allowed regardless of priority.

Parameters

$key
mixed
key
$value
mixed
value
$priority
numeric|null
priority, default: null, filled in with default priority

Returns

numeric
priority at which the pair was added

Throws

TInvalidOperationException
if the map is read-only

Overrides

TMap::add()
public mixed
# remove( mixed $key, numeric|false|null $priority = false )

Removes an item from the map by its key. If no priority, or false, is specified then priority is irrelevant. If null is used as a parameter for priority, then the priority will be the default priority. If a priority is specified, or the default priority is specified, only key-value pairs in that priority will be affected.

Removes an item from the map by its key. If no priority, or false, is specified then priority is irrelevant. If null is used as a parameter for priority, then the priority will be the default priority. If a priority is specified, or the default priority is specified, only key-value pairs in that priority will be affected.

Parameters

$key
mixed
the key of the item to be removed
$priority
numeric|false|null
priority. False is any priority, null is the default priority, and numeric is a specific priority

Returns

mixed
the removed value, null if no such key exists.

Throws

TInvalidOperationException
if the map is read-only

Overrides

TMap::remove()
public
# clear( )

Removes all items in the map. TPriorityMap::remove() is called on all items.

Removes all items in the map. TPriorityMap::remove() is called on all items.

Overrides

TMap::clear()
public boolean
# contains( mixed $key )

Parameters

$key
mixed
the key

Returns

boolean
whether the map contains an item with the specified key

Overrides

TMap::contains()
public array
# 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.

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.

Returns

array
the list of items in array

Overrides

TMap::toArray()
public array
# toArrayBelowPriority( numeric $priority, boolean $inclusive = false )

Combines the map elements which have a priority below the parameter value

Combines the map elements which have a priority below the parameter value

Parameters

$priority
numeric
the cut-off priority. All items of priority less than this are returned.
$inclusive
boolean
whether or not the input cut-off priority is inclusive. Default: false, not inclusive.

Returns

array
the array of priorities keys with values of arrays of items that are below a specified priority. The priorities are sorted so important priorities, lower numerics, are first.
public array
# toArrayAbovePriority( numeric $priority, boolean $inclusive = true )

Combines the map elements which have a priority above the parameter value

Combines the map elements which have a priority above the parameter value

Parameters

$priority
numeric
the cut-off priority. All items of priority greater than this are returned.
$inclusive
boolean
whether or not the input cut-off priority is inclusive. Default: true, inclusive.

Returns

array
the array of priorities keys with values of arrays of items that are above a specified priority. The priorities are sorted so important priorities, lower numerics, are first.
public
# copyFrom( mixed $data )

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

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

Parameters

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

Throws

TInvalidDataTypeException
If data is neither an array nor an iterator.

Overrides

TMap::copyFrom()
public
# 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.

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

Parameters

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

Throws

TInvalidDataTypeException
If data is neither an array nor an iterator.

Overrides

TMap::mergeWith()
public boolean
# offsetExists( mixed $offset )

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to check on

Returns

boolean

Overrides

TMap::offsetExists()
public mixed
# offsetGet( integer $offset )

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Returns the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
integer
the offset to retrieve element.

Returns

mixed
the element at the offset, null if no element is found at the offset

Overrides

TMap::offsetGet()
public
# offsetSet( integer $offset, mixed $item )

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Sets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

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

Overrides

TMap::offsetSet()
public
# offsetUnset( mixed $offset )

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Unsets the element at the specified offset. This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to unset element

Overrides

TMap::offsetUnset()
Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO