1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*******************************************************************************
2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Copyright (c) 2000, 2009 IBM Corporation and others.
3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * All rights reserved. This program and the accompanying materials
4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * are made available under the terms of the Eclipse Public License v1.0
5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * which accompanies this distribution, and is available at
6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * http://www.eclipse.org/legal/epl-v10.html
7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Contributors:
9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *     IBM Corporation - initial API and implementation
10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *******************************************************************************/
11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpackage org.eclipse.test.internal.performance.results.model;
12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.ArrayList;
14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.List;
15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.Vector;
16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.core.runtime.IAdaptable;
18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.core.runtime.preferences.IEclipsePreferences;
19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.core.runtime.preferences.InstanceScope;
20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.resource.ImageDescriptor;
21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.swt.graphics.Image;
22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.eval.StatisticsUtil;
23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.AbstractResults;
24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.BuildResults;
25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.ConfigResults;
26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.db.DB_Results;
27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.utils.IPerformancesConstants;
28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.utils.Util;
29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.ISharedImages;
30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.PlatformUI;
31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.model.IWorkbenchAdapter;
32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.views.properties.IPropertyDescriptor;
34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.views.properties.IPropertySource;
35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.views.properties.PropertyDescriptor;
36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.views.properties.TextPropertyDescriptor;
37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.osgi.service.prefs.BackingStoreException;
38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * An Organization Element
41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic abstract class ResultsElement implements IAdaptable, IPropertySource, IWorkbenchAdapter, Comparable {
43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Image descriptors
45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	private static final ISharedImages WORKBENCH_SHARED_IMAGES = PlatformUI.getWorkbench().getSharedImages();
46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final Image ERROR_IMAGE = WORKBENCH_SHARED_IMAGES.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final ImageDescriptor ERROR_IMAGE_DESCRIPTOR = WORKBENCH_SHARED_IMAGES.getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK);
48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final Image WARN_IMAGE = WORKBENCH_SHARED_IMAGES.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final ImageDescriptor WARN_IMAGE_DESCRIPTOR = WORKBENCH_SHARED_IMAGES.getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK);
50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final Image INFO_IMAGE = WORKBENCH_SHARED_IMAGES.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final ImageDescriptor INFO_IMAGE_DESCRIPTOR = WORKBENCH_SHARED_IMAGES.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK);
52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final Image HELP_IMAGE = WORKBENCH_SHARED_IMAGES.getImage(ISharedImages.IMG_LCL_LINKTO_HELP);
53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final ImageDescriptor HELP_IMAGE_DESCRIPTOR = WORKBENCH_SHARED_IMAGES.getImageDescriptor(ISharedImages.IMG_LCL_LINKTO_HELP);
54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final ImageDescriptor FOLDER_IMAGE_DESCRIPTOR = WORKBENCH_SHARED_IMAGES.getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final ImageDescriptor CONNECT_IMAGE_DESCRIPTOR = WORKBENCH_SHARED_IMAGES.getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED);
56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Model
58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    ResultsElement parent;
59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	AbstractResults results;
60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	ResultsElement[] children;
61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String name;
62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int status = -1;
63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Stats
65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    double[] statistics;
66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Status constants
68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// state
69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int UNKNOWN = 0x01;
70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int UNREAD = 0x02;
71402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int READ = 0x04;
72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int MISSING = 0x08;
73402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final int STATE_MASK = 0x0F;
74402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// info
75402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int SMALL_VALUE = 0x0010;
76402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int STUDENT_TTEST = 0x0020;
77402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final int INFO_MASK = 0x0030;
78402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// warning
79402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int NO_BASELINE = 0x0040;
80402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int SINGLE_RUN = 0x0080;
81402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int BIG_ERROR = 0x0100;
82402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int NOT_STABLE = 0x0200;
83402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int NOT_RELIABLE = 0x0400;
84402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final int WARNING_MASK = 0x0FC0;
85402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// error
86402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final int BIG_DELTA = 0x1000;
87402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	public static final int ERROR_MASK = 0xF000;
88402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
89402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Property descriptors
90402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_ID_STATUS_INFO = "ResultsElement.status_info"; //$NON-NLS-1$
91402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_ID_STATUS_WARNING = "ResultsElement.status_warning"; //$NON-NLS-1$
92402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_ID_STATUS_ERROR = "ResultsElement.status_error"; //$NON-NLS-1$
93402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_ID_STATUS_COMMENT = "ResultsElement.status_comment"; //$NON-NLS-1$
94402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
95402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_STR_STATUS_INFO = " info"; //$NON-NLS-1$
96402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_STR_STATUS_WARNING = "warning"; //$NON-NLS-1$
97402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_STR_STATUS_ERROR = "error"; //$NON-NLS-1$
98402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String P_STR_STATUS_COMMENT = "comment"; //$NON-NLS-1$
99402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final String[] NO_VALUES = new String[0];
100402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
101402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	private static Vector DESCRIPTORS;
102402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final TextPropertyDescriptor COMMENT_DESCRIPTOR = new TextPropertyDescriptor(P_ID_STATUS_COMMENT, P_STR_STATUS_COMMENT);
103402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static final TextPropertyDescriptor ERROR_DESCRIPTOR = new TextPropertyDescriptor(P_ID_STATUS_ERROR, P_STR_STATUS_ERROR);
104402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    static Vector initDescriptors(int status) {
105402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		DESCRIPTORS = new Vector();
106402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// Status category
107402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		DESCRIPTORS.add(getInfosDescriptor(status));
108402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		DESCRIPTORS.add(getWarningsDescriptor(status));
109402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		DESCRIPTORS.add(ERROR_DESCRIPTOR);
110402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ERROR_DESCRIPTOR.setCategory("Status");
111402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// Survey category
112402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		DESCRIPTORS.add(COMMENT_DESCRIPTOR);
113402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		COMMENT_DESCRIPTOR.setCategory("Survey");
114402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return DESCRIPTORS;
115402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
116402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    static Vector getDescriptors() {
117402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    	return DESCRIPTORS;
118402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
119402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    static ComboBoxPropertyDescriptor getInfosDescriptor(int status) {
120402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		List list = new ArrayList();
121402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & SMALL_VALUE) != 0) {
122402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have tests with small values");
123402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
124402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & STUDENT_TTEST) != 0) {
125402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have student-t test error over the threshold");
126402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
127402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String[] infos = new String[list.size()];
128402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (list.size() > 0) {
129402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.toArray(infos);
130402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
131402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ComboBoxPropertyDescriptor infoDescriptor = new ComboBoxPropertyDescriptor(P_ID_STATUS_INFO, P_STR_STATUS_INFO, infos);
132402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		infoDescriptor.setCategory("Status");
133402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return infoDescriptor;
134402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
135402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    static PropertyDescriptor getWarningsDescriptor(int status) {
136402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		List list = new ArrayList();
137402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & BIG_ERROR) != 0) {
138402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have tests with error over 3%");
139402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
140402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & NOT_RELIABLE) != 0) {
141402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have no reliable tests");
142402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
143402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & NOT_STABLE) != 0) {
144402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have no stable tests");
145402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
146402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & NO_BASELINE) != 0) {
147402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have no baseline to compare with");
148402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
149402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((status & SINGLE_RUN) != 0) {
150402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.add("Some builds have single run tests");
151402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
152402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String[] warnings = new String[list.size()];
153402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (list.size() > 0) {
154402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			list.toArray(warnings);
155402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
156402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ComboBoxPropertyDescriptor warningDescriptor = new ComboBoxPropertyDescriptor(P_ID_STATUS_WARNING, P_STR_STATUS_WARNING, warnings);
157402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		warningDescriptor.setCategory("Status");
158402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return warningDescriptor;
159402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
160402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
161402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollResultsElement() {
162402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
163402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
164402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollResultsElement(AbstractResults results, ResultsElement parent) {
165402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    this.parent = parent;
166402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    this.results = results;
167402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
168402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
169402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollResultsElement(String name, ResultsElement parent) {
170402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.parent = parent;
171402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.name = name;
172402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
173402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
174402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic int compareTo(Object o) {
175402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results == null) {
176402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (o instanceof ResultsElement && this.name != null) {
177402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			ResultsElement element = (ResultsElement) o;
178402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return this.name.compareTo(element.getName());
179402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
180402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return -1;
181402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
182402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (o instanceof ResultsElement) {
183402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return this.results.compareTo(((ResultsElement)o).results);
184402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
185402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return -1;
186402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
187402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
188402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollabstract ResultsElement createChild(AbstractResults testResults);
189402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
190402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
191402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IAdaptable
192402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
193402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic Object getAdapter(Class adapter) {
194402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    if (adapter == IPropertySource.class) {
195402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll        return this;
196402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    }
197402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    if (adapter == IWorkbenchAdapter.class) {
198402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll        return this;
199402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    }
200402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return null;
201402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
202402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
203402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
204402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Iterate the element children.
205402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
206402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic ResultsElement[] getChildren() {
207402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results == null) {
208402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return new ResultsElement[0];
209402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
210402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.children == null) {
211402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		initChildren();
212402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
213402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return this.children;
214402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
215402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
216402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
217402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IWorkbenchAdapter
218402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
219402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic Object[] getChildren(Object o) {
220402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results == null) {
221402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return new Object[0];
222402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
223402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.children == null) {
224402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		initChildren();
225402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
226402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return this.children;
227402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
228402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
229402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
230402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IPropertySource
231402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
232402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic Object getEditableValue() {
233402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return this;
234402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
235402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
236402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollfinal String getId() {
237402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return getId(new StringBuffer()).toString();
238402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
239402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
240402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate StringBuffer getId(StringBuffer buffer) {
241402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.parent != null) {
242402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return this.parent.getId(buffer).append('/').append(getName());
243402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
244402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return buffer.append(DB_Results.getDbName());
245402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
246402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
247402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
248402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IWorkbenchAdapter
249402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
250402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic ImageDescriptor getImageDescriptor(Object object) {
251402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (object instanceof ResultsElement) {
252402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ResultsElement resultsElement = (ResultsElement) object;
253402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// DEBUG
254402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		if (resultsElement.getName().equals("I20090806-0100")) {
255402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			if (resultsElement.results != null) {
256402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				String toString = resultsElement.results.getParent().toString();
257402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				String toString = resultsElement.results.toString();
258402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				if (toString.indexOf("testStoreExists")>0 && toString.indexOf("eplnx2")>0) {
259402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//					System.out.println("stop");
260402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				}
261402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//			}
262402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//		}
263402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		int elementStatus = resultsElement.getStatus();
264402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (elementStatus == MISSING) {
265402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return HELP_IMAGE_DESCRIPTOR;
266402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
267402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((elementStatus & ResultsElement.ERROR_MASK) != 0) {
268402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return ERROR_IMAGE_DESCRIPTOR;
269402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
270402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((elementStatus & ResultsElement.WARNING_MASK) != 0) {
271402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return WARN_IMAGE_DESCRIPTOR;
272402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
273402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((elementStatus & ResultsElement.INFO_MASK) != 0) {
274402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return INFO_IMAGE_DESCRIPTOR;
275402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
276402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
277402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return null;
278402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
279402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
280402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
281402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IWorkbenchAdapter
282402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
283402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String getLabel(Object o) {
284402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return getName();
285402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
286402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
287402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
288402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the name
289402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
290402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String getName() {
291402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.name == null && this.results != null) {
292402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.name = this.results.getName();
293402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
294402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.name;
295402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
296402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
297402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
298402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the parent
299402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
300402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic Object getParent(Object o) {
301402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return this.parent;
302402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
303402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
304402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
305402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
306402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
307402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic IPropertyDescriptor[] getPropertyDescriptors() {
308402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Vector descriptors = getDescriptors();
309402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (descriptors == null) {
310402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		descriptors = initDescriptors(getStatus());
311402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
312402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int size = descriptors.size();
313402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	IPropertyDescriptor[] descriptorsArray = new IPropertyDescriptor[size];
314402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	descriptorsArray[0] = getInfosDescriptor(getStatus());
315402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	descriptorsArray[1] = getWarningsDescriptor(getStatus());
316402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=2; i<size; i++) {
317402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		descriptorsArray[i] = (IPropertyDescriptor) descriptors.get(i);
318402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
319402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return descriptorsArray;
320402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
321402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
322402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
323402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
324402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
325402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic Object getPropertyValue(Object propKey) {
326402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propKey.equals(P_ID_STATUS_INFO)) {
327402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((getStatus() & INFO_MASK) != 0) {
328402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return new Integer(0);
329402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
330402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
331402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propKey.equals(P_ID_STATUS_WARNING)) {
332402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((getStatus() & WARNING_MASK) != 0) {
333402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return new Integer(0);
334402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
335402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
336402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propKey.equals(P_ID_STATUS_ERROR)) {
337402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((getStatus() & BIG_DELTA) != 0) {
338402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return "Some builds have tests with regression";
339402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
340402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
341402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propKey.equals(P_ID_STATUS_COMMENT)) {
342402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		IEclipsePreferences preferences = new InstanceScope().getNode(IPerformancesConstants.PLUGIN_ID);
343402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return preferences.get(getId(), "");
344402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
345402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return null;
346402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
347402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
348402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic ResultsElement getResultsElement(String resultName) {
349402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = getChildren(null).length;
350402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
351402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ResultsElement searchedResults = this.children[i];
352402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (searchedResults.getName().equals(resultName)) {
353402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return searchedResults;
354402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
355402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
356402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return null;
357402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
358402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
359402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
360402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the status of the element.
361402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
362402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * The status is a bit mask pattern where digits are
363402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * allowed as follow:
364402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	<ul>
365402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		<li>0-3: bits for state showing whether the element is
366402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			<ul>
367402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #UNKNOWN} : not connected to a db</li>
368402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #UNREAD} : is not valid (e.g. NaN results)</li>
369402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #MISSING} : no results (e.g. the perf machine crashed and didn't store any results)</li>
370402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #READ} : has valid results</li>
371402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			</ul>
372402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		</li>
373402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		<li>4-5: bits for information. Current possible information are
374402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			<ul>
375402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #SMALL_VALUE} : build results or delta with baseline value is under 100ms</li>
376402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #STUDENT_TTEST} : the Student T-test is over the threshold (old yellow color for test results)</li>
377402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			</ul>
378402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		</li>
379402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		<li>6-11: bits for warnings. Current possible warnings are
380402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			<ul>
381402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #NO_BASELINE} : no baseline for the current build</li>
382402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #SINGLE_RUN} : the test has only one run (i.e. no error could be computed), hence its reliability cannot be evaluated</li>
383402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #BIG_ERROR} : the test result is over the 3% threshold</li>
384402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #NOT_STABLE} : the test history shows a deviation between 10% and 20% (may mean that this test is not so reliable)</li>
385402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #NOT_RELIABLE} : the test history shows a deviation over 20% (surely means that this test is too erratic to be reliable)</li>
386402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			</ul>
387402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		</li>
388402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		<li>12-15: bits for errors. Current possible errors are
389402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			<ul>
390402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 				<li>{@link #BIG_DELTA} : the delta for the test is over the 10% threshold</li>
391402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 			</ul>
392402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 		</li>
393402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	</ul>
394402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
395402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Note that these explanation applied to {@link BuildResultsElement}, and {@link DimResultsElement}.
396402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * For {@link ComponentResultsElement}, and {@link ScenarioResultsElement}, it's the merge of all the children status
397402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * and means "Some tests have..." instead of "The test has...". For {@link ConfigResultsElement}, it means the status
398402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * of the most recent build compared to its most recent baseline.
399402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
400402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return An int with each bit set when the corresponding symptom applies.
401402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
402402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic final int getStatus() {
403402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.status < 0) {
404402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		initStatus();
405402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
406402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.status;
407402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
408402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
409402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
410402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the statistics of the build along its history.
411402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
412402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return An array of double built as follows:
413402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <ul>
414402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <li>0:	numbers of values</li>
415402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <li>1:	mean of values</li>
416402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <li>2:	standard deviation of these values</li>
417402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <li>3:	coefficient of variation of these values</li>
418402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * </ul>
419402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
420402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Molldouble[] getStatistics() {
421402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.statistics;
422402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
423402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
424402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
425402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns whether the element (or one in its hierarchy) has an error.
426402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
427402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return <code> true</code> if the element or one in its hierarchy has an error,
428402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	<code> false</code>  otherwise
429402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
430402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic final boolean hasError() {
431402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return (getStatus() & ERROR_MASK) != 0;
432402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
433402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
434402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid initChildren() {
435402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	AbstractResults[] resultsChildren = this.results.getChildren();
436402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = resultsChildren.length;
437402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.children = new ResultsElement[length];
438402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int count = 0;
439402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
440402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ResultsElement childElement = createChild(resultsChildren[i]);
441402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (childElement != null) {
442402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.children[count++] = childElement;
443402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
444402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
445402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (count < length) {
446402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		System.arraycopy(this.children, 0, this.children = new ResultsElement[count], 0, count);
447402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
448402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
449402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid initStatus() {
450402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.status = READ;
451402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results != null) {
452402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.children == null) initChildren();
453402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		int length = this.children.length;
454402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		for (int i=0; i<length; i++) {
455402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.status |= this.children[i].getStatus();
456402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
457402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
458402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
459402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
460402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollint initStatus(BuildResults buildResults) {
461402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.status = READ;
462402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
463402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Get values
464402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double buildValue = buildResults.getValue();
465402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	ConfigResults configResults = (ConfigResults) buildResults.getParent();
466402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	BuildResults baselineResults = configResults.getBaselineBuildResults(buildResults.getName());
467402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double baselineValue = baselineResults.getValue();
468402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double delta = (baselineValue - buildValue) / baselineValue;
469402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
470402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Store if there's no baseline
471402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (Double.isNaN(delta)) {
472402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.status |= NO_BASELINE;
473402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
474402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
475402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Store if there's only one run
476402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long baselineCount = baselineResults.getCount();
477402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long currentCount = buildResults.getCount();
478402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double error = Double.NaN;
479402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (baselineCount == 1 || currentCount == 1) {
480402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.status |= SINGLE_RUN;
481402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
482402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
483402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Store if the T-test is not good
484402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double ttestValue = Util.computeTTest(baselineResults, buildResults);
485402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int degreeOfFreedom = (int) (baselineResults.getCount()+buildResults.getCount()-2);
486402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (ttestValue >= 0 && StatisticsUtil.getStudentsT(degreeOfFreedom, StatisticsUtil.T90) >= ttestValue) {
487402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.status |= STUDENT_TTEST;
488402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
489402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
490402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Store if there's a big error (over 3%)
491402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double baselineError = baselineResults.getError();
492402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double currentError = buildResults.getError();
493402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	error = Double.isNaN(baselineError)
494402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			? currentError / baselineValue
495402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			: Math.sqrt(baselineError*baselineError + currentError*currentError) / baselineValue;
496402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (error > 0.03) {
497402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.status |= BIG_ERROR;
498402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
499402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
500402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Store if there's a big delta (over 10%)
501402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (delta <= -0.1) {
502402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.status |= BIG_DELTA;
503402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		double currentBuildValue = buildResults.getValue();
504402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		double diff = Math.abs(baselineValue - currentBuildValue);
505402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (currentBuildValue < 100 || diff < 100) { // moderate the status when
506402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// diff is less than 100ms
507402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.status |= SMALL_VALUE;
508402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} else {
509402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			double[] stats = getStatistics();
510402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (stats != null) {
511402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (stats[3] > 0.2) { // invalidate the status when the test
512402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					// historical deviation is over 20%
513402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.status |= NOT_RELIABLE;
514402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				} else if (stats[3] > 0.1) { // moderate the status when the test
515402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					// historical deviation is between 10%
516402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					// and 20%
517402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.status |= NOT_STABLE;
518402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
519402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
520402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
521402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
522402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
523402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.status;
524402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
525402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
526402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic boolean isInitialized() {
527402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.results != null;
528402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
529402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
530402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
531402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IPropertySource
532402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
533402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic boolean isPropertySet(Object property) {
534402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return false;
535402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
536402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
537402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollboolean onlyFingerprints() {
538402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.parent != null) {
539402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return this.parent.onlyFingerprints();
540402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
541402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return ((PerformanceResultsElement)this).fingerprints;
542402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
543402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
544402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
545402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Method declared on IPropertySource
546402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
547402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void resetPropertyValue(Object property) {
548402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
549402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
550402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid resetStatus() {
551402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.status = -1;
552402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results != null) {
553402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.children == null) initChildren();
554402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		int length = this.children.length;
555402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		for (int i=0; i<length; i++) {
556402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.children[i].resetStatus();
557402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
558402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
559402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
560402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
561402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void setPropertyValue(Object name, Object value) {
562402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (name.equals(P_ID_STATUS_COMMENT)) {
563402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		IEclipsePreferences preferences = new InstanceScope().getNode(IPerformancesConstants.PLUGIN_ID);
564402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		preferences.put(getId(), (String) value);
565402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		try {
566402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			preferences.flush();
567402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} catch (BackingStoreException e) {
568402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// skip
569402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
570402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
571402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
572402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
573402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
574402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Sets the image descriptor
575402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
576402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid setImageDescriptor(ImageDescriptor desc) {
577402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//    this.imageDescriptor = desc;
578402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
579402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
580402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String toString() {
581402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results == null) {
582402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return getName();
583402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
584402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.results.toString();
585402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
586402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
587402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
588402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Write the element status in the given stream
589402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
590402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollStringBuffer writableStatus(StringBuffer buffer, int kind, StringBuffer excluded) {
591402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = this.children.length;
592402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
593402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.children[i].writableStatus(buffer, kind, excluded);
594402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
595402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return buffer;
596402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
597402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
598402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
599402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
600