WebLinks: Convert Functions/Predicates to lambdas
Change-Id: I96e7c03839fb86c775d63e6dd6adf10a233865a1
This commit is contained in:
		@@ -39,11 +39,9 @@ import org.slf4j.LoggerFactory;
 | 
			
		||||
@Singleton
 | 
			
		||||
public class WebLinks {
 | 
			
		||||
  private static final Logger log = LoggerFactory.getLogger(WebLinks.class);
 | 
			
		||||
  private static final Predicate<WebLinkInfo> INVALID_WEBLINK =
 | 
			
		||||
      new Predicate<WebLinkInfo>() {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean apply(WebLinkInfo link) {
 | 
			
		||||
  private static final Predicate<WebLinkInfo> INVALID_WEBLINK =
 | 
			
		||||
      link -> {
 | 
			
		||||
        if (link == null) {
 | 
			
		||||
          return false;
 | 
			
		||||
        } else if (Strings.isNullOrEmpty(link.name)
 | 
			
		||||
@@ -53,13 +51,10 @@ public class WebLinks {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
  private static final Predicate<WebLinkInfoCommon> INVALID_WEBLINK_COMMON =
 | 
			
		||||
      new Predicate<WebLinkInfoCommon>() {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean apply(WebLinkInfoCommon link) {
 | 
			
		||||
  private static final Predicate<WebLinkInfoCommon> INVALID_WEBLINK_COMMON =
 | 
			
		||||
      link -> {
 | 
			
		||||
        if (link == null) {
 | 
			
		||||
          return false;
 | 
			
		||||
        } else if (Strings.isNullOrEmpty(link.name)
 | 
			
		||||
@@ -69,7 +64,6 @@ public class WebLinks {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
  private final DynamicSet<PatchSetWebLink> patchSetLinks;
 | 
			
		||||
@@ -85,8 +79,7 @@ public class WebLinks {
 | 
			
		||||
      DynamicSet<FileHistoryWebLink> fileLogLinks,
 | 
			
		||||
      DynamicSet<DiffWebLink> diffLinks,
 | 
			
		||||
      DynamicSet<ProjectWebLink> projectLinks,
 | 
			
		||||
      DynamicSet<BranchWebLink> branchLinks
 | 
			
		||||
      ) {
 | 
			
		||||
      DynamicSet<BranchWebLink> branchLinks) {
 | 
			
		||||
    this.patchSetLinks = patchSetLinks;
 | 
			
		||||
    this.fileLinks = fileLinks;
 | 
			
		||||
    this.fileHistoryLinks = fileLogLinks;
 | 
			
		||||
@@ -101,15 +94,11 @@ public class WebLinks {
 | 
			
		||||
   * @param commit SHA1 of commit.
 | 
			
		||||
   * @return Links for patch sets.
 | 
			
		||||
   */
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getPatchSetLinks(final Project.NameKey project,
 | 
			
		||||
      final String commit) {
 | 
			
		||||
    return filterLinks(patchSetLinks, new Function<WebLink, WebLinkInfo>() {
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public WebLinkInfo apply(WebLink webLink) {
 | 
			
		||||
        return ((PatchSetWebLink)webLink).getPatchSetWebLink(project.get(), commit);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getPatchSetLinks(Project.NameKey project,
 | 
			
		||||
      String commit) {
 | 
			
		||||
    return filterLinks(
 | 
			
		||||
        patchSetLinks,
 | 
			
		||||
        webLink -> webLink.getPatchSetWebLink(project.get(), commit));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -119,15 +108,11 @@ public class WebLinks {
 | 
			
		||||
   * @param file File name.
 | 
			
		||||
   * @return Links for files.
 | 
			
		||||
   */
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getFileLinks(final String project, final String revision,
 | 
			
		||||
      final String file) {
 | 
			
		||||
    return filterLinks(fileLinks, new Function<WebLink, WebLinkInfo>() {
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public WebLinkInfo apply(WebLink webLink) {
 | 
			
		||||
        return ((FileWebLink)webLink).getFileWebLink(project, revision, file);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getFileLinks(String project,
 | 
			
		||||
      String revision, String file) {
 | 
			
		||||
    return filterLinks(
 | 
			
		||||
        fileLinks,
 | 
			
		||||
        webLink -> webLink.getFileWebLink(project, revision, file));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -137,28 +122,21 @@ public class WebLinks {
 | 
			
		||||
   * @param file File name.
 | 
			
		||||
   * @return Links for file history
 | 
			
		||||
   */
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getFileHistoryLinks(final String project,
 | 
			
		||||
      final String revision, final String file) {
 | 
			
		||||
    return filterLinks(fileHistoryLinks, new Function<WebLink, WebLinkInfo>() {
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public WebLinkInfo apply(WebLink webLink) {
 | 
			
		||||
        return ((FileHistoryWebLink) webLink).getFileHistoryWebLink(project,
 | 
			
		||||
            revision, file);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getFileHistoryLinks(String project,
 | 
			
		||||
      String revision, String file) {
 | 
			
		||||
    return filterLinks(
 | 
			
		||||
        fileHistoryLinks,
 | 
			
		||||
        webLink -> webLink.getFileHistoryWebLink(project, revision, file));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public FluentIterable<WebLinkInfoCommon> getFileHistoryLinksCommon(
 | 
			
		||||
      final String project, final String revision, final String file) {
 | 
			
		||||
      String project, String revision, String file) {
 | 
			
		||||
    return FluentIterable
 | 
			
		||||
        .from(fileHistoryLinks)
 | 
			
		||||
        .transform(new Function<WebLink, WebLinkInfoCommon>() {
 | 
			
		||||
          @Override
 | 
			
		||||
          public WebLinkInfoCommon apply(WebLink webLink) {
 | 
			
		||||
        .transform(
 | 
			
		||||
            webLink -> {
 | 
			
		||||
              WebLinkInfo info =
 | 
			
		||||
                ((FileHistoryWebLink) webLink).getFileHistoryWebLink(project,
 | 
			
		||||
                    revision, file);
 | 
			
		||||
                  webLink.getFileHistoryWebLink(project, revision, file);
 | 
			
		||||
              if (info == null) {
 | 
			
		||||
                return null;
 | 
			
		||||
              }
 | 
			
		||||
@@ -168,7 +146,6 @@ public class WebLinks {
 | 
			
		||||
              commonInfo.url = info.url;
 | 
			
		||||
              commonInfo.target = info.target;
 | 
			
		||||
              return commonInfo;
 | 
			
		||||
          }
 | 
			
		||||
            })
 | 
			
		||||
        .filter(INVALID_WEBLINK_COMMON);
 | 
			
		||||
  }
 | 
			
		||||
@@ -190,14 +167,10 @@ public class WebLinks {
 | 
			
		||||
      final int patchSetIdB, final String revisionB, final String fileB) {
 | 
			
		||||
   return FluentIterable
 | 
			
		||||
       .from(diffLinks)
 | 
			
		||||
       .transform(new Function<WebLink, DiffWebLinkInfo>() {
 | 
			
		||||
         @Override
 | 
			
		||||
         public DiffWebLinkInfo apply(WebLink webLink) {
 | 
			
		||||
            return ((DiffWebLink) webLink).getDiffLink(project, changeId,
 | 
			
		||||
       .transform(webLink ->
 | 
			
		||||
            webLink.getDiffLink(project, changeId,
 | 
			
		||||
                patchSetIdA, revisionA, fileA,
 | 
			
		||||
                patchSetIdB, revisionB, fileB);
 | 
			
		||||
          }
 | 
			
		||||
       })
 | 
			
		||||
                patchSetIdB, revisionB, fileB))
 | 
			
		||||
       .filter(INVALID_WEBLINK);
 | 
			
		||||
 }
 | 
			
		||||
 | 
			
		||||
@@ -207,13 +180,9 @@ public class WebLinks {
 | 
			
		||||
   * @return Links for projects.
 | 
			
		||||
   */
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getProjectLinks(final String project) {
 | 
			
		||||
    return filterLinks(projectLinks, new Function<WebLink, WebLinkInfo>() {
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public WebLinkInfo apply(WebLink webLink) {
 | 
			
		||||
        return ((ProjectWebLink)webLink).getProjectWeblink(project);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
    return filterLinks(
 | 
			
		||||
        projectLinks,
 | 
			
		||||
        webLink -> webLink.getProjectWeblink(project));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -223,17 +192,13 @@ public class WebLinks {
 | 
			
		||||
   * @return Links for branches.
 | 
			
		||||
   */
 | 
			
		||||
  public FluentIterable<WebLinkInfo> getBranchLinks(final String project, final String branch) {
 | 
			
		||||
    return filterLinks(branchLinks, new Function<WebLink, WebLinkInfo>() {
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public WebLinkInfo apply(WebLink webLink) {
 | 
			
		||||
        return ((BranchWebLink)webLink).getBranchWebLink(project, branch);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
    return filterLinks(
 | 
			
		||||
        branchLinks,
 | 
			
		||||
        webLink -> webLink.getBranchWebLink(project, branch));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private FluentIterable<WebLinkInfo> filterLinks(DynamicSet<? extends WebLink> links,
 | 
			
		||||
      Function<WebLink, WebLinkInfo> transformer) {
 | 
			
		||||
  private <T extends WebLink> FluentIterable<WebLinkInfo> filterLinks(DynamicSet<T> links,
 | 
			
		||||
      Function<T, WebLinkInfo> transformer) {
 | 
			
		||||
    return FluentIterable
 | 
			
		||||
        .from(links)
 | 
			
		||||
        .transform(transformer)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user