-/* ownCloud Android client application
+/**
+ * ownCloud Android client application
+ *
+ * @author David A. Velasco
* Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
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;
* A map provides the indexation based in hashing.
*
* A tree is created per account.
- *
- * @author David A. Velasco
*/
public class IndexedForest<V> {
public void removeChild(Node<V> removed) {
mChildren.remove(removed);
}
+
+ public void clearPayload() {
+ mPayload = null;
+ }
}
return new Pair<String, String>(targetKey, linkedTo);
};
+
+ public Pair<V, String> removePayload(Account account, String remotePath) {
+ String targetKey = buildKey(account, remotePath);
+ Node<V> target = mMap.get(targetKey);
+ if (target != null) {
+ target.clearPayload();
+ if (!target.hasChildren()) {
+ return remove(account, remotePath);
+ }
+ }
+ return new Pair<V, String>(null, null);
+ }
+
+
public /* synchronized */ Pair<V, String> remove(Account account, String remotePath) {
String targetKey = buildKey(account, remotePath);
Node<V> firstRemoved = mMap.remove(targetKey);
if (parent != null) {
unlinkedFrom = parent.getKey().substring(account.name.length());
}
- }
- if (firstRemoved != null) {
return new Pair<V, String>(firstRemoved.getPayload(), unlinkedFrom);
- } else {
- return new Pair<V, String>(null, unlinkedFrom);
}
+ return new Pair<V, String>(null, null);
}
private void removeDescendants(Node<V> removed) {
}
}
+ 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<String> 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
return account.name + remotePath;
}
-
-
}