PHP Classes
elePHPant
Icontem

File: demo/arraylistdemo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ordland Euroboros  >  PHP Collections Framework  >  demo/arraylistdemo.php  >  Download  
File: demo/arraylistdemo.php
Role: Example script
Content type: text/plain
Description: A demo using arraylist
Class: PHP Collections Framework
Manipulate collections of objects like Java and C#
Author: By
Last change:
Date: 2 years ago
Size: 2,537 bytes
 

Contents

Class file image Download
<?php

require "autoloader.php";
use
Resource\Native\String as String;
use
Resource\Collection\ArrayList as ArrayList;

$seraphim = new ArrayList(4);
$mithos = new String("Mithos Yggdrasill");
$martel = new String("Martel Yggdraill");
$yuan = new String("Yuan Kafei");
$kratos = new String("Kratos Aurion");

$seraphim->add($martel);
$seraphim->add($yuan);
$seraphim->add($kratos);
$seraphim->insert(0, $mithos);
$seraphIterator = $seraphim->iterator();

echo
"Cruxis has the following Four Seraphim:<br>";
while(
$seraphIterator->hasNext()){
    echo
$seraphIterator->next();
    echo
"<br>";
}

$desians = new ArrayList(5);
$pronyma = new String("Pronyma");
$forcystus = new String("Forcystus");
$rodyle = new String("Rodyle");
$kvar = new String("Kvar");
$magnius = new String("Magnius");

$desians->add($pronyma);
$desians->add($forcystus);
$desians->add($rodyle);
$desians->add($kvar);
$desians->add($magnius);
$desianIterator = $desians->iterator();

echo
"<br>Cruxis has the following Five Grand Cardinals:<br>";
while(
$desianIterator->hasNext()){
    echo
$desianIterator->next();
    echo
"<br>";
}

$desianIterator->rewind();
echo
"The leader of the desian grand cardinals is: ";
echo
$desianIterator->next();
echo
"<br>";

$cruxis = new ArrayList($desians);
$cruxis->insertAll(0, $seraphim);
$remiel = new String("Remiel");
$cruxis->add($remiel);
$cruxisIterator = $cruxis->iterator();
echo
"<br>The following members all belong to cruxis: <br>";
while(
$cruxisIterator->hasNext()){
    echo
$cruxisIterator->next();
    echo
"<br>";
}

$deceaced = new ArrayList;
$deceaced->add($magnius);
$deceaced->add($kvar);
$deceaced->add($remiel);
$deceaced->add($martel);
$deceacedIterator = $deceaced->iterator();
echo
"<br>The following {$deceaced->size()} members are already dead before we visit Tethe'alla: <br>";
while(
$deceacedIterator->hasNext()){
    echo
$deceacedIterator->next();
    echo
"<br>";
}

$cruxis->removeAll($deceaced);
$aliveIterator = $cruxis->iterator();
echo
"<br>As a result, only the following Cruxis Members are still alive: <br>";
while(
$aliveIterator->hasNext()){
    echo
$aliveIterator->next();
    echo
"<br>";
}

$cruxis->retainAll($desians);
$aliveIterator = $cruxis->iterator();
echo
"<br>The Desian Grand Cardinals still alive are: <br>";
while(
$aliveIterator->hasNext()){
    echo
$aliveIterator->next();
    echo
"<br>";
}

//$cruxis->trimSize();
//var_dump($cruxis);
//var_dump($cruxis->get(1));

?>