svn: Migrate "String" to "Url" in "SvnRepositoryCache"

This commit is contained in:
Konstantin Kolosovsky
2018-11-21 16:56:51 +03:00
parent 8743c4c3c6
commit 6637ca274d
4 changed files with 19 additions and 22 deletions
@@ -25,13 +25,11 @@ public class CacheLoader extends Loader {
@Override
public void load(@NotNull final RepositoryTreeNode node, @NotNull final Expander expander) {
SwingUtilities.invokeLater(() -> {
final String nodeUrl = node.getURL().toString();
final List<DirectoryEntry> cached = myCache.getChildren(nodeUrl);
final List<DirectoryEntry> cached = myCache.getChildren(node.getURL());
if (cached != null) {
refreshNode(node, cached, expander);
}
final String error = myCache.getError(nodeUrl);
final String error = myCache.getError(node.getURL());
if (error != null) {
refreshNodeError(node, error);
}
@@ -50,12 +50,12 @@ class RepositoryLoader extends Loader {
}
private void setResults(@NotNull Pair<RepositoryTreeNode, Expander> data, @NotNull List<DirectoryEntry> children) {
myCache.put(data.first.getURL().toString(), children);
myCache.put(data.first.getURL(), children);
refreshNode(data.first, children, data.second);
}
private void setError(@NotNull Pair<RepositoryTreeNode, Expander> data, @NotNull String message) {
myCache.put(data.first.getURL().toString(), message);
myCache.put(data.first.getURL(), message);
refreshNodeError(data.first, message);
}
@@ -3,27 +3,28 @@ package org.jetbrains.idea.svn.dialogs.browserCache
import com.intellij.openapi.components.service
import com.intellij.util.containers.ContainerUtil.createSoftMap
import org.jetbrains.idea.svn.api.Url
import org.jetbrains.idea.svn.browse.DirectoryEntry
class SvnRepositoryCache private constructor() {
private val myMap = createSoftMap<String, List<DirectoryEntry>>()
private val myErrorsMap = createSoftMap<String, String>()
private val myMap = createSoftMap<Url, List<DirectoryEntry>>()
private val myErrorsMap = createSoftMap<Url, String>()
fun getChildren(parent: String) = myMap[parent]
fun getChildren(parent: Url) = myMap[parent]
fun getError(parent: String) = myErrorsMap[parent]
fun getError(parent: Url) = myErrorsMap[parent]
fun put(parent: String, error: String) {
fun put(parent: Url, error: String) {
myMap.remove(parent)
myErrorsMap[parent] = error
}
fun put(parent: String, children: List<DirectoryEntry>) {
fun put(parent: Url, children: List<DirectoryEntry>) {
myErrorsMap.remove(parent)
myMap[parent] = children
}
fun remove(parent: String) {
fun remove(parent: Url) {
myErrorsMap.remove(parent)
myMap.remove(parent)
}
@@ -28,9 +28,9 @@ public class SyntheticWorker {
}
public void removeSelf() {
final String parentUrl;
final Url parentUrl;
try {
parentUrl = removePathTail(myUrl).toString();
parentUrl = removePathTail(myUrl);
}
catch (SvnBindException e) {
return;
@@ -50,16 +50,14 @@ public class SyntheticWorker {
}
public void addSyntheticChildToSelf(final Url newUrl, final Url repositoryUrl, final String name, final boolean isDir) {
final String currentUrlAsString = myUrl.toString();
final List<DirectoryEntry> children = myCache.getChildren(currentUrlAsString);
final List<DirectoryEntry> children = myCache.getChildren(myUrl);
if (children == null) {
return;
}
children.add(createSyntheticEntry(newUrl, repositoryUrl, name, isDir));
sort(children, DirectoryEntry.CASE_INSENSITIVE_ORDER);
myCache.put(currentUrlAsString, children);
myCache.put(myUrl, children);
}
public void copyTreeToSelf(final RepositoryTreeNode node) {
@@ -84,7 +82,7 @@ public class SyntheticWorker {
@Override
@NotNull
public Object fun(final RepositoryTreeNode repositoryTreeNode) {
myCache.remove(repositoryTreeNode.getURL().toString());
myCache.remove(repositoryTreeNode.getURL());
return Boolean.FALSE;
}
}
@@ -101,7 +99,7 @@ public class SyntheticWorker {
@Override
@NotNull
public Object fun(final RepositoryTreeNode repositoryTreeNode) {
final List<DirectoryEntry> children = myCache.getChildren(repositoryTreeNode.getURL().toString());
final List<DirectoryEntry> children = myCache.getChildren(repositoryTreeNode.getURL());
if (children == null) {
return Boolean.FALSE;
}
@@ -111,7 +109,7 @@ public class SyntheticWorker {
for (DirectoryEntry child : children) {
newChildren.add(createSyntheticEntry(convertUrl(child.getUrl()), child.getRepositoryRoot(), child.getName(), child.isDirectory()));
}
myCache.put(convertUrl(repositoryTreeNode.getURL()).toString(), newChildren);
myCache.put(convertUrl(repositoryTreeNode.getURL()), newChildren);
}
catch (SvnBindException ignored) {
}