X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a07937cb6f1d2a19d526e7fcb666c8e66515620d..e3a61d283fdd1a89cac30faacbba1863dd2907a7:/src/com/owncloud/android/files/services/IndexedForest.java diff --git a/src/com/owncloud/android/files/services/IndexedForest.java b/src/com/owncloud/android/files/services/IndexedForest.java index 0f737aad..c40cece3 100644 --- a/src/com/owncloud/android/files/services/IndexedForest.java +++ b/src/com/owncloud/android/files/services/IndexedForest.java @@ -21,6 +21,7 @@ import android.accounts.Account; import android.util.Pair; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.utils.Log_OC; import java.io.File; import java.util.HashSet; @@ -89,6 +90,10 @@ public class IndexedForest { public void removeChild(Node removed) { mChildren.remove(removed); } + + public void clearPayload() { + mPayload = null; + } } @@ -129,6 +134,20 @@ public class IndexedForest { return new Pair(targetKey, linkedTo); }; + + public Pair removePayload(Account account, String remotePath) { + String targetKey = buildKey(account, remotePath); + Node target = mMap.get(targetKey); + if (target != null) { + target.clearPayload(); + if (!target.hasChildren()) { + return remove(account, remotePath); + } + } + return new Pair(null, null); + } + + public /* synchronized */ Pair remove(Account account, String remotePath) { String targetKey = buildKey(account, remotePath); Node firstRemoved = mMap.remove(targetKey); @@ -155,14 +174,11 @@ public class IndexedForest { if (parent != null) { unlinkedFrom = parent.getKey().substring(account.name.length()); } - } - if (firstRemoved != null) { return new Pair(firstRemoved.getPayload(), unlinkedFrom); - } else { - return new Pair(null, unlinkedFrom); } + return new Pair(null, null); } private void removeDescendants(Node removed) { @@ -189,6 +205,26 @@ public class IndexedForest { } } + public V get(Account account, String remotePath) { + String key = buildKey(account, remotePath); + return get(key); + } + + + /** + * Remove the elements that contains account as a part of its key + * @param account + */ + public void remove(Account account){ + Iterator it = mMap.keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + Log_OC.d("IndexedForest", "Number of pending downloads= " + mMap.size()); + if (key.startsWith(account.name)) { + mMap.remove(key); + } + } + } /** * Builds a key to index files @@ -200,6 +236,4 @@ public class IndexedForest { return account.name + remotePath; } - - }