trace/traceviewer/com.nokia.trace.dictionary/src/com/nokia/trace/dictionary/model/TraceInstanceList.java
changeset 11 5b9d4d8641ce
equal deleted inserted replaced
10:ed1c9f64298a 11:5b9d4d8641ce
       
     1 /*
       
     2  * Copyright (c) 2007-2010 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:
       
    15  *
       
    16  * Holds trace instances for a trace structure
       
    17  *
       
    18  */
       
    19 package com.nokia.trace.dictionary.model;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 import java.util.HashMap;
       
    23 import java.util.Iterator;
       
    24 
       
    25 /**
       
    26  * Holds trace instances for a trace structure
       
    27  * 
       
    28  */
       
    29 public class TraceInstanceList extends DecodeObject {
       
    30 
       
    31 	/**
       
    32 	 * Trace list
       
    33 	 */
       
    34 	private ArrayList<Trace> traces;
       
    35 
       
    36 	/**
       
    37 	 * Constructor
       
    38 	 * 
       
    39 	 * @param id
       
    40 	 *            Id
       
    41 	 * @param name
       
    42 	 *            Name
       
    43 	 */
       
    44 	public TraceInstanceList(int id, String name) {
       
    45 		super(id, name);
       
    46 		traces = new ArrayList<Trace>();
       
    47 	}
       
    48 
       
    49 	/**
       
    50 	 * Add trace
       
    51 	 * 
       
    52 	 * @param trace
       
    53 	 *            new trace
       
    54 	 */
       
    55 	public void addTrace(Trace trace) {
       
    56 		traces.add(trace);
       
    57 	}
       
    58 
       
    59 	/**
       
    60 	 * Sets metadata to all the traces in the list. Is called when trace tag
       
    61 	 * ends in dictionary file.
       
    62 	 */
       
    63 	public void setMetadataToTraces() {
       
    64 		if (getMetadata() != null) {
       
    65 			Iterator<Trace> it = traces.iterator();
       
    66 			while (it.hasNext()) {
       
    67 				Trace trace = it.next();
       
    68 				if (trace.metadataMap == null) {
       
    69 					trace.metadataMap = new HashMap<String, HashMap<String, Object>>();
       
    70 				}
       
    71 				addMissingMetadataToList(getMetadata(), trace.metadataMap);
       
    72 			}
       
    73 		}
       
    74 	}
       
    75 
       
    76 	/**
       
    77 	 * Adds missing metadata to list
       
    78 	 * 
       
    79 	 * @param oldList
       
    80 	 *            old list to append from
       
    81 	 * @param newList
       
    82 	 *            new list to append to
       
    83 	 */
       
    84 	private void addMissingMetadataToList(
       
    85 			HashMap<String, HashMap<String, Object>> oldList,
       
    86 			HashMap<String, HashMap<String, Object>> newList) {
       
    87 		Iterator<String> it = oldList.keySet().iterator();
       
    88 		while (it.hasNext()) {
       
    89 			String key = it.next();
       
    90 
       
    91 			// Doesn't contain this key, add it
       
    92 			if (!newList.containsKey(key)) {
       
    93 				newList.put(key, oldList.get(key));
       
    94 
       
    95 				// Contains the key, check values inside
       
    96 			} else {
       
    97 				Iterator<String> valueIt = oldList.get(key).keySet().iterator();
       
    98 				while (valueIt.hasNext()) {
       
    99 					String valueKey = valueIt.next();
       
   100 
       
   101 					// Doesn't contain value key, add it
       
   102 					if (!newList.get(key).containsKey(valueKey)) {
       
   103 						newList.get(key).put(valueKey,
       
   104 								newList.get(key).get(valueKey));
       
   105 					}
       
   106 				}
       
   107 			}
       
   108 		}
       
   109 	}
       
   110 }