我在Java中使用哈希映射来检索软件系统的API。因此,我有类似以下的内容:
[SoftwareID, SoftwareAPI]
当我请求软件系统的所有API时,我会得到以下内容:
[ [SoftwareID, SoftwareAPI], [SoftwareID, SoftwareAPI], [SoftwareID, SoftwareAPI] ]
我有一个问题,我需要根据软件来删除所有重复的SoftwareAPIs。
例如,当我遍历我的哈希映射时,我得到:
[ [0, A], [0, B], [0, A], [0, A] ];
[ [1, A], [1, B], [1, B], [1, C] ];
[ [2, A], [2, B], [2, A] ];
但我需要删除重复的对,所以它应该是这样的:
[ [0, A], [0, B] ];
[ [1, A], [1, B], [1, C] ];
[ [2, A], [2, B] ]
这里有一些代码信息:
// HashMap APIs per user/Systems
HashMap<Integer, Set<API>> apisPerSystem = new HashMap<Integer, Set<API>>();
/**
* Stores a API in the data model
* @param system the user
* @param api the item
* @return the newly added API
*/
public API addAPIs(int system, String api) {
API r = new API(system,api);
apis.add(r);
Set<API> systemApis = apisPerUser.get(system);
if (systemApis == null) {
systemApis = new HashSet<API>();
}
apisPerUser.put(system, systemApis);
systemApis.add(r);
systems.add(system);
apisList.add(api);
return r;
}
// Get the APIs per Systemfrom the outside.
public HashMap<Integer, Set<API>> getAPIsPerSystem() {
return apisPerSystem;
}