function testPutSameElementTwice()
 {
     $map = new HashMap("integer", "string");
     $map->put(4, "Peter");
     $map->put(4, "Raf");
     $this->assertEqual(1, $map->size());
     $this->assertEqual("Raf", $map->get(4));
 }
Exemple #2
0
 public function addAll(HashMap $items)
 {
     if ($items->size() < 1) {
         return false;
     }
     foreach ($items->getAll() as $itemKey => $itemValue) {
         $this->add($itemKey, $itemValue);
     }
     return true;
 }
Exemple #3
0
 /**
  * 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;
 }
 /**
  *
  * @param SerializationStreamWriter $streamWriter
  * @param HashMap $instance
  * @param MappedClass $instanceClass
  * @throws SerializationException
  */
 public static function serialize(SerializationStreamWriter $streamWriter, $instance, MappedClass $instanceClass)
 {
     if ($instance instanceof HashMap) {
         $size = $instance->size();
         $streamWriter->writeInt($size);
         //assert($instanceClass->isGeneric()); //jesli nie array to zapomniano w gwtphpmap dodacgenericsow
         if ($instanceClass->isGeneric()) {
             $typeParameters = $instanceClass->getTypeParameters();
         } else {
             $typeParameters = array();
         }
         assert(is_array($typeParameters));
         //jesli nie array to zapomniano w gwtphpmap dodacgenericsow
         foreach ($instance->getKeySet() as $key) {
             $streamWriter->writeObject($key, $typeParameters[0]);
             $streamWriter->writeObject($instance->get($key), $typeParameters[1]);
         }
     } else {
         if (is_array($instance)) {
             // $instance is array
             //$size = $instance->size();
             $size = count($instance);
             $streamWriter->writeInt($size);
             //for (Object obj : instance) {
             if (!$instanceClass->isGeneric()) {
                 require_once GWTPHP_DIR . '/maps/java/lang/SerializationException.class.php';
                 throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap must be mapped as generic type! add < > to signatures and CRC");
             }
             $typeParameters = $instanceClass->getTypeParameters();
             if (!isset(HashMap_CustomFieldSerializer::$ACCEPTABLE_KEY_TYPES[$typeParameters[0]->getSignature()])) {
                 require_once GWTPHP_DIR . '/maps/java/lang/SerializationException.class.php';
                 throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap_CustomFieldSerializer serialize only array() where " . "keys object are mapped by one of following types: " . "java.lang.String, java.lang.Byte, java.lang.Character, java.lang.Double, " . "java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short, but given: " . $typeParameters[0]->getSignature());
             }
             foreach ($instance as $key => $obj) {
                 $streamWriter->writeObject($key, $typeParameters[0]);
                 $streamWriter->writeObject($obj, $typeParameters[1]);
             }
         } else {
             require_once GWTPHP_DIR . '/maps/java/lang/UnimplementedOperationException.class.php';
             throw new UnimplementedOperationException("HashMap_CustomFieldSerializer serialize type: " + gettype($instance) + " not implemented");
         }
     }
 }
Exemple #5
0
 /**
  * マッピングの個数を整数で返すことを確認します.
  * 
  * @covers Peach\Util\HashMap::size
  */
 public function testSize()
 {
     $this->assertSame(3, $this->object->size());
 }
Exemple #6
0
 /**
  * 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;
 }
 /**
  * This method tests the merge method
  * of the hash map.
  *
  * @return void
  */
 public function testMerge()
 {
     // initialize a new HashMap
     $map = new HashMap();
     // initialize a new hash map and add some elements
     $mergeMap = new HashMap();
     $mergeMap->add(1, "test_merge_1");
     $mergeMap->add(3, "test_merge_3");
     // add some elements to the original hash map
     $map->add(1, "test_original_1");
     $map->add(2, "test_original_2");
     // merge the original map with the new one
     $map->merge($mergeMap);
     // check the merge result
     $this->assertEquals(3, $map->size());
     $this->assertEquals("test_original_1", $map->get(1));
 }