/** * Evaluates two string operands. * * @param \Tbm\Peval\Types\String $leftOperand * @param \Tbm\Peval\Types\String $rightOperand * @internal param $leftOperand The left operand being evaluated. * The left operand being evaluated. * @internal param $rightOperand The right operand being evaluated. * The right operand being evaluated. * @return string */ protected function evaluate2Strings(string $leftOperand, string $rightOperand) { if ($leftOperand . compareTo($rightOperand) > 0) { return EvaluationConstants::BOOLEAN_STRING_TRUE; } return EvaluationConstants::BOOLEAN_STRING_FALSE; }
/** * Mergesort for an array with objects all from the same type * implementing the Comparable interface. * * This sort is guaranteed to be <i>stable</i>: equal elements will * not be reordered as a result of the sort. The sorting algorithm is * mergesort. This algorithm offers guaranteed n*log(n) performance. * * Note: This function assigns new keys to the elements in array . * It will remove any existing keys that may have been assigned, rather * than just reordering the keys. * * @param array Array to sort * @return boolean true on success, false on failure * @author sreid at sea-to-sky dot net * @link http://www.php.net/manual/en/function.usort.php#38827 */ private static function mergesort(array &$array) { // Arrays of size < 2 require no action. if (count($array) < 2) { return true; } // Split the array in half $halfway = count($array) / 2; $array1 = array_slice($array, 0, $halfway); $array2 = array_slice($array, $halfway); // Recurse to sort the two halves self::mergesort($array1); self::mergesort($array2); if (is_a(end($array1), 'Comparable') == false) { return false; } // If all of $array 1 is <= all of $array2, just append them. // Original code: call_user_func($cmpFunction, end($array1), $array2[0]) if (end($array1).compareTo($array2[0]) < 1) { $array = array_merge($array1, $array2); return true; } // Merge the two sorted arrays into a single sorted array $array = array(); $ptr1 = 0; $ptr2 = 0; while ($ptr1 < count($array1) && $ptr2 < count($array2)) { if (is_a($array1[$ptr1], 'Comparable') == false) { return false; } // Original code: call_user_func($cmpFunction, $array1[$ptr1], $array2[$ptr2]) if ($array1[$ptr1].compareTo($array2[$ptr2]) < 1) { $array[] = $array1[$ptr1++]; } else { $array[] = $array2[$ptr2++]; } } // Merge the remainder while ($ptr1 < count($array1)) { $array[] = $array1[$ptr1++]; } while ($ptr2 < count($array2)) { $array[] = $array2[$ptr2++]; } return true; }