Merge branch '556-thread-safety-blocking-issues' into 'master'

Forum controller thread safety and tree safety

This branch solves the concurrent forum issues by code restructure and refactoring.

Closes #556 
Closes #552 

See merge request !262
This commit is contained in:
akwizgran
2016-09-29 09:30:51 +00:00
14 changed files with 812 additions and 819 deletions

View File

@@ -0,0 +1,51 @@
package org.briarproject.android.util;
import android.support.annotation.UiThread;
import org.briarproject.api.clients.MessageTree;
import org.briarproject.clients.MessageTreeImpl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@UiThread
public class NestedTreeList<T extends MessageTree.MessageNode>
implements Iterable<T> {
private final MessageTree<T> tree = new MessageTreeImpl<>();
private List<T> depthFirstCollection = new ArrayList<>();
public void addAll(Collection<T> collection) {
tree.add(collection);
depthFirstCollection = new ArrayList<>(tree.depthFirstOrder());
}
public void add(T elem) {
tree.add(elem);
depthFirstCollection = new ArrayList<>(tree.depthFirstOrder());
}
public void clear() {
tree.clear();
depthFirstCollection.clear();
}
public T get(int index) {
return depthFirstCollection.get(index);
}
public int indexOf(T elem) {
return depthFirstCollection.indexOf(elem);
}
public int size() {
return depthFirstCollection.size();
}
@Override
public Iterator<T> iterator() {
return depthFirstCollection.iterator();
}
}