gpt4 book ai didi

java - 迁移到 HRD - 如何将字符串编码的 key 转换为新应用程序

转载 作者:行者123 更新时间:2023-11-30 11:46:25 25 4
gpt4 key购买 nike

我已经开始从我们的 M/S 应用程序迁移到 HRD。我想知道您是否可以推荐我如何将旧字符串编码 key 转换为新字符串。

我知道字符串编码的键包含应用程序名称,但我不确定是否还有其他需要注意的细节。此外,我找不到任何论坛帖子,其中有 Java 转换“字符串编码键”的代码示例,这对我来说很奇怪(只有 python 论坛讨论它)。

对于此事,我将不胜感激。

顺便说一句,我想运行以下,虽然我担心它不会工作或涵盖所有方面:

    private static String convertKey(String encodedKey) {
Key key = KeyFactory.stringToKey(encodedKey);
Key newKey = KeyFactory.createKey(key.getKind(), key.getId());
return KeyFactory.keyToString(newKey);
}

谢谢!乌里

最佳答案

使用以下递归函数 generateKey(Key key) 可以涵盖编码字符串 key 转换的所有情况(也包括级联父级)。其他两个函数是一个结束键集合转换的包装器。 http://www.geotrack24.com

private Key generateKey(Key key) {  
Key parentKey = key.getParent();
if(parentKey == null){
return KeyFactory.createKey(key.getKind(), key.getId());
}else{
Key _newParentKey = generateKey(parentKey);
return KeyFactory.createKey(_newParentKey, key.getKind(), key.getId());
}
}

private String convertKey(String encodedKey) {
Key key = KeyFactory.stringToKey(encodedKey);
return KeyFactory.keyToString(generateKey(key));
}

private Set<String> convertKeys(Set<String> keys){
Set<String> newkeys = new HashSet<String>();
for(String key: keys){
newkeys.add(convertKey(key));
}
return newkeys;
}

关于java - 迁移到 HRD - 如何将字符串编码的 key 转换为新应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9760205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com