Dec 202012
 

An interface for a List in PHP.

 

/**
 * An ordered collection (also known as a sequence). The user of this interface has
 * precise control over where in the list each element is inserted. The user can 
 * access elements by their index (position in the list), and search for elements in 
 * the list.
 * 
 * @author Steven Bolin - December 2012 - All rights reserved.
 */
interface RList {

  /**
   * Appends the specified element to the end of this list.
   * @param mixed $element - The element to add to the List
   */
  public function add($element);

  /**
   * Inserts the specified element at the specified position in this list
   * @param int $index - The index at which to enter the element
   * @param mixed $element - The element to add to the List
   */
  public function addAt($index, $element);

  /**
   * Removes all of the elements from this list.
   */
  public function clear();

  /**
   * Returns true if this list contains the specified element, false otherwise.
   * @require - $content != null
   * @param mixed $element - The element to search for.
   * @return boolean - Returns true if this list contains the specified element, false otherwise.
   */
  public function contains($element);

  /**
   * Returns the element at the specified position in this list.
   * @param int $index - The index of the element to return.
   * @return mixed - Returns the element at the specified position in this list.
   */
  public function get($index);

  /**
   * Returns the index of the first occurrence of the specified element in this 
   * list, or null if this list does not contain the element.
   * @param mixed $element - The element to get the index of.
   * @return int - Returns the index of the first occurrence of the specified 
   * element in this list, or null if this list does not contain the element.
   */
  public function indexOf($element);

  /**
   * Returns true if this list contains no elements, false otherwise.
   * @return boolean - Returns true if this list contains no elements, false otherwise.
   */
  public function isEmpty();

  /**
   * Returns an iterator over the elements in this list in proper sequence.
   * @return \ListIterator - Returns an iterator over the elements in this list 
   * in proper sequence.
   */
  public function iterator();

  /**
   * Removes the first occurrence of the specified element from this list, if 
   * it is present
   * @param mixed $element - The element to remove the first occurance of.
   */
  public function remove($element);

  /**
   * Removes the element at the specified position in this list.
   * @param int $index - the index of the element to remove.
   */
  public function removeIndex($index);

  /**
   * Replaces the element at the specified position in this list with the 
   * specified element
   * @param int $index - The index at which to place element
   * @param mixed $element - The element to place at index
   */
  public function set($index, $element);

  /**
   * Returns an array containing all of the elements in this list in proper 
   * sequence (from first to last element).
   * @return mixed array - Returns an array containing all of the elements in 
   * this list in proper sequence (from first to last element).
   */
  public function toArray();

  /**
   * Returns a string representation of the List.
   * @return string - Returns a string representation of the List.
   */
  public function toString();

  /**
   * Returns the number of elements in this list.
   * @return int - Returns the number of elements in this list.
   */
  public function size();
}
 Posted by at 8:59 am