2016-03-21 8 views
-1

私のプロジェクトでは、2つのメソッドが必要です:1つは追加のためバージョンをオブジェクトに追加し、もう1つは削除するメソッドです。 これらの2つの方法のロジックはほぼ同じです:条件を検証し、すべてがOKなら問題のバージョンCollectionにバージョンを追加/削除します。 Collectiion::addCollection::removeを使用する際にいくつか問題があります。そのため、2つの静的メソッドremoveVersionaddVersionを作成しました。このメソッドを更新するにはどうすればいいですか?FixVersionServiceImpl::addVersionFixVersionServiceImpl::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); 
    } 

答えて

2

Collection::add::removeは、第1のタイプは、コレクション・インスタンスを囲むを指すタイプBiFunction<Collection<T>, T, Boolean>、です。だから、引数としてこれらのメソッドを渡すなど、ラムダとしてそれらを使用する:あなたはBiFunction<Collection<Version>, Version, Boolean>にその引数の型を変更する必要が

function.apply(fixVersions, version);