Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
Fixing collections with abstract methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ítalo Lelis de Vietro committed Jul 28, 2014
1 parent bf167da commit ed839e9
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 130 deletions.
87 changes: 40 additions & 47 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/Easy/Collections/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,22 @@ public function toKeysArrays()
{
return array_keys($this->array);
}

/**
* {@inheritdoc}
*/
public function concat(ICollectionConvertable $collection)
{
$this->array = array_merge_recursive($this->array,
$collection->toArray());
return $this;
}

/**
* {@inheritdoc}
*/
public static function fromItems(Traversable $items)
{
return new static($items);
}
}
18 changes: 0 additions & 18 deletions src/Easy/Collections/CollectionArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,6 @@ public function map($p)
return static::fromArray(array_map($p, $this->array));
}

/**
* {@inheritdoc}
*/
public function concat(ICollectionConvertable $collection)
{
$this->array = array_merge_recursive($this->array,
$collection->toArray());
return $this;
}

/**
* {@inheritdoc}
*/
public static function fromItems(Traversable $items)
{
return new static($items);
}

/**
* {@inheritdoc}
*/
Expand Down
53 changes: 1 addition & 52 deletions src/Easy/Collections/ImmutableVector.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<?php

// Copyright (c) Lellys Informática. All rights reserved. See License.txt in the project root for license information.

namespace Easy\Collections;

use Closure;
use Easy\Collections\AbstractCollection;
use Easy\Collections\IConstIndexAccess;
use Easy\Collections\ImmutableVector;
use Easy\Collections\Linq\Criteria;
use Easy\Collections\Linq\Expr\ClosureExpressionVisitor;
use Easy\Generics\IEquatable;
use InvalidArgumentException;
use OutOfBoundsException;
use Traversable;
Expand Down Expand Up @@ -93,50 +88,4 @@ protected static function convertFromArray($arr)
}
return $vector;
}

/**
* {@inheritdoc}
*/
public function filter(Closure $p)
{
return ImmutableVector::fromArray(array_filter($this->array, $p));
}

/**
* {@inheritdoc}
*/
public function matching(Criteria $criteria)
{
$expr = $criteria->getWhereExpression();
$filtered = $this->array;

if ($expr) {
$visitor = new ClosureExpressionVisitor();
$filter = $visitor->dispatch($expr);
$filtered = array_filter($filtered, $filter);
}

if ($orderings = $criteria->getOrderings()) {
$next = null;
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == 'DESC' ? -1 : 1, $next);
}

if ($next === null) {
throw new InvalidArgumentException("The next value needs to be a callable function");
}

usort($filtered, $next);
}

$offset = $criteria->getFirstResult();
$length = $criteria->getMaxResults();

if ($offset || $length) {
$filtered = array_slice($filtered, (int) $offset, $length);
}

return ImmutableVector::fromArray($filtered);
}

}
}
20 changes: 9 additions & 11 deletions src/Easy/Collections/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ public function peek()
return $this->array[0];
}

public function concat(ICollectionConvertable $collection)
{

}

public static function fromArray(array $arr)
{

}

public static function fromItems(\Traversable $items)
{

$collection = new Queue();
foreach ($arr as $v) {
if (is_array($v)) {
$collection->enqueue(static::fromArray($v));
} else {
$collection->enqueue($v);
}
}
return $collection;
}
}
Loading

0 comments on commit ed839e9

Please sign in to comment.