システム内のデータのディープ コピーを実行したいと考えています。私はこの種のクラスを持っています:
Class User{
User mother;
User father;
User spouse;
}
個々のレコードを作成した後、次のように参照を再構築します。
Map<User, User> motherMap = new HashMap<User, User>();
Map<User, User> fatherMap = ...;
Map<User, User> spouseMap = ...;
//Now I want to populate User reference like this:
for(User user : motherMap.keySet) {
//some other similar code;
user.setMother(motherMap.get(user));
}
for(User user : fatherMap.keySet) {
//some other similar code;
user.setFather(fatherMap.get(user));
}
for(User user : motherMap.keySet) {
//some other similar code;
user.setSpouse(spouseMap.get(user));
}
この種の同様のコードをクリーンアップする方法はありますか? 実際のコードではユーザー間に 10 以上の参照があるため、コードをより良くしたいと考えています。Intellij は、この方法は複雑すぎて分析できないと警告しています。