/** * This method returns a hash map of lists of characters that are considered in the same group. * * @access public * @static * @param IArrayList\Type $xs the array list to be processed * @param callable $subroutine the subroutine to be used * @return IHashMap\Type a hash map of lists of characters that * are considered in the same group */ public static function group(IArrayList\Type $xs, callable $subroutine) : IHashMap\Type { $groups = IHashMap\Type::empty_(); IString\Module::each($xs, function (IChar\Type $x, IInt32\Type $i) use($groups, $subroutine) { $key = $subroutine($x, $i); $item = $groups->__hasKey($key) ? $groups->item($key)->unbox() : ''; $item .= $x->unbox(); $groups->putEntry($key, IString\Type::box($item)); }); return $groups; }
/** * This method tests the creation of an empty list. */ public function testEmpty() { //$this->markTestIncomplete(); $p0 = IHashMap\Type::empty_(); $this->assertInstanceOf('\\Saber\\Data\\IHashMap\\Type', $p0); $p1 = $p0->unbox(); $e1 = 0; $this->assertInternalType('array', $p1); $this->assertCount($e1, $p1); }
/** * This method returns the latter value should the former value evaluates * to null. * * @access public * @static * @param IHashMap\Type $xs the value to be evaluated * @param IHashMap\Type $ys the default value * @return IHashMap\Type the result */ public static function nvl(IHashMap\Type $xs = null, IHashMap\Type $ys = null) : IHashMap\Type { return $xs ?? $ys ?? IHashMap\Type::empty_(); }
/** * This method returns a hash map of lists of items that are considered in the same group. * * @access public * @static * @param IArrayList\Type $xs the array list to be processed * @param callable $subroutine the subroutine to be used * @return IHashMap\Type a hash map of lists of items that * are considered in the same group */ public static function group(IArrayList\Type $xs, callable $subroutine) : IHashMap\Type { $groups = IHashMap\Type::empty_(); $xi = IArrayList\Module::iterator($xs); foreach ($xi as $i => $x) { $key = $subroutine($x, $i); $item = $groups->__hasKey($key) ? $groups->item($key)->unbox() : array(); $item[] = $x; $groups->putEntry($key, IArrayList\Type::box($item)); } return $groups; }