import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
import org.eclipse.tracecompass.internal.analysis.timing.core.store.ArrayListStore;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
/* Attempt to read the existing file */
try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file))) {
Object[] segmentArray = readObject(ois);
- final ISegmentStore<ISegment> store = new ArrayListStore<>();
- for (Object element : segmentArray) {
- if (element instanceof ISegment) {
- ISegment segment = (ISegment) element;
- store.add(segment);
- }
- }
+ ISegmentStore<ISegment> store = new ArrayListStore<>(NonNullUtils.checkNotNullContents(segmentArray));
fSegmentStore = store;
sendUpdate(store);
return true;
private final ReadWriteLock fLock = new ReentrantReadWriteLock(false);
- private final List<E> fStore = new ArrayList<>();
+ private final List<E> fStore;
private @Nullable transient Iterable<E> fLastSnapshot = null;
* Constructor
*/
public ArrayListStore() {
- /*
- * 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.
- *
- * The same is done for the end times index, but swapping the first two
- * comparators instead.
- */
+ fStore = new ArrayList<>();
}
+ /**
+ * Constructor
+ *
+ * @param array
+ * an array of elements to wrap in the segment store
+ *
+ */
+ public ArrayListStore(Object[] array) {
+ fStore = new ArrayList<>();
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] instanceof ISegment) {
+ fStore.add((E) array[i]);
+ }
+ }
+ fStore.sort(COMPARATOR);
+ }
// ------------------------------------------------------------------------
// Methods from Collection
// ------------------------------------------------------------------------