Exemple #1
0
 /**
  * This method unsubscribes a listener.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param ITuple\Type $entry                                a tuple containing the key and listener
  * @return IHashMap\Type                                    the map
  */
 public static function unsubscribe(IHashMap\Type $xs, ITuple\Type $entry) : IHashMap\Type
 {
     $k = $entry->first();
     if ($xs->__hasKey($k)) {
         $ys = ILinkedList\Module::delete($xs->item($k), $entry->second());
         $zs = IHashMap\Module::putEntry($xs, ITuple\Type::box2($k, $ys));
         return $zs;
     }
     return $xs;
 }
Exemple #2
0
 /**
  * This method returns whether the iterator is still valid.
  *
  * @access public
  * @final
  * @return boolean                                          whether there are more objects
  */
 public final function valid() : bool
 {
     return $this->iterator->valid();
 }
Exemple #3
0
 /**
  * This method returns a value as a boxed object.  A value is typically a PHP typed
  * primitive or object.  It is considered type-safe.
  *
  * @access public
  * @static
  * @param mixed ...$xss                                     the value(s) to be boxed
  * @return IHashMap\Type                                    the boxed object
  */
 public static function make2(...$xss) : IHashMap\Type
 {
     // an array of tuples
     return IHashMap\Type::make($xss);
 }
Exemple #4
0
 /**
  * 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;
 }
Exemple #5
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param IHashMap\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(IHashMap\Type $xs, IHashMap\Type $ys) : ITrit\Type
 {
     $x_length = $xs->__size();
     $y_length = $ys->__size();
     if ($x_length == $y_length) {
         $xi = IHashMap\Module::iterator($xs);
         foreach ($xi as $k => $v) {
             if (!$ys->__hasKey($k) || !$ys->item($k)->__eq($v)) {
                 return ITrit\Type::make(strcmp((string) serialize($xs), (string) serialize($ys)));
                 // order is not "stable"
             }
         }
         return ITrit\Type::zero();
     } else {
         if ($x_length < $y_length) {
             return ITrit\Type::negative();
         } else {
             // ($x_length > $y_length)
             return ITrit\Type::positive();
         }
     }
 }
Exemple #6
0
 /**
  * This method tests that a value is of a particular size.
  *
  * @dataProvider dataSize
  */
 public function testSize(array $provided, array $expected)
 {
     //$this->markTestIncomplete();
     $p0 = IHashMap\Type::make($provided)->size();
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p0);
     $p1 = $p0->unbox();
     $e1 = $expected[0];
     $this->assertSame($e1, $p1);
 }
Exemple #7
0
 /**
  * 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;
 }