From 72349bed0f0e493ee613cacaa0be1d377d97b05e Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 30 Nov 2016 17:10:02 +0300 Subject: [PATCH] [vcs]: cleanUp remove deprecated usage, lambdify --- .../src/com/intellij/dvcs/DvcsUtil.java | 77 +++++-------------- 1 file changed, 20 insertions(+), 57 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java b/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java index 483727401eb0..a95019b95d9b 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/DvcsUtil.java @@ -36,7 +36,6 @@ import com.intellij.openapi.roots.JdkOrderEntry; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -82,19 +81,17 @@ public class DvcsUtil { /** * Comparator for virtual files by name */ - public static final Comparator VIRTUAL_FILE_PRESENTATION_COMPARATOR = new Comparator() { - public int compare(final VirtualFile o1, final VirtualFile o2) { - if (o1 == null && o2 == null) { - return 0; - } - if (o1 == null) { - return -1; - } - if (o2 == null) { - return 1; - } - return o1.getPresentableUrl().compareTo(o2.getPresentableUrl()); + public static final Comparator VIRTUAL_FILE_PRESENTATION_COMPARATOR = (o1, o2) -> { + if (o1 == null && o2 == null) { + return 0; } + if (o1 == null) { + return -1; + } + if (o2 == null) { + return 1; + } + return o1.getPresentableUrl().compareTo(o2.getPresentableUrl()); }; @NotNull @@ -105,12 +102,7 @@ public class DvcsUtil { @NotNull public static List findVirtualFilesWithRefresh(@NotNull List files) { RefreshVFsSynchronously.refreshFiles(files); - return ContainerUtil.mapNotNull(files, new Function() { - @Override - public VirtualFile fun(File file) { - return VfsUtil.findFileByIoFile(file, false); - } - }); + return ContainerUtil.mapNotNull(files, file -> VfsUtil.findFileByIoFile(file, false)); } /** @@ -124,17 +116,12 @@ public class DvcsUtil { @NotNull public static String getShortRepositoryName(@NotNull Repository repository) { - return getShortRepositoryName(repository.getProject(), repository.getRoot()); + return VcsImplUtil.getShortVcsRootName(repository.getProject(), repository.getRoot()); } @NotNull public static String getShortNames(@NotNull Collection repositories) { - return StringUtil.join(repositories, new Function() { - @Override - public String fun(Repository repository) { - return getShortRepositoryName(repository); - } - }, ", "); + return StringUtil.join(repositories, (Function)repository -> getShortRepositoryName(repository), ", "); } @NotNull @@ -220,12 +207,7 @@ public class DvcsUtil { ApplicationManager.getApplication().getMessageBus().syncPublisher(BatchFileChangeListener.TOPIC).batchChangeCompleted(project); } - public static final Comparator REPOSITORY_COMPARATOR = new Comparator() { - @Override - public int compare(Repository o1, Repository o2) { - return o1.getPresentableUrl().compareTo(o2.getPresentableUrl()); - } - }; + public static final Comparator REPOSITORY_COMPARATOR = Comparator.comparing(Repository::getPresentableUrl); public static void assertFileExists(File file, String message) throws IllegalStateException { if (!file.exists()) { @@ -248,12 +230,7 @@ public class DvcsUtil { @NotNull public static String tryLoadFile(@NotNull final File file, @Nullable String encoding) throws RepoStateException { - return tryOrThrow(new Callable() { - @Override - public String call() throws Exception { - return StringUtil.convertLineSeparators(FileUtil.loadFile(file, encoding)).trim(); - } - }, file); + return tryOrThrow(() -> StringUtil.convertLineSeparators(FileUtil.loadFile(file, encoding)).trim(), file); } @Nullable @@ -406,12 +383,7 @@ public class DvcsUtil { } public static List sortRepositories(@NotNull Collection repositories) { - List validRepositories = ContainerUtil.filter(repositories, new Condition() { - @Override - public boolean value(T t) { - return t.getRoot().isValid(); - } - }); + List validRepositories = ContainerUtil.filter(repositories, t -> t.getRoot().isValid()); Collections.sort(validRepositories, REPOSITORY_COMPARATOR); return validRepositories; } @@ -492,12 +464,8 @@ public class DvcsUtil { @Nullable public static PushSupport getPushSupport(@NotNull final AbstractVcs vcs) { - return ContainerUtil.find(Extensions.getExtensions(PushSupport.PUSH_SUPPORT_EP, vcs.getProject()), new Condition() { - @Override - public boolean value(final PushSupport support) { - return support.getVcs().equals(vcs); - } - }); + return ContainerUtil.find(Extensions.getExtensions(PushSupport.PUSH_SUPPORT_EP, vcs.getProject()), + support -> support.getVcs().equals(vcs)); } @NotNull @@ -507,12 +475,7 @@ public class DvcsUtil { @NotNull public static String joinShortNames(@NotNull Collection repositories, int limit) { - return joinWithAnd(ContainerUtil.map(repositories, new Function() { - @Override - public String fun(@NotNull Repository repository) { - return getShortRepositoryName(repository); - } - }), limit); + return joinWithAnd(ContainerUtil.map(repositories, (Function)repository -> getShortRepositoryName(repository)), limit); } @NotNull @@ -523,7 +486,7 @@ public class DvcsUtil { if (size == 2) return strings.get(0) + " and " + strings.get(1); boolean isLimited = limit >= 2 && limit < size; - int listCount = isLimited ? limit - 1 : size - 1; + int listCount = (isLimited ? limit : size) - 1; StringBuilder sb = new StringBuilder(); for (int i = 0; i < listCount; i++) {