示例#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;
 }
示例#2
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();
         }
     }
 }