Пример #1
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param ITrit\Type $x                                     the left operand
  * @param ITrit\Type $y                                     the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(ITrit\Type $x, ITrit\Type $y) : ITrit\Type
 {
     $__x = $x->unbox();
     $__y = $y->unbox();
     if ($__x < $__y) {
         return ITrit\Type::negative();
     } else {
         if ($__x == $__y) {
             return ITrit\Type::zero();
         } else {
             // ($__x > $__y)
             return ITrit\Type::positive();
         }
     }
 }
Пример #2
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));
 }
Пример #3
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param IUnit\Type $x                                     the left operand
  * @param IUnit\Type $y                                     the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(IUnit\Type $x, IUnit\Type $y) : ITrit\Type
 {
     if (IUnit\Module::eq($x, $y)->unbox()) {
         return ITrit\Type::zero();
     }
     return ITrit\Type::make(strcmp($x->__typeOf(), $y->__typeOf()));
 }
Пример #4
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the left operand
  * @param IString\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(IString\Type $xs, IString\Type $ys) : ITrit\Type
 {
     return ITrit\Type::make(strcmp($xs->unbox(), $ys->unbox()));
 }
Пример #5
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param Throwable\Runtime\Exception $x                    the left operand
  * @param Throwable\Runtime\Exception $y                    the right operand
  * @return ITrit\Type                                        the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(Throwable\Runtime\Exception $x, Throwable\Runtime\Exception $y)
 {
     $x = $x->__getCode();
     $y = $y->__getCode();
     if ($x < $y) {
         return ITrit\Type::negative();
     } else {
         if ($x == $y) {
             return ITrit\Type::zero();
         } else {
             // ($x > $y)
             return ITrit\Type::positive();
         }
     }
 }
Пример #6
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $p0 = ITrit\Type::make($provided[0])->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Пример #7
0
 /**
  * This method returns an object with a "0" value.
  *
  * @access public
  * @static
  * @return ITrit\Type                                       the object
  */
 public static function zero() : ITrit\Type
 {
     return ITrit\Type::box(0);
 }
Пример #8
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();
         }
     }
 }
Пример #9
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param IInt32\Type $x                                    the left operand
  * @param IInt32\Type $y                                    the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(IInt32\Type $x, IInt32\Type $y) : ITrit\Type
 {
     return ITrit\Type::box($x->unbox() <=> $y->unbox());
 }
Пример #10
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param IInteger\Type $x                                  the left operand
  * @param IInteger\Type $y                                  the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(IInteger\Type $x, IInteger\Type $y) : ITrit\Type
 {
     return ITrit\Type::make(gmp_cmp($x->unbox(), $y->unbox()));
 }
Пример #11
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param ITuple\Type $xs                                   the left operand
  * @param ITuple\Type $ys                                   the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(ITuple\Type $xs, ITuple\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());
 }
Пример #12
0
 /**
  * This method tests the "min" method.
  *
  * @dataProvider data_min
  */
 public function test_min(array $provided, array $expected)
 {
     $p0 = ITrit\Module::min(ITrit\Type::box($provided[0]), ITrit\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Пример #13
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param IChar\Type $x                                     the left operand
  * @param IChar\Type $y                                     the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(IChar\Type $x, IChar\Type $y) : ITrit\Type
 {
     return ITrit\Type::box(ord($x->unbox()) <=> ord($y->unbox()));
 }
Пример #14
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xs                              the left operand
  * @param ILinkedList\Type $ys                              the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(ILinkedList\Type $xs, ILinkedList\Type $ys) : ITrit\Type
 {
     for ($as = $xs, $bs = $ys; !$as->__isEmpty() && !$bs->__isEmpty(); $as = $as->tail(), $bs = $bs->tail()) {
         $r = $as->head()->compare($bs->head());
         if ($r->unbox() != 0) {
             return $r;
         }
     }
     return ITrit\Type::box($xs->__length() <=> $ys->__length());
 }