示例#1
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IOption\Type $xs                                  the left operand
  * @param IOption\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(IOption\Type $xs, IOption\Type $ys) : ITrit\Type
 {
     $x = $xs->__isDefined();
     $y = $ys->__isDefined();
     if (!$x && $y) {
         return ITrit\Type::negative();
     }
     if (!$x && !$y) {
         return ITrit\Type::zero();
     }
     if ($x && !$y) {
         return ITrit\Type::positive();
     }
     $x = $xs->item();
     $y = $ys->item();
     if ($x === null && $y !== null) {
         return ITrit\Type::negative();
     }
     if ($x === null && $y === null) {
         return ITrit\Type::zero();
     }
     if ($x !== null && $y === null) {
         return ITrit\Type::positive();
     }
     if ($x instanceof Core\Comparable\Type) {
         return call_user_func_array(array($x, 'compare'), array($y));
     }
     return IString\Module::compare(Core\Module::hashCode($x), Core\Module::hashCode($y));
 }
示例#2
0
 /**
  * This method returns the numerically lowest value.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the left operand
  * @param IString\Type $ys                                  the right operand
  * @return IString\Type                                     the minimum value
  */
 public static function min(IString\Type $xs, IString\Type $ys) : IString\Type
 {
     return IString\Module::compare($xs, $ys)->unbox() <= 0 ? $xs : $ys;
 }