Beispiel #1
0
 /**
  * constructor
  * 
  * @param string $value
  * @return Midori\String the class
  */
 public function __construct($value = "")
 {
     $value = unbox($value);
     if ($value != null) {
         $this->value = $value;
     }
 }
Beispiel #2
0
 /**
  * Type getter.
  *
  * @return integer The type of this event.
  */
 public function getType()
 {
     return unbox($this->getValue());
 }
Beispiel #3
0
 /**
  * Returns the given object if is contained in this set; otherwise NULL.
  *
  * @return mixed The given object or NULL.
  */
 public function find(IComparable $obj)
 {
     if ($this->containsItem(unbox($obj))) {
         return $obj;
     } else {
         return NULL;
     }
 }
 /**
  * Tests if the specified item is a member of this multiset.
  *
  * @param integer $item The item for which to look.
  * @return boolean True if the item is a member of this multiset;
  * false otherwise.
  */
 public function containsItem($item)
 {
     for ($ptr = $this->list->getHead(); $ptr !== NULL; $ptr = $ptr->getNext()) {
         $datum = $ptr->getDatum();
         if (unbox($datum) == $item) {
             return true;
         }
     }
     return false;
 }
Beispiel #5
0
 public function expectsThat($data, $message = null)
 {
     $this->data = unbox($data);
     return $this;
 }
Beispiel #6
0
 /**
  * Counts the number of distinct words in the input stream and then
  * prints a table of the words and the number of occurrences
  * on the output stream.
  * Uses a hash table.
  *
  * @param resource $in The input stream.
  * @param resource $out The output stream.
  */
 public static function wordCounter($in, $out)
 {
     $table = new ChainedHashTable(1031);
     while (($line = fgets($in)) != false) {
         $words = preg_split('/[ \\t\\n]+/', $line, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($words as $word) {
             $assoc = $table->find(new Association(box($word)));
             if ($assoc === NULL) {
                 $table->insert(new Association(box($word), box(1)));
             } else {
                 $count = unbox($assoc->getValue());
                 $assoc->setValue(box($count + 1));
             }
         }
     }
     fprintf($out, "%s\n", str($table));
 }