私のプロジェクトでは、2つのメソッドが必要です:1つは追加のためバージョンをオブジェクトに追加し、もう1つは削除するメソッドです。 これらの2つの方法のロジックはほぼ同じです:条件を検証し、すべてがOKなら問題のバージョンCollection
にバージョンを追加/削除します。 Collectiion::add
とCollection::remove
を使用する際にいくつか問題があります。そのため、2つの静的メソッドremoveVersion
とaddVersion
を作成しました。このメソッドを更新するにはどうすればいいですか?FixVersionServiceImpl::addVersion
とFixVersionServiceImpl::removeVersion
は必要ありません。FixVersionServiceImpl - 現在のクラス名はどこですか?Collection :: addとCollection :: removeを使用した更新メソッド
private boolean updateIssueVersion(User user,
IssuesVersionUpdateDescription issueVersionUpdate,
Version version,
BiFunction<Version, Collection<Version>, Boolean> function) {
boolean updated = false;
for (String issueKey : issueVersionUpdate.getIssueKeys()) {
IssueService.IssueResult issueResult = issueService.getIssue(user, issueKey);
MutableIssue issue = issueResult.getIssue();
if (issue == null) {
LOG.info("Issue was not found for user.");
continue;
}
if (issue.getProjectObject() == null
|| !issue.getProjectObject().getKey().equals(version.getProject().getKey())) {
LOG.error("Issue project doesn't contain this fix version.");
continue;
}
Collection<Version> fixVersions = issue.getFixVersions();
function.apply(version, fixVersions);
issue.setFixVersions(fixVersions);
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);
updated = true;
}
return updated;
}
private static boolean addVersion(Version version, Collection<Version> fixVersions) {
return fixVersions.add(version);
}
private static boolean removeVersion(Version version, Collection<Version> fixVersions) {
return fixVersions.remove(version);
}