Sgss_Collection_Array_List
Represents an indexed collection using array

Description

Class diagram:
Sgss_Collection_List_Abstract
 + Sgss_Collection_Array_List
Author:
Matsuda Shota
Copyright:
(c) 2007-2008 Matsuda Shota
License:
http://creativecommons.org/licenses/GPL/2.0/
Located in:
/Collection/Array/List.php (line 51)

Class overview

Variables

protected array $_elements

Indices and elements in this list

protected int $_size

The number of elements in this list

Methods

__construct ([array|object|null $elements = null])

The constructor

boolean add (mixed $element)

Appends the specified element at the end of this list

boolean clear ()

Removes all the indices and elements in this list

mixed drop (int $index)

Removes the specified index and the corresponding element from this list

mixed get (int $index)

Returns the element at the specified index of this list

boolean has (mixed $element)

Determines whether this list contains the specified element

int index (mixed $element)

Returns the index at which the specified element first appears in this list

boolean insert (int $index, mixed $element)

Inserts or appends the specified element at the specified index of this list

boolean remove (mixed $element)

Removes the specified element from this list

mixed set (int $index, mixed $element)

Replaces the element at the specified index of this list to the specified element

int size ()

Returns the number of elements in this list

array toArray ()

Converts this list to an associated array

Inherited from Sgss_Collection_List_Abstract:
addAll(), count(), current(), hasAll(), insertAll(), isEmpty(), key(), next(), offsetExists(), offsetGet(), offsetSet(), offsetUnset(), removeAll(), rewind(), valid()

Variable detail

$_elements 

Indices and elements in this list

Signature:
protected array $_elements


$_size 

The number of elements in this list

Signature:
protected int $_size = 0


Method detail

__construct

The constructor

Parameters:
  • array|object|null $elements

    Value containing elements to be stored

Uses:
Sgss_Collection_List_Abstract::addAll()
Signature:
public __construct ([array|object|null $elements = null])


add

Appends the specified element at the end of this list

Parameters:
  • mixed $element

    Element to be appended

Returns:
boolean -- True when the operation changed this list
Related subject:
Sgss_Collection_List_Interface::add()
Signature:
public boolean add (mixed $element)


clear

Removes all the indices and elements in this list

Returns:
boolean -- True when the operation changed this list
Related subject:
Sgss_Collection_List_Interface::size()
Signature:
public boolean clear ()


drop

Removes the specified index and the corresponding element from this list

Parameters:
  • int $index

    Index to be removed

Returns:
mixed -- The element previously stored at the specified index
Throws:
  • Sgss_Collection_List_Exception

    When the specified index is below 0 or beyond the last index of this list

Uses:
array_splice()
Related subject:
Sgss_Collection_List_Interface::drop()
Signature:
public mixed drop (int $index)


get

Returns the element at the specified index of this list

Parameters:
  • int $index

    Index of element to be retrieved

Returns:
mixed -- The element stored at the specified index
Throws:
  • Sgss_Collection_List_Exception

    When the specified index is below 0 or beyond the last index of this list

Related subject:
Sgss_Collection_List_Interface::get()
Signature:
public mixed get (int $index)


has

Determines whether this list contains the specified element

Parameters:
  • mixed $element

    Element to determine

Returns:
boolean -- True when this list contains the specified element
Uses:
array_search()
Related subject:
Sgss_Collection_List_Interface::has()
Signature:
public boolean has (mixed $element)


index

Returns the index at which the specified element first appears in this list

Parameters:
  • mixed $element

    Element to search

Returns:
int -- The index at which the specified element first appears, or -1 if this list does not contains it
Uses:
array_search()
Related subject:
Sgss_Collection_List_Interface::index()
Signature:
public int index (mixed $element)


insert

Inserts or appends the specified element at the specified index of this list

Parameters:
  • int $index

    Index to insert at

  • mixed $element

    Element to be inserted or appended

Returns:
boolean -- True when the operation changed this list
Throws:
  • Sgss_Collection_List_Exception

    When the specified index is below 0 or beyond the size of this list

Uses:
array_splice()
Related subject:
Sgss_Collection_List_Interface::insert()
Signature:
public boolean insert (int $index, mixed $element)


remove

Removes the specified element from this list

Parameters:
  • mixed $element

    Element to be removed

Returns:
boolean -- True when the operation changed this list
Uses:
array_splice()
Related subject:
Sgss_Collection_List_Interface::remove()
Signature:
public boolean remove (mixed $element)


set

Replaces the element at the specified index of this list to the specified element

Parameters:
  • int $index

    Index of element to be replaced

  • mixed $element

    Element to store

Returns:
mixed -- The element previously stored at the specified index
Throws:
  • Sgss_Collection_List_Exception

    When the specified index is below 0 or beyond the last index of this list

Related subject:
Sgss_Collection_List_Interface::set()
Signature:
public mixed set (int $index, mixed $element)


size

Returns the number of elements in this list

Returns:
int -- The number of elements in this list
Related subject:
Sgss_Collection_List_Interface::size()
Signature:
public int size ()


toArray

Converts this list to an associated array

Returns:
array -- An associated array which represents this list
Related subject:
Sgss_Collection_List_Interface::toArray()
Signature:
public array toArray ()