2017 © Pedro Peláez
 

library collections

Package that provides basic PHP collections and utilities.

image

appserver-io/collections

Package that provides basic PHP collections and utilities.

  • Wednesday, June 7, 2017
  • by wagnert
  • Repository
  • 3 Watchers
  • 4 Stars
  • 8,962 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

PHP collection library

Latest Stable Version Total Downloads License Build Status Scrutinizer Code Quality Code Coverage, (*1)

Introduction

This package provides a generic collection library., (*2)

The library is based on the SPL extension of PHP5 and uses the introduced iterators. The library also provides, beside the most used collection types, interfaces and exceptions., (*3)

Issues

In order to bundle our efforts we would like to collect all issues regarding this package in the main project repository's issue tracker. Please reference the originating repository as the first element of the issue title e.g.: [appserver-io/<ORIGINATING_REPO>] A issue I am having, (*4)

Usage

The following examples will give you a short introduction how you can use the classes provided by this library., (*5)

ArrayList

An ArrayList will provide a container that can store items of different data types. With the provided methods, elements can be added, returned oder deleted. The ArrayList is unsorted and has an ongoing integer index that starts with 0., (*6)

// initialize a new ArrayList object $list = new ArrayList(); 
// add several values 
$list->add(new Integer(1)); 
$list->add(new Integer(2));
foreach($list as $key => $item) {
    echo "Found item with key " . $key . " value " . $item->__toString() . PHP_EOL; 
} 

// produces the following output 
Found item with key 0 and value 1 Found item with key 1 and value 2 

HashMap

A HashMap will provide a container that can store items of different data types. With the provided methods, elements can be added, returned oder deleted. The HashMap is unsorted like an ArrayList and all simple data types are supported as index., (*7)

// initialize a new HashMap object 
$map = new HashMap(); 

// add several values 
$map->add("number", new Integer(1)); 
$map->add("string", new String("foo")); 
foreach($list as $key => $item) { 
    echo "Found item with key " . $key . " and value " . $item->__toString() . PHP_EOL;
} 

// produces the following output 
Found item with key number and value 1 Found item with key string and value foo

Dictionary

A Dictionary, like an ArrayList or a HashMap, will provide a container that can store items of different data types. With the provided methods, elements can be added, returned oder deleted. The Dictionary is unsorted like an ArrayList. But in opposite to an ArrayList or a HashMap, between simple data types, also objects are allowed as index., (*8)

// initialize a new Dictionary object 
$dictionary = new Dictionary(); 

// add several values 
$dictionary->add(new Integer(1), new Integer(12)); 
$dictionary->add(new String("foo"), new String("foo")); 

foreach($dictionary as $key => $item) {
    echo "Found item with key " . $key->__toString() . " and value " . $item->__toString() . PHP_EOL;
}

// produces the following output
Found item with key 1 and value foo Found item with key foo and value 12

TreeMap

The usage of a TreeMap is very similar to a HashMap. The main difference is, that the items are either sorted ascending, or by the Predicate passed to the constructor., (*9)

// initialize a new TreeMap object 
$map = new TreeMap(); 

// add several values 
$map->add(2, new Integer(12)); 
$map->add(1, new String("foo")); 

foreach($map as $key => $item) {
    echo "Found item with key " . $key . " and value " . $item->__toString() . PHP_EOL;
}

// produces the following output
Found item with key 1 and value foo Found item with key 2 and value 12

The next example gives you an example implementation for using a TreeMap, sorted with a Comparator., (*10)

/** 
 * A class TestComparator to sort TreeMap by value.
 */
class TestComparator implements Comparator
{

    public function compare($object1, $object2)
    { 

        if ($object1->intValue() < $object2->intValue()) { 
            return -1;
        } 

        if ($object1->intValue() > $object2->intValue()) { 
            return 1;
        }

        if ($object1->intValue() == $object2->intValue()) {
            return 0;
        }
    } 
} 

// initialize a new TreeMap object and pass the TestComparator to the constructor 
$map = new TreeMap(new TestComparator()); 

// add several values
$map->add(1, new Integer(14)); 
$map->add(2, new Integer(13)); 
$map->add(3, new Integer(15)); 

foreach($map as $key => $item) { 
    echo "Found item with key " . $key . " and value " . $item->__toString() . PHP_EOL;
}

// produces the following output
Found item with key 2 and value 13 Found item with key 1 and value 14 Found item with key 3 and value 15

The Versions

07/06 2017

dev-master

9999999-dev https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

07/06 2017

2.0.0

2.0.0.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

07/06 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

07/06 2017

1.1.0

1.1.0.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

04/05 2016

1.0.2

1.0.2.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

02/07 2015

1.0.1

1.0.1.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

13/02 2015

1.0.0

1.0.0.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

28/01 2015

0.2.0

0.2.0.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate

21/11 2014

0.1.1

0.1.1.0 https://github.com/appserver-io/collections

Package that provides basic PHP collections and utilities.

  Sources   Download

OSL-3.0

The Requires

 

The Development Requires

collection arraylist map tree sorted set dictionary comparator predicate