MatchName Class Reference

Inheritance diagram for MatchName:

MatchListInterface MatchInterface

List of all members.

Public Member Functions

 setNotFoundValue ($objNotFoundValue)
 getNotFoundValue ()
 setDefaultItemValue ($objDefaultItemValue)
 getDefaultItemValue ()
 setItemList (array $arrItemList, $arrValues=null)
 getItemList ()
 addItem ($objItem, $objValue=null)
 isEmpty ()
 found ($objName)
 match ($objName)

Protected Attributes

 $objNotFoundValue = false
 $objDefaultItemValue = true
 $arrItemList = array()
 $arrValues = array()


Detailed Description

Author:
Thiago Henrique Ramos da Mata <thiago.henrique.mata@gmail.com>
Since:
2009-06-16
Math the string name with a string list

The string itens are strings elements and the string name is a string. The compare item and name returns true when the string it is equal the name.

The values <value> start will boolean values, but is not restrict to it. The not found value <value> by default is false. The default found value <value> it is by default true.

Example:
      $objMatchName = new MatchName();
      $objMatchName->addItem( "Molly" );
      $objMatchName->addItem( "Armitage" );
      $objMatchName->addItem( "Wintermute" , "machine" );
      $objMatchName->addItem( "Case" , "hacker" );
      if ( $objMatchName->found( "Molly" ) !== true ) return false;
      if ( $objMatchName->match( "Molly" ) !== true ) return false;
      if( $objMatchName->match( "Wintermute" ) !== "machine" ) return false;
      if( $objMatchName->match( "Jackson" ) !== false ) return false;
      return true;
returns
 true 

Definition at line 35 of file MatchName.class.php.


Member Function Documentation

addItem ( objItem,
objValue = null 
)

Add a item into the item list

Implements:
MatchListInterface::addItem( <item> object [, <value> object ])
See also:
MatchListInterface::setItemList( string[] )

MatchName::setItemList( string[] )

MatchListInterface::getItemList()

MatchName::getItemList()

Parameters:
string $objItem
<value> $objValue
Returns:
MatchListInterface me

Implements MatchListInterface.

Definition at line 189 of file MatchName.class.php.

References getDefaultItemValue().

Referenced by setItemList().

00190     {
00191         if( $objValue == null )
00192         {
00193             $objValue = $this->getDefaultItemValue();
00194         }
00195         $intItemKey = sizeof( $this->arrItemList );
00196         $this->arrItemList[ $intItemKey ] = (string) $objItem;
00197         $this->arrValues[ $intItemKey ] = $objValue;
00198     }

found ( objName  ) 

Match the name into the item list and returns true if some item successfully match or false if not

Execution Plan:
  • get the item list
  • for each item into the list
  • try match the item with the name
    • if match returns true
    • if no item match, returns false
Implements:
MatchListInterface::found( <name> object )
Parameters:
string $objName
Returns:
boolean

Implements MatchInterface.

Definition at line 251 of file MatchName.class.php.

References getItemList().

00252     {
00253         $strName = (string) $objName;
00254         return in_array( $strName , $this->getItemList() );
00255     }

getDefaultItemValue (  ) 

Get the default item value.

This value <value> what will be saved on some string item when this setter dont inform its value

Implements:
MatchListInterface::getDefaultItemValue()
Returns:
object <value>

Implements MatchListInterface.

Definition at line 124 of file MatchName.class.php.

Referenced by addItem().

00125     {
00126         return $this->objDefaultItemValue;
00127     }

getItemList (  ) 

Get the array with the item list into the match

Implements:
MatchListInterface::getItemList()
Returns:
string[] $arrItemList

Implements MatchListInterface.

Definition at line 172 of file MatchName.class.php.

Referenced by found(), and isEmpty().

00173     {
00174         return $this->arrItemList;
00175     }

getNotFoundValue (  ) 

Get the not found value.

This value will be returned when the name received don't match with any element into the item list in the match() method

Implements:
MatchListInterface::getNotFoundValue()
See also:
MatchListInterface::match( <name> object )

MatchName::match( string )

Returns:
object <value>

Implements MatchInterface.

Definition at line 92 of file MatchName.class.php.

Referenced by match().

00093     {
00094         return $this->objNotFoundValue;
00095     }

isEmpty (  ) 

Returns true if the item list is empty returns false if not.

If is empty the match allways will return the not found value

Execution Plan:
  • read the list itens.
  • check if the list is empty
    • returns true if the list is empty
    • returns false if the list is not empty
Implements:
MatchListInterface::isEmpty()
Returns:
boolean

Implements MatchListInterface.

Definition at line 222 of file MatchName.class.php.

References getItemList().

00223     {
00224         return ( sizeof( $this->getItemList() ) == 0 );
00225     }

match ( objName  ) 

Match the string name with the list string item return the value <value> of the first item what match or the not found value when no item match.

Execution Plan:
  • get the item list
  • for each item into the list
  • try match the item with the name
    • if match returns the value of the item
    • if no item match, returns the not found value
Implements:
MatchListInterface::match( <name> object )
See also:
MatchListInterface::getNotFoundValue()

MatchName::getNotFoundValue()

MatchListInterface::getItemList()

MatchName::getItemList()

Parameters:
string $objName
Returns:
object <value>

Implements MatchInterface.

Definition at line 285 of file MatchName.class.php.

References getNotFoundValue().

00286     {
00287         $strName = (string) $objName;
00288 
00289         // for each item into the list //
00290         // try match the item with the name //
00291         $intKey = array_search( $strName , $this->arrItemList );
00292         
00293         if( $intKey === false )
00294         {
00295             // if no item match, returns the not found value //
00296             return $this->getNotFoundValue();
00297         }
00298         else
00299         {
00300             // if match returns the value of the item //
00301             return $this->arrValues[ $intKey ];
00302         }
00303     }

setDefaultItemValue ( objDefaultItemValue  ) 

Set the default item value.

Changing this element will change how the value of the itens string[] what not informed they values into the setItemList() and addItem()

Implements:
MatchListInterface::setDefaultItemValue( <value> object )
See also:
MatchListInterface::setItemList( <item>[] [, <value>[] ] )

MatchName::setItemList( string[] [, <value>[] ] )

Parameters:
object $objNotFoundValue
Returns:
MatchName me

Implements MatchListInterface.

Definition at line 109 of file MatchName.class.php.

References $objDefaultItemValue.

00110     {
00111         $this->objDefaultItemValue = $objDefaultItemValue;
00112         return $this;
00113     }

setItemList ( array $  arrItemList,
arrValues = null 
)

Set the array with the item list into the match. Can receive the array with the values of each item. If the array with values not received, the default value to the itens will be true

Implements:
MatchListInterface::setItemList( <item>[] [ , <value>[] ])
See also:
MatchListInterface::getItemList()

MatchName::getItemList()

Parameters:
string[] $arrItemList
<value>[] $arrValues
Returns:
MatchListInterface me
Exceptions:
MatchException 

Implements MatchListInterface.

Definition at line 143 of file MatchName.class.php.

References $arrValues, and addItem().

00144     {
00145         if( $arrValues !== null )
00146         {
00147             if( sizeof( $arrValues ) !== sizeof( $arrItemList ) )
00148             {
00149                 throw new MatchException( "Invalid value list to the respective item list" );
00150             }
00151         }
00152         else
00153         {
00154             $arrValues = array_pad( array() , null , sizeof( $arrItemList ) );
00155         }
00156         
00157         foreach( $arrItemList as $intKey => $objItem )
00158         {
00159             $objValue = $arrValues[ $intKey ];
00160             $this->addItem( $objItem , $objValue );
00161         }
00162         
00163         return $this;
00164     }

setNotFoundValue ( objNotFoundValue  ) 

Set the not found value.

Changing this value will change how the result of the match() method when not item match with the received name

Implements:
MatchListInterface::match( <name> object )
See also:
MatchListInterface::setNotFoundValue( <value> object )

MatchName::setNotFoundValue( <value> object )

Parameters:
object $objNotFoundValue
Returns:
MatchName me

Implements MatchInterface.

Definition at line 75 of file MatchName.class.php.

References $objNotFoundValue.

00076     {
00077         $this->objNotFoundValue = $objNotFoundValue;
00078     }


Member Data Documentation

$arrItemList = array() [protected]

string[]

Definition at line 54 of file MatchName.class.php.

$arrValues = array() [protected]

<value>[]

Definition at line 60 of file MatchName.class.php.

Referenced by setItemList().

$objDefaultItemValue = true [protected]

Default: true
<value> object

Definition at line 47 of file MatchName.class.php.

Referenced by setDefaultItemValue().

$objNotFoundValue = false [protected]

Default: false
<value> object

Definition at line 41 of file MatchName.class.php.

Referenced by setNotFoundValue().


The documentation for this class was generated from the following file:

Generated on Thu Feb 3 03:55:03 2011 for CodeToDiagram by  doxygen 1.5.9