public function testIsEmpty() { // Remove the following lines when you implement this test. $this->assertFalse($this->object->isEmpty()); $this->object->clear(); $this->assertTrue($this->object->isEmpty()); }
/** * This method tests the add and the get method * of the HashMap. * * @return void */ public function testAddAndGetAndIsEmptyAndClear() { // initialize a new HashMap $map = new HashMap(); // check that the HashMap is empty $this->assertTrue($map->isEmpty()); // add a new element $map->add(10, "Test"); // get the element $this->assertEquals("Test", $map->get(10)); // check that the HashMap is not empty $this->assertFalse($map->isEmpty()); // remove all elements $map->clear(); // check that the HashMap is empty $this->assertTrue($map->isEmpty()); }
function test_isEmpty_empty_returnsTrue() { $map = new HashMap(); $this->assertTrue($map->isEmpty()); $this->assertTrue($map->getIterator()->isEmpty()); }
/** * getPlainSortAndByAnd方法 使用&符号组织签名明文串排序a-z,如:merId=9996&goodsId=100&version=3.0 * @param HashMap $map */ public static function getPlainSortAndByAnd($map) { $log = new Logger(); $plain = ""; $arg = ""; $paramter = array(); if (!$map->isEmpty() && $map->size() > 0) { $keys = $map->keys(); foreach ($keys as $key) { // $log->logInfo (" ssssssgetRequestData plain111122333=" . $keys ); //如果是sign_type 不许要参与RAS签名 if ("sign_type" != $key) { $plain = $plain . $key . "=" . $map->get($key) . "|"; //$paramter = explode ( "&", $plain ); $paramter[$key . "=" . $map->get($key)] = $key . "=" . $map->get($key); } } $plain = substr($plain, 0, strlen($plain) - 1); // $log->logInfo (" ssssssgetRequestData plain111122=" . $plain ); //$paramter = explode ( "|", $plain ); $sort_array = StringUtil::arg_sort($paramter); //得到从字母a到z排序后的加密参数数组 while (list($key, $val) = each($sort_array)) { $arg .= $val . "&"; //$log->logInfo (" ssssssgetRequestData plain11=" . $arg ); } $arg = substr($arg, 0, count($arg) - 2); //去掉最后一个&字符 //die ( "使用&组织签名明文串失败:传入参数为空!".$arg."|".plain ); return $arg; } else { die("Use & organize signature plaintext string failure: incoming parameters is empty!"); return null; } //$log->logInfo (" ssssssgetRequestData plain115=" . $arg ); return $arg; }
/** * V4.0对商户提交的参数进行校验,最终返回一个提交给平台的HashMap * @param HashMap $param 商户提交的参数 * @param HashMap $fields1 必填的参数 * @param HashMap $fields2 非必填参数 */ public static function getData($param, $fields1, $fields2) { //需要进行日期校验的参数 $field_date = new HashMap(); $field_date->put("settle_date", "settle_date"); $field_date->put("mer_date", "mer_date"); $field_date->put("payDate", "payDate"); //需要进行RAS加密的参数 $field_ras = new HashMap(); $field_ras->put("card_id", "card_id"); $field_ras->put("valid_date", "valid_date"); $field_ras->put("cvv2", "cvv2"); $field_ras->put("pass_wd", "pass_wd"); $field_ras->put("identity_code", "identity_code"); $field_ras->put("card_holder", "card_holder"); //付款请求添加RAS加密的参数 $field_ras->put("recv_account", "recv_account"); $field_ras->put("recv_user_name", "recv_user_name"); $field_ras->put("identity_holder", "identity_holder"); $data = new HashMap(); if (!$fields1->isEmpty() && $fields1->size() > 0) { $keys = $fields1->keys(); foreach ($keys as $key) { $value = StringUtil::trim($param->get($key)); $length = StringUtil::trim($fields1->get($key)); $flag = $field_date->containsKey($key); $flag1 = $field_ras->containsKey($key); if ($flag1) { if ("" == $value) { die($key . "为空或者长度超过限制"); } else { $value = iconv("UTF-8", "GBK", $value); $value = RSACryptUtil::encrypt($value); $data->put($key, $value); } } elseif ($flag) { if (!DateUtil::checkData($value)) { die($key . "为空或者长度不符合要求"); } else { $data->put($key, $value); } } elseif ("split_data" == $key) { if ("" == $value) { die($key . "为空或者长度超过限制"); } else { $data->put($key, $value); } } else { if ("" == $value || strlen($value) > $length) { die($key . "为空或者长度超过限制"); } else { $data->put($key, $value); } } } $keys1 = $fields2->keys(); foreach ($keys1 as $key) { if (!is_null($param->get($key))) { $value = StringUtil::trim($param->get($key)); $length = StringUtil::trim($fields2->get($key)); $flag1 = $field_ras->containsKey($key); if ($flag1) { if ("" != $value) { if (strlen($value) > $length) { die($key . "为空或者长度超过限制"); } else { $value = iconv("UTF-8", "GBK", $value); $value = RSACryptUtil::encrypt($value); $data->put($key, $value); } } } elseif ($field_date->containsKey($key)) { if (!DateUtil::checkData($value)) { die($key . "为空或者长度不符合要求"); } else { $data->put($key, $value); } } elseif ("split_data" == $key) { if ("" != $value) { $data->put($key, $value); } } else { if ("" != $value) { if (strlen($value) > $length) { die($key . "为空或者长度超过限制"); } else { $data->put($key, $value); } } } } } } else { die("获取请求参数字符串失败:传入参数为空!"); } return $data; }