segstore: remove redundancies in deprecated class
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.segmentstore.core / src / org / eclipse / tracecompass / segmentstore / core / treemap / TreeMapStore.java
index a013aa960b2f3371504c4e3cea68bfd2c25f480d..e8014ad2928779acf18692fc4500f37fde0237d1 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
 
 package org.eclipse.tracecompass.segmentstore.core.treemap;
 
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.Comparator;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.TreeMap;
 
+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 com.google.common.collect.Iterables;
-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.
  * This relatively simple implementation holds everything in memory, and as such
  * cannot contain too much data.
  *
- * @param <T>
- *            The time of time range held
+ * The TreeMapStore itself is Iterable, and its iteration order will be by
+ * ascending order of start times. For segments with identical start times, the
+ * secondary comparator will be the end time. If even those are equal, it will
+ * defer to the segments' natural ordering ({@link ISegment#compareTo}).
+ *
+ * The store's tree maps will not accept duplicate key-value pairs, which means
+ * that if you want several segments with the same start and end times, make
+ * sure their compareTo() differentiates them.
+ *
+ * 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 TreeMultimap<Long, T> fStartTimesIndex;
-    private final TreeMultimap<Long, T> fEndTimesIndex;
-
-    private final Map<Long, T> fPositionMap;
-
-    private volatile long fSize;
+@Deprecated
+public class TreeMapStore<@NonNull E extends ISegment> extends org.eclipse.tracecompass.internal.segmentstore.core.treemap.TreeMapStore<E> {
 
     /**
-     *Constructor
+     * Constructor
      */
     public TreeMapStore() {
-        fStartTimesIndex = checkNotNull(TreeMultimap.<Long, T> create(LONG_COMPARATOR, INTERVAL_START_COMPARATOR));
-        fEndTimesIndex = checkNotNull(TreeMultimap.<Long, T> create(LONG_COMPARATOR, INTERVAL_END_COMPARATOR));
-        fPositionMap = new HashMap<>();
-        fSize = 0;
+        super();
     }
 
+    // ------------------------------------------------------------------------
+    // Methods from Collection
+    // ------------------------------------------------------------------------
+
     @Override
-    public Iterator<T> iterator() {
-        return checkNotNull(fStartTimesIndex.values().iterator());
+    public Iterator<E> iterator() {
+        return super.iterator();
     }
 
     @Override
-    public synchronized void addElement(T val) {
-        fStartTimesIndex.put(Long.valueOf(val.getStart()), val);
-        fEndTimesIndex.put(Long.valueOf(val.getEnd()), val);
-        fPositionMap.put(fSize, val);
-        fSize++;
+    public boolean add(@Nullable E val) {
+        return super.add(val);
     }
 
     @Override
-    public long getNbElements() {
-        return fSize;
+    public int size() {
+        return super.size(); // me
     }
 
     @Override
-    public T getElementAtIndex(long index) {
-        return checkNotNull(fPositionMap.get(Long.valueOf(index)));
+    public boolean isEmpty() {
+        return super.isEmpty();
     }
 
     @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'.
-         */
-        Iterable<T> matchStarts = Iterables.concat(fStartTimesIndex.asMap().headMap(position, true).values());
-        Iterable<T> matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(position, true).values());
+    public boolean contains(@Nullable Object o) {
+        return super.contains(o);
+    }
 
-        return checkNotNull(Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds)));
+    @Override
+    public boolean containsAll(@Nullable Collection<?> c) {
+        return super.containsAll(c);
     }
 
     @Override
-    public Iterable<T> getIntersectingElements(long start, long end) {
-        Iterable<T> matchStarts = Iterables.concat(fStartTimesIndex.asMap().headMap(end, true).values());
-        Iterable<T> matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(start, true).values());
+    public Object[] toArray() {
+        return super.toArray();
+    }
 
-        return checkNotNull(Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds)));
+    @Override
+    public <T> T[] toArray(T[] a) {
+        return super.toArray(a);
     }
 
     @Override
-    public synchronized void dispose() {
-        fStartTimesIndex.clear();
-        fEndTimesIndex.clear();
-        fPositionMap.clear();
-        fSize = 0;
+    public boolean remove(@Nullable Object o) {
+        return super.remove(o);
+    }
+
+    @Override
+    public boolean addAll(@Nullable Collection<? extends E> c) {
+        return super.addAll(c);
+    }
+
+    @Override
+    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();
     }
 
     // ------------------------------------------------------------------------
-    // Comparators, used for the tree maps
+    // Methods added by ISegmentStore
     // ------------------------------------------------------------------------
 
-    private static final Comparator<Long> LONG_COMPARATOR = new Comparator<Long>() {
-        @Override
-        public int compare(@Nullable Long o1, @Nullable Long o2) {
-            if (o1 == null || o2 == null) {
-                throw new IllegalArgumentException();
-            }
-            return o1.compareTo(o2);
-        }
-    };
-
-    private static final Comparator<ISegment> INTERVAL_START_COMPARATOR = new Comparator<ISegment>() {
-        @Override
-        public int compare(@Nullable ISegment o1, @Nullable ISegment o2) {
-            if (o1 == null || o2 == null) {
-                throw new IllegalArgumentException();
-            }
-            return Long.compare(o1.getStart(), o2.getStart());
-        }
-    };
-
-    private static final Comparator<ISegment> INTERVAL_END_COMPARATOR = new Comparator<ISegment>() {
-        @Override
-        public int compare(@Nullable ISegment o1, @Nullable ISegment o2) {
-            if (o1 == null || o2 == null) {
-                throw new IllegalArgumentException();
-            }
-            return Long.compare(o1.getEnd(), o2.getEnd());
-        }
-    };
+    @Override
+    public Iterable<E> getIntersectingElements(long position) {
+        return super.getIntersectingElements(position);
+    }
 
+    @Override
+    public Iterable<E> getIntersectingElements(long start, long end) {
+        return super.getIntersectingElements(start, end);
+    }
 
+    @Override
+    public void dispose() {
+        super.dispose();
+    }
 }
This page took 0.039613 seconds and 5 git commands to generate.