package org.eclipse.tracecompass.segmentstore.core.treemap;
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
+import java.util.Collection;
import java.util.Iterator;
import java.util.TreeMap;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
-import org.eclipse.tracecompass.segmentstore.core.SegmentComparators;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.Sets;
-import com.google.common.collect.TreeMultimap;
+import org.eclipse.tracecompass.segmentstore.core.SegmentStoreFactory;
/**
* Implementation of a {@link ISegmentStore} using in-memory {@link TreeMap}'s.
* that if you want several segments with the same start and end times, make
* sure their compareTo() differentiates them.
*
- * @param <T>
+ * Removal operations are not supported.
+ *
+ * @param <E>
* The type of segment held in this store
*
* @author Alexandre Montplaisir
+ * @deprecated Use the {@link SegmentStoreFactory} to create a new segment store
*/
-public class TreeMapStore<T extends ISegment> implements ISegmentStore<T> {
-
- private final ReadWriteLock fLock = new ReentrantReadWriteLock(false);
-
- private final TreeMultimap<Long, T> fStartTimesIndex;
- private final TreeMultimap<Long, T> fEndTimesIndex;
-
- private long fSize;
+@Deprecated
+public class TreeMapStore<@NonNull E extends ISegment> extends org.eclipse.tracecompass.internal.segmentstore.core.treemap.TreeMapStore<E> {
/**
* Constructor
*/
public TreeMapStore() {
- /*
- * For the start times index, the "key comparator" will compare the
- * start times as longs directly. This is the primary comparator for its
- * tree map.
- *
- * The secondary "value" comparator will check the end times first, and
- * in the event of a tie, defer to the ISegment's Comparable
- * implementation, a.k.a. its natural ordering.
- *
- * The same is done for the end times index, but swapping the first two
- * comparators instead.
- */
- fStartTimesIndex = checkNotNull(TreeMultimap.<Long, T> create(
- SegmentComparators.LONG_COMPARATOR,
- Ordering.from(SegmentComparators.INTERVAL_END_COMPARATOR).compound(Ordering.natural())));
-
- fEndTimesIndex = checkNotNull(TreeMultimap.<Long, T> create(
- SegmentComparators.LONG_COMPARATOR,
- Ordering.from(SegmentComparators.INTERVAL_START_COMPARATOR).compound(Ordering.natural())));
-
- fSize = 0;
+ super();
+ }
+
+ // ------------------------------------------------------------------------
+ // Methods from Collection
+ // ------------------------------------------------------------------------
+
+ @Override
+ public Iterator<E> iterator() {
+ return super.iterator();
+ }
+
+ @Override
+ public boolean add(@Nullable E val) {
+ return super.add(val);
+ }
+
+ @Override
+ public int size() {
+ return super.size(); // me
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return super.isEmpty();
+ }
+
+ @Override
+ public boolean contains(@Nullable Object o) {
+ return super.contains(o);
+ }
+
+ @Override
+ public boolean containsAll(@Nullable Collection<?> c) {
+ return super.containsAll(c);
+ }
+
+ @Override
+ public Object[] toArray() {
+ return super.toArray();
}
- /**
- * Warning, this is not thread safe, and can cause concurrent modification
- * exceptions
- */
@Override
- public Iterator<T> iterator() {
- return checkNotNull(fStartTimesIndex.values().iterator());
+ public <T> T[] toArray(T[] a) {
+ return super.toArray(a);
}
@Override
- public void addElement(T val) {
- fLock.writeLock().lock();
- try {
- if (fStartTimesIndex.put(Long.valueOf(val.getStart()), val)) {
- fEndTimesIndex.put(Long.valueOf(val.getEnd()), val);
- fSize++;
- }
- } finally {
- fLock.writeLock().unlock();
- }
+ public boolean remove(@Nullable Object o) {
+ return super.remove(o);
}
@Override
- public long getNbElements() {
- fLock.readLock().lock();
- try {
- return fSize;
- } finally {
- fLock.readLock().unlock();
- }
+ public boolean addAll(@Nullable Collection<? extends E> c) {
+ return super.addAll(c);
}
@Override
- public Iterable<T> getIntersectingElements(long position) {
- /*
- * The intervals intersecting 't' are those whose 1) start time is
- * *lower* than 't' AND 2) end time is *higher* than 't'.
- */
- fLock.readLock().lock();
- try {
- Iterable<T> matchStarts = Iterables.concat(fStartTimesIndex.asMap().headMap(position, true).values());
- Iterable<T> matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(position, true).values());
- return checkNotNull(Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds)));
- } finally {
- fLock.readLock().unlock();
- }
+ public boolean removeAll(@Nullable Collection<?> c) {
+ return super.removeAll(c);
+ }
+
+ @Override
+ public boolean retainAll(@Nullable Collection<?> c) {
+ return super.retainAll(c);
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ }
+
+ // ------------------------------------------------------------------------
+ // Methods added by ISegmentStore
+ // ------------------------------------------------------------------------
+
+ @Override
+ public Iterable<E> getIntersectingElements(long position) {
+ return super.getIntersectingElements(position);
}
@Override
- public Iterable<T> getIntersectingElements(long start, long end) {
- fLock.readLock().lock();
- try {
- Iterable<T> matchStarts = Iterables.concat(fStartTimesIndex.asMap().headMap(end, true).values());
- Iterable<T> matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(start, true).values());
- return checkNotNull(Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds)));
- } finally {
- fLock.readLock().unlock();
- }
+ public Iterable<E> getIntersectingElements(long start, long end) {
+ return super.getIntersectingElements(start, end);
}
@Override
public void dispose() {
- fLock.writeLock().lock();
- try {
- fStartTimesIndex.clear();
- fEndTimesIndex.clear();
- fSize = 0;
- } finally {
- fLock.writeLock().unlock();
- }
+ super.dispose();
}
}