sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/engine/ResultsBase.java
changeset 1 1050670c6980
child 6 f65f740e69f9
equal deleted inserted replaced
0:5ad7ad99af01 1:1050670c6980
       
     1 /*
       
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Definitions for the class ResultsBase
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.engine;
       
    19 
       
    20 import java.util.AbstractList;
       
    21 import java.util.ArrayList;
       
    22 import java.util.Hashtable;
       
    23 import java.util.Iterator;
       
    24 
       
    25 /**
       
    26  * Base class for {@link ProjectResults} and {@link RunResults} Provides
       
    27  * functionality to store basic information of one results item.
       
    28  *
       
    29  * Information is parsed from atool.exe generated XML file so we can assume that
       
    30  * all the information is valid and no other checking is needed.
       
    31  *
       
    32  * @author kihe
       
    33  *
       
    34  */
       
    35 public class ResultsBase {
       
    36 
       
    37 	/** Run id. */
       
    38 	private final int itemID;
       
    39 
       
    40 	/** Run end time. */
       
    41 	private String endTime;
       
    42 
       
    43 	/** Run start time. */
       
    44 	private String startTime;
       
    45 
       
    46 	/** Contains information of current run memory leak count for modules. */
       
    47 	private final Hashtable<String, Integer> moduleLeaks;
       
    48 
       
    49 	/** Contains information of current run handle leak count for modules. */
       
    50 	private final Hashtable<String, Integer> handleLeaks;
       
    51 
       
    52 	/** Run process name. */
       
    53 	private String processName;
       
    54 
       
    55 	/** Run build target. */
       
    56 	private String buildTarget;
       
    57 
       
    58 	/** Run Analysis items. */
       
    59 	private final AbstractList<AnalysisItem> analysisItems;
       
    60 
       
    61 	/**
       
    62 	 * Constructor.
       
    63 	 *
       
    64 	 * @param id
       
    65 	 *            Results id number
       
    66 	 */
       
    67 	public ResultsBase(final int id) {
       
    68 		itemID = id;
       
    69 		this.moduleLeaks = new Hashtable<String, Integer>();
       
    70 		this.handleLeaks = new Hashtable<String, Integer>();
       
    71 		analysisItems = new ArrayList<AnalysisItem>();
       
    72 	}
       
    73 
       
    74 	/**
       
    75 	 * Adds one item to the existing list.
       
    76 	 *
       
    77 	 * @param item
       
    78 	 *            Analysis item
       
    79 	 */
       
    80 	public final void addAnalysisItem(final AnalysisItem item) {
       
    81 		analysisItems.add(item);
       
    82 	}
       
    83 
       
    84 	/**
       
    85 	 * Adds module handle leak information.
       
    86 	 *
       
    87 	 * @param name
       
    88 	 *            Module name
       
    89 	 * @param count
       
    90 	 *            Number of handle leaks
       
    91 	 */
       
    92 	public final void addHandleLeak(final String name, final int count) {
       
    93 		handleLeaks.put(name, count);
       
    94 	}
       
    95 
       
    96 	/**
       
    97 	 * Adds module memory leak information.
       
    98 	 *
       
    99 	 * @param name
       
   100 	 *            Module name
       
   101 	 * @param count
       
   102 	 *            Number of module leaks
       
   103 	 */
       
   104 	public final void addModuleLeak(final String name, final int count) {
       
   105 		moduleLeaks.put(name, count);
       
   106 	}
       
   107 
       
   108 	/**
       
   109 	 * Gets run Analysis items.
       
   110 	 *
       
   111 	 * @return Run Analysis items
       
   112 	 */
       
   113 	public final AbstractList<AnalysisItem> getAnalysisItems() {
       
   114 		return analysisItems;
       
   115 	}
       
   116 
       
   117 	/**
       
   118 	 * Gets current run build target.
       
   119 	 *
       
   120 	 * @return Build target
       
   121 	 */
       
   122 	public final String getBuildTarget() {
       
   123 		if( buildTarget == null) {
       
   124 			return "";
       
   125 		}
       
   126 		return buildTarget;
       
   127 	}
       
   128 
       
   129 	/**
       
   130 	 * Gets the end time of current analysis run.
       
   131 	 *
       
   132 	 * @return End time
       
   133 	 */
       
   134 	public final String getEndTime() {
       
   135 		if(endTime == null) {
       
   136 			return "";
       
   137 		}
       
   138 		return this.endTime;
       
   139 	}
       
   140 
       
   141 	/**
       
   142 	 * Gets handle leak count.
       
   143 	 *
       
   144 	 * @return Handle leak count
       
   145 	 */
       
   146 	public final int getHandleLeakCount() {
       
   147 		int count = 0;
       
   148 		if (handleLeaks != null) {
       
   149 			for (java.util.Enumeration<String> e = handleLeaks.keys(); e
       
   150 					.hasMoreElements();) {
       
   151 				String handleLeakName = e.nextElement();
       
   152 				count = count + handleLeaks.get(handleLeakName);
       
   153 			}
       
   154 		}
       
   155 		return count;
       
   156 
       
   157 	}
       
   158 
       
   159 	/**
       
   160 	 * Gets current run module handle leak information.
       
   161 	 *
       
   162 	 * @return Hashtable<String, Integer> Module handle leak information
       
   163 	 */
       
   164 	public final Hashtable<String, Integer> getHandleLeaks() {
       
   165 		return handleLeaks;
       
   166 	}
       
   167 
       
   168 	/**
       
   169 	 * Gets one Analysis item by given id number.
       
   170 	 *
       
   171 	 * @param givenID
       
   172 	 *            Analysis item id
       
   173 	 * @return Analysis item if found otherwise null
       
   174 	 */
       
   175 	public final AnalysisItem getItemByID(final int givenID) {
       
   176 
       
   177 		// get analysis items
       
   178 		Iterator<AnalysisItem> itemIter = this.analysisItems.iterator();
       
   179 		while (itemIter.hasNext()) {
       
   180 			// get one analysis item
       
   181 			AnalysisItem oneItem = itemIter.next();
       
   182 
       
   183 			// if given id and current analysis item id match return current
       
   184 			// analysis item
       
   185 			if (oneItem.getID() == givenID) {
       
   186 				return oneItem;
       
   187 			}
       
   188 		}
       
   189 		return null;
       
   190 	}
       
   191 
       
   192 	/**
       
   193 	 * Gets current run ID.
       
   194 	 *
       
   195 	 * @return Run ID
       
   196 	 */
       
   197 	public final int getItemID() {
       
   198 		return itemID;
       
   199 	}
       
   200 
       
   201 	/**
       
   202 	 * Gets current run module memory leak information.
       
   203 	 *
       
   204 	 * @return Hashtable<String, Integer> Module memory leak information
       
   205 	 */
       
   206 	public final Hashtable<String, Integer> getModuleLeaks() {
       
   207 		return moduleLeaks;
       
   208 	}
       
   209 
       
   210 	/**
       
   211 	 * Gets current run process name.
       
   212 	 *
       
   213 	 * @return Process name of the run
       
   214 	 */
       
   215 	public final String getProcessName() {
       
   216 		if( processName == null ){
       
   217 			return "";
       
   218 		}
       
   219 		return processName;
       
   220 	}
       
   221 
       
   222 	/**
       
   223 	 * Gets the start time of current analysis run.
       
   224 	 *
       
   225 	 * @return Start time
       
   226 	 */
       
   227 	public final String getStartTime() {
       
   228 		if( startTime == null ){
       
   229 			return "";
       
   230 		}
       
   231 		return this.startTime;
       
   232 	}
       
   233 
       
   234 	/**
       
   235 	 * Sets current run build target.
       
   236 	 *
       
   237 	 * @param target
       
   238 	 *            Build target
       
   239 	 */
       
   240 	public final void setBuildTarget(final String target) {
       
   241 		buildTarget = target;
       
   242 	}
       
   243 
       
   244 	/**
       
   245 	 * Sets the end time of current analysis run.
       
   246 	 *
       
   247 	 * @param newEndTime
       
   248 	 *            End time
       
   249 	 */
       
   250 	public final void setEndTime(final String newEndTime) {
       
   251 		this.endTime = newEndTime;
       
   252 	}
       
   253 
       
   254 	/**
       
   255 	 * Sets current run process name.
       
   256 	 *
       
   257 	 * @param newProcessName
       
   258 	 *            Process name for the run
       
   259 	 */
       
   260 	public final void setProcessName(final String newProcessName) {
       
   261 		processName = newProcessName;
       
   262 	}
       
   263 
       
   264 	/**
       
   265 	 * Sets the start time of current analysis run.
       
   266 	 *
       
   267 	 * @param newStartTime
       
   268 	 *            Start time
       
   269 	 */
       
   270 	public final void setStartTime(final String newStartTime) {
       
   271 		this.startTime = newStartTime;
       
   272 	}
       
   273 }