Beispiel #1
0
try {
    $setObject->addAll(array(17, 11, 12, 18));
    // 11 and 12 are duplicate elements
} catch (HashSetException $exception) {
    echo ' > Exception!<br/>';
}
echo 'Count: ';
echo count($setObject);
echo '<br/>';
echo '<br/>';
echo '<br/>';
echo 'remove value: ';
echo '<br/>';
$setObject = new HashSet();
$setObject->addAll(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
$setObject->remove(4);
$setObject->remove(10);
echo 'Count: ';
echo count($setObject);
echo '<br/>';
echo 'is empty (has any entries): ';
if ($setObject->isEmpty()) {
    echo 'FALSE';
} else {
    echo 'TRUE';
}
echo '<br/>';
echo 'clear set';
$setObject->clear();
echo '<br/>';
echo 'is empty (has any entries): ';
Beispiel #2
0
 /**
  * @return    void
  */
 public function testRemove()
 {
     $setObject = new HashSet();
     $setObject->addAll(self::$setValues);
     $setObject->remove(self::$setValues[4]);
     $setObject->remove(self::$setValues[10]);
     $array = array();
     foreach ($setObject as $key => $value) {
         $array[] = $value;
     }
     $this->assertEquals(8, count($array));
     $this->assertEquals(self::$setValues[1], $array[0]);
     $this->assertEquals(self::$setValues[2], $array[1]);
     $this->assertEquals(self::$setValues[3], $array[2]);
     $this->assertEquals(self::$setValues[5], $array[3]);
     $this->assertEquals(self::$setValues[6], $array[4]);
     $this->assertEquals(self::$setValues[7], $array[5]);
     $this->assertEquals(self::$setValues[8], $array[6]);
     $this->assertEquals(self::$setValues[9], $array[7]);
 }