analysis: Bug 489573: Internalize Resources view implementation
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / internal / analysis / os / linux / ui / views / resources / AggregateResourcesEntry.java
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/resources/AggregateResourcesEntry.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/resources/AggregateResourcesEntry.java
new file mode 100644 (file)
index 0000000..15ef086
--- /dev/null
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.resources;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
+
+/**
+ * Internal entry of the aggregate kind, it is one without a state system value,
+ * it uses other entries and aggregates their values.
+ *
+ * @author Matthew Khouzam
+ */
+class AggregateResourcesEntry extends ResourcesEntry {
+
+    private final @NonNull List<ITimeGraphEntry> fContributors = new ArrayList<>();
+
+    private static final Comparator<ITimeEvent> COMPARATOR = new Comparator<ITimeEvent>() {
+        @Override
+        public int compare(ITimeEvent o1, ITimeEvent o2) {
+            // largest value
+            return Integer.compare(getValue(o2), getValue(o1));
+        }
+
+        private int getValue(ITimeEvent element) {
+            return (element instanceof TimeEvent) ? ((TimeEvent) element).getValue() : Integer.MIN_VALUE;
+        }
+    };
+
+    /**
+     * AggregateResourcesEntry Constructor
+     *
+     * @param trace
+     *            the parent trace
+     * @param startTime
+     *            the start time
+     * @param endTime
+     *            the end time
+     * @param type
+     *            the type
+     * @param id
+     *            the id
+     */
+    public AggregateResourcesEntry(@NonNull ITmfTrace trace,
+            long startTime, long endTime, Type type, int id) {
+        super(ITmfStateSystem.INVALID_ATTRIBUTE, trace, startTime, endTime, type, id);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param trace
+     *            The trace on which we are working
+     * @param name
+     *            The exec_name of this entry
+     * @param startTime
+     *            The start time of this entry lifetime
+     * @param endTime
+     *            The end time of this entry
+     * @param type
+     *            The type of this entry
+     * @param id
+     *            The id of this entry
+     */
+    public AggregateResourcesEntry(@NonNull ITmfTrace trace, String name, long startTime, long endTime, Type type, int id) {
+        super(ITmfStateSystem.INVALID_ATTRIBUTE, trace, name, startTime, endTime, type, id);
+    }
+
+    @Override
+    public void addEvent(ITimeEvent event) {
+    }
+
+    @Override
+    public void addZoomedEvent(ITimeEvent event) {
+    }
+
+    @Override
+    public Iterator<@NonNull ITimeEvent> getTimeEventsIterator() {
+        return new AggregateEventIterator(fContributors, COMPARATOR);
+    }
+
+    @Override
+    public Iterator<@NonNull ITimeEvent> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {
+        return new AggregateEventIterator(fContributors, startTime, stopTime, visibleDuration, COMPARATOR);
+    }
+
+    public void addContributor(ITimeGraphEntry entry) {
+        fContributors.add(entry);
+    }
+}
This page took 0.027078 seconds and 5 git commands to generate.