Пример #1
0
 /**
  * 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));
 }
Пример #2
0
 /**
  * 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));
 }
Пример #3
0
 /**
  * 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());
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
0
 /**
  * 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())));
 }
Пример #6
0
 /**
  * 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);
 }
Пример #7
0
 /**
  * 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);
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 /**
  * 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());
 }
Пример #10
0
 /**
  * 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_();
 }
Пример #11
0
 /**
  * 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());
 }
Пример #12
0
 /**
  * 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();
 }
Пример #13
0
 /**
  * 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());
 }
Пример #14
0
 /**
  * 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
 }
Пример #15
0
 /**
  * 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());
 }
Пример #16
0
 /**
  * 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);
 }
Пример #17
0
 /**
  * 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_());
 }