PHP 클래스 Prado\Collections\TPriorityMap

TPriorityMap implements a collection that takes key-value pairs with a priority to allow key-value pairs to be ordered. This ordering is important when flattening the map. When flattening the map, if some key-value pairs are required to be before or after others, use this class to keep order to your map. You can access, add or remove an item with a key by using {@link itemAt}, {@link add}, and {@link remove}. These functions can optionally take a priority parameter to allow access to specific priorities. TPriorityMap is functionally backward compatible with {@link TMap}. To get the number of the items in the map, use {@link getCount}. TPriorityMap 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 Using standard array access method like these will always use the default priority. An item that doesn't specify a priority will receive the default priority. The default priority is set during the instantiation of a new TPriorityMap. If no custom default priority is specified, the standard default priority of 10 is used. Priorities with significant digits below precision will be rounded. A priority may also be a numeric with decimals. This is set during the instantiation of a new TPriorityMap. The default is 8 decimal places for a priority. If a negative number is used, rounding occurs into the integer space rather than in the decimal space. See {@link round}.
부터: 3.2a
저자: Brad Anderson ([email protected])
상속: extends TMap
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( $data = null, $readOnly = false, $defaultPriority = 10, $precision = 8 ) Constructor.
add ( $key, $value, $priority = null ) : numeric 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 ( ) Removes all items in the map. {@link remove} is called on all items.
contains ( $key ) : boolean
copyFrom ( $data ) Copies iterable data into the map.
count ( ) : integer Returns the number of items in the map.
getCount ( ) : integer
getDefaultPriority ( ) : numeric
getIterator ( ) : Iterator Returns an iterator for traversing the items in the map.
getKeys ( ) : array Returns the keys within the map ordered through the priority of each key-value pair
getPrecision ( ) : integer
getPriorities ( ) : array This returns a list of the priorities within this map, ordered lowest to highest.
getPriorityCount ( $priority = null ) : integer Gets the number of items at a priority within the map.
getReadOnly ( ) : boolean
itemAt ( $key, $priority = false ) : mixed Returns the item with the specified key. If a priority is specified, only items within that specific priority will be selected
itemsAtPriority ( $priority = null ) : array Gets all the items at a specific priority.
mergeWith ( $data ) Merges iterable data into the map.
offsetExists ( $offset ) : boolean Returns whether there is an element at the specified offset.
offsetGet ( $offset ) : mixed Returns the element at the specified offset.
offsetSet ( $offset, $item ) Sets the element at the specified offset.
offsetUnset ( $offset ) Unsets the element at the specified offset.
priorityAt ( $key ) : numeric Retutrns the priority of an item at a particular flattened index.
priorityOf ( $item ) : numeric Returns the priority of a particular item within the map. This searches the map for the item.
remove ( $key, $priority = false ) : mixed 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.
setPriorityAt ( $key, $priority = null ) : numeric This changes an item's priority. Specify the item and the new priority.
toArray ( ) : array 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.
toArrayAbovePriority ( $priority, $inclusive = true ) : array Combines the map elements which have a priority above the parameter value
toArrayBelowPriority ( $priority, $inclusive = false ) : array Combines the map elements which have a priority below the parameter value

보호된 메소드들

메소드 설명
flattenPriorities ( ) : array This flattens the priority map into a flat array [0,.
setDefaultPriority ( $value ) This must be called internally or when instantiated.
setPrecision ( $value ) This must be called internally or when instantiated.
setReadOnly ( $value )
sortPriorities ( ) Orders the priority list internally.

메소드 상세

__construct() 공개 메소드

Initializes the array with an array or an iterable object.
public __construct ( $data = null, $readOnly = false, $defaultPriority = 10, $precision = 8 )

add() 공개 메소드

Note, if the specified key already exists, the old value will be overwritten. No duplicate keys are allowed regardless of priority.
public add ( $key, $value, $priority = null ) : numeric
리턴 numeric priority at which the pair was added

clear() 공개 메소드

Removes all items in the map. {@link remove} is called on all items.
public clear ( )

contains() 공개 메소드

public contains ( $key ) : boolean
리턴 boolean whether the map contains an item with the specified key

copyFrom() 공개 메소드

Note, existing data in the map will be cleared first.
public copyFrom ( $data )

count() 공개 메소드

This method is required by \Countable interface.
public count ( ) : integer
리턴 integer number of items in the map.

flattenPriorities() 보호된 메소드

..,n-1]
protected flattenPriorities ( ) : array
리턴 array array of items in the list in priority and index order

getCount() 공개 메소드

public getCount ( ) : integer
리턴 integer the number of items in the map

getDefaultPriority() 공개 메소드

public getDefaultPriority ( ) : numeric
리턴 numeric gets the default priority of inserted items without a specified priority

getIterator() 공개 메소드

This method is required by the interface \IteratorAggregate.
public getIterator ( ) : Iterator
리턴 Iterator an iterator for traversing the items in the map.

getKeys() 공개 메소드

Returns the keys within the map ordered through the priority of each key-value pair
public getKeys ( ) : array
리턴 array the key list

getPrecision() 공개 메소드

public getPrecision ( ) : integer
리턴 integer The precision of numeric priorities, defaults to 8

getPriorities() 공개 메소드

This returns a list of the priorities within this map, ordered lowest to highest.
public getPriorities ( ) : array
리턴 array the array of priority numerics in decreasing priority order

getPriorityCount() 공개 메소드

Gets the number of items at a priority within the map.
public getPriorityCount ( $priority = null ) : integer
리턴 integer the number of items in the map at the specified priority

getReadOnly() 공개 메소드

public getReadOnly ( ) : boolean
리턴 boolean whether this map is read-only or not. Defaults to false.

itemAt() 공개 메소드

Returns the item with the specified key. If a priority is specified, only items within that specific priority will be selected
public itemAt ( $key, $priority = false ) : mixed
리턴 mixed the element at the offset, null if no element is found at the offset

itemsAtPriority() 공개 메소드

Gets all the items at a specific priority.
public itemsAtPriority ( $priority = null ) : array
리턴 array all items at priority in index order, null if there are no items at that priority

mergeWith() 공개 메소드

Existing data in the map will be kept and overwritten if the keys are the same.
public mergeWith ( $data )

offsetExists() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetExists ( $offset ) : boolean
리턴 boolean

offsetGet() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetGet ( $offset ) : mixed
리턴 mixed the element at the offset, null if no element is found at the offset

offsetSet() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetSet ( $offset, $item )

offsetUnset() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetUnset ( $offset )

priorityAt() 공개 메소드

Retutrns the priority of an item at a particular flattened index.
public priorityAt ( $key ) : numeric
리턴 numeric priority of the item in the map

priorityOf() 공개 메소드

Returns the priority of a particular item within the map. This searches the map for the item.
public priorityOf ( $item ) : numeric
리턴 numeric priority of the item in the map

remove() 공개 메소드

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.
public remove ( $key, $priority = false ) : mixed
리턴 mixed the removed value, null if no such key exists.

setDefaultPriority() 보호된 메소드

This must be called internally or when instantiated.
protected setDefaultPriority ( $value )

setPrecision() 보호된 메소드

This must be called internally or when instantiated.
protected setPrecision ( $value )

setPriorityAt() 공개 메소드

This method is exactly the same as {@link offsetGet}.
public setPriorityAt ( $key, $priority = null ) : numeric
리턴 numeric old priority of the item

setReadOnly() 보호된 메소드

protected setReadOnly ( $value )

sortPriorities() 보호된 메소드

Orders the priority list internally.
protected sortPriorities ( )

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.
public toArray ( ) : array
리턴 array the list of items in array

toArrayAbovePriority() 공개 메소드

Combines the map elements which have a priority above the parameter value
public toArrayAbovePriority ( $priority, $inclusive = true ) : array
리턴 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.

toArrayBelowPriority() 공개 메소드

Combines the map elements which have a priority below the parameter value
public toArrayBelowPriority ( $priority, $inclusive = false ) : array
리턴 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.