/** * This method returns an array of sub-strings that were split on the regular expression. * * @access public * @static * @param IRegex\Type $x the regular expression * @param Core\Type $ys the object to be split * @return IArrayList\Type an array of sub-strings */ public static function split(IRegex\Type $x, Core\Type $ys) : IArrayList\Type { $zs = $ys instanceof ITuple\Type ? preg_split($x->unbox(), $ys->first()->__toString(), (int) $ys->second()->unbox()) : preg_split($x->unbox(), $ys->__toString()); return IArrayList\Type::box(array_map(function ($z) { return IString\Type::box($z); }, $zs)); }
/** * This method returns an array list of substrings that were delimited by the specified * delimiter. * * @access public * @static * @param IString\Type $xs the delimiter * @param IString\Type $ys the string to be exploded * @return IArrayList\Type the array list of substrings */ public static function split(IString\Type $xs, IString\Type $ys) { $zs = explode($xs->unbox(), $ys->unbox()); return IArrayList\Type::box(array_map(function ($z) : IString\Type { return IString\Type::box($z); }, $zs)); }
/** * This method returns all of the keys in the collection. * * @access public * @final * @return IArrayList\Type all keys in the collection */ public final function keys() : IArrayList\Type { return IArrayList\Type::box($this->__keys()); }
/** * This method returns the collection as an array. * * @access public * @static * @param IString\Type $xs the operand * @return IArrayList\Type the collection as an array list */ public static function toArrayList(IString\Type $xs) : IArrayList\Type { $buffer = array(); IString\Module::each($xs, function (IChar\Type $x, IInt32\Type $i) use($buffer) { $buffer[] = $x; }); return IArrayList\Type::box($buffer); }
/** * This method returns a list of all numbers for the specified sequence. * * @access public * @static * @param IInt32\Type $x where to start * @param Core\Boxable\Type $y either an integer representing * the end of the sequence or a * tuple describing the sequence * @return IArrayList\Type an empty array list */ public static function sequence(IInt32\Type $x, Core\Boxable\Type $y) : IArrayList\Type { if ($y instanceof ITuple\Type) { $s = $y->first(); $n = $y->second(); } else { $s = IInt32\Type::one(); $n = $y; } return IArrayList\Type::box(array_map(function (int $value) : IInt32\Type { return IInt32\Type::box($value); }, range($x->unbox(), $n->unbox(), $s->unbox()))); }
/** * This method returns the hash map as an array. * * @access public * @static * @param IHashMap\Type $xs the hash map * @return IHashMap\Type the hash map as an array list */ public static function toArrayList(IHashMap\Type $xs) : IHashMap\Type { $buffer = array(); $xi = IHashMap\Module::iterator($xs); foreach ($xi as $x) { $buffer[] = $x; } return IArrayList\Type::box($buffer); }
/** * This method returns a list of all numbers for the specified sequence. * * @access public * @static * @param IInteger\Type $x where to start * @param Core\Type $y either an integer representing * the end of the sequence or a * tuple describing the sequence * @return IArrayList\Type an empty array list */ public static function sequence(IInteger\Type $x, Core\Type $y) : IArrayList\Type { $buffer = array(); if ($y instanceof ITuple\Type) { $s = IInteger\Module::subtract($y->first(), $x); $n = $y->second(); } else { // ($y instanceof IInteger\Type) $s = IInteger\Type::one(); $n = $y; } if (IInteger\Module::isNegative($s)->unbox()) { for ($i = $x; IInteger\Module::ge($i, $n)->unbox(); $i = IInteger\Module::add($i, $s)) { $buffer[] = $i; } } else { for ($i = $x; IInteger\Module::le($i, $n)->unbox(); $i = IInteger\Module::add($i, $s)) { $buffer[] = $i; } } return IArrayList\Type::box($buffer); }
/** * This method creates a list of "n" length with every item set to the given object. * * @access public * @param Core\Type $x the object to be replicated * @param IInt32\Type $n the number of times to replicate * @return IArrayList\Type the collection */ public static function replicate(Core\Type $x, IInt32\Type $n) : IArrayList\Type { $buffer = array(); for ($i = $n->unbox() - 1; $i >= 0; $i--) { $buffer[] = $x; } return IArrayList\Type::box($buffer); }
/** * This method returns the tuple as an array. * * @access public * @static * @param ITuple\Type $xs the operand * @return IArrayList\Type the tuple as an array list */ public static function toArrayList(ITuple\Type $xs) : IArrayList\Type { return IArrayList\Type::box($xs->unbox()); }
/** * This method returns the either as an array. * * @access public * @final * @return IArrayList\Type the either as an array list */ public final function toArrayList() : IArrayList\Type { return $this->either->__isLeft() ? IArrayList\Type::box(array($this->either->item())) : IArrayList\Type::empty_(); }
/** * This method tests the "toString" method. * * @dataProvider data_toString */ public function test_toString(array $provided, array $expected) { $this->markTestIncomplete(); $p0 = IArrayList\Type::make($provided[0])->toString(); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0); $this->assertSame($e0, $p0->unbox()); }
/** * This method returns whether the iterator is still valid. * * @access public * @final * @return bool whether there are more objects */ public final function valid() : bool { return $this->i->unbox() < $this->xs->__length(); }
/** * This method compares the specified object with the current object for order. * * @access public * @static * @param IArrayList\Type $xs the left operand * @param IArrayList\Type $ys the object to be compared * @return ITrit\Type whether the current object is less than, * equal to, or greater than the specified * object */ public static function compare(IArrayList\Type $xs, IArrayList\Type $ys) : ITrit\Type { $xsl = $xs->length(); $ysl = $ys->length(); $length = IInt32\Module::min($xsl, $ysl); for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $r = $xs->item($i)->compare($ys->item($i)); if ($r->unbox() != 0) { return $r; } } return ITrit\Type::box($xsl->unbox() <=> $ysl->unbox()); }
/** * This method returns any backtrace information. * * @access public * @static * @param Throwable\Runtime\Exception $x the exception to be processed * @return array any backtrace information */ public static function getTrace(Throwable\Runtime\Exception $x) { return IArrayList\Type::box($x->__getTrace()); // TODO re-implement to use recursive make }
/** * This method tests the "or" method. * * @dataProvider data_or */ public function test_or(array $provided, array $expected) { $p0 = IArrayList\Type::make($provided[0], '\\Saber\\Data\\IBool\\Type'); $r0 = IArrayList\Module::or_($p0); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $r0); $this->assertSame($e0, $r0->unbox()); }
/** * This method returns the option as an array. * * @access public * @static * @param IOption\Type $xs the operand * @return IArrayList\Type the option as an array list */ public static function toArrayList(IOption\Type $xs) : IArrayList\Type { $buffer = array(); if ($xs->__isDefined()) { $buffer[] = $xs->item(); } return IArrayList\Type::box($buffer); }
/** * This method returns the list as an array. * * @access public * @static * @param ILinkedList\Type $xs the operand * @return IArrayList\Type the list as an array list */ public static function toArrayList(ILinkedList\Type $xs) : IArrayList\Type { return ILinkedList\Module::foldLeft($xs, function (IArrayList\Type $c, Core\Type $x) { return IArrayList\Module::append($c, $x); }, IArrayList\Type::empty_()); }