xp-framework / collections
Generic collections for the XP Framework
Installs: 83 102
Dependents: 6
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.0.0
- xp-framework/core: ^12.0 | 11.0 | ^10.2
Requires (Dev)
- xp-framework/test: ^2.0 | ^1.0
README
Generic collections for the XP Framework
API
package util.collections { public interface util.collections.IList<T> public interface util.collections.Map<K, V> public interface util.collections.Set<T> public class util.collections.HashSet<T> public class util.collections.HashTable<K, V> public class util.collections.LRUBuffer<T> public class util.collections.Pair<K, V> public class util.collections.Queue<T> public class util.collections.Stack<T> public class util.collections.Vector<T> }
Example: HashTable
$map= create('new util.collections.HashTable<string, com.example.Customer>'); $empty= $map->isEmpty(); $size= $map->size(); // Write values $map['@example']= new Customer(0, 'Example customer'); $map->put('@friebe', new Customer(1, 'Timm Friebe')); // Raises an exception $map['@invalid']= new Date(); // Access $customer= $map['@example']; $customer= $map->get('@example'); // Test if (isset($map['@example'])) { // ... } // Will return NULL $customer= $map['@nonexistant']; // Remove unset($map['@example']); $map->remove('@example'); // Iteration foreach ($map as $pair) { echo $pair->key, ': ', $pair->value->toString(), "\n"; }
Example: Vector
$list= create('new util.collections.Vector<com.example.Customer>'); $empty= $list->isEmpty(); $size= $list->size(); // Write values $list[]= new Customer(0, 'Example customer'); $list->add(new Customer(1, 'Timm Friebe')); $list[0]= new Customer(0, 'Example customer'); $list->set(1, new Customer(1, 'Timm Friebe')); // Raises an exception $list[0]= new Date(); // Access $customer= $list[0]; $customer= $list->get(0); // Test if (isset($list[1])) { // ... } // Will return NULL $customer= $list[1]; // Remove unset($list[1]); $list->remove(1); // Iteration foreach ($list as $customer) { echo $customer->toString(), "\n"; }