timing.core: Simplify CalledFunctionFactory
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / internal / analysis / timing / core / callgraph / CalledFunctionFactory.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.analysis.timing.core.callgraph;
11
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
14
15 /**
16 * Factory to create {@link ICalledFunction}s.
17 *
18 * @author Matthew Khouzam
19 */
20 public final class CalledFunctionFactory {
21
22 private static final String SEPARATOR = ": "; //$NON-NLS-1$
23 private static final String ERROR_MSG = "Cannot create a called function of type : "; //$NON-NLS-1$
24
25 private CalledFunctionFactory() {
26 // do nothing
27 }
28
29 /**
30 * Factory Method for a state value mapped called function
31 *
32 * @param start
33 * the start time
34 * @param end
35 * the end time
36 * @param depth
37 * the depth
38 * @param stateValue
39 * the symbol
40 * @param processId
41 * The process ID of the traced application
42 * @param parent
43 * the parent node
44 * @return an ICalledFunction with the specified properties
45 */
46 public static AbstractCalledFunction create(long start, long end, int depth, ITmfStateValue stateValue, int processId, @Nullable ICalledFunction parent) {
47 switch (stateValue.getType()) {
48 case INTEGER:
49 return create(start, end, depth, stateValue.unboxInt(), processId, parent);
50 case LONG:
51 return create(start, end, depth, stateValue.unboxLong(), processId, parent);
52 case STRING:
53 return create(start, end, depth, stateValue.unboxStr(), processId, parent);
54 case CUSTOM:
55 // Fall through
56 case DOUBLE:
57 // Fall through
58 case NULL:
59 // Fall through
60 default:
61 throw new IllegalArgumentException(ERROR_MSG + stateValue.getType() + SEPARATOR + stateValue.toString());
62 }
63 }
64
65 /**
66 * Factory method to create a called function with a symbol that is a long
67 * integer
68 *
69 * @param start
70 * the start time
71 * @param end
72 * the end time
73 * @param depth
74 * the depth
75 * @param value
76 * the symbol
77 * @param processId
78 * The process ID of the traced application
79 * @param parent
80 * the parent node
81 * @return an ICalledFunction with the specified propertiess
82 */
83 private static CalledFunction create(long start, long end, int depth, long value, int processId, @Nullable ICalledFunction parent) {
84 if (start > end) {
85 throw new IllegalArgumentException(Messages.TimeError + '[' + start + ',' + end + ']');
86 }
87 return new CalledFunction(start, end, value, depth, processId, parent);
88 }
89
90 /**
91 * Factory method to create a called function with a symbol that is a
92 * {@link String}
93 *
94 * @param start
95 * the start time
96 * @param end
97 * the end time
98 * @param depth
99 * the depth
100 * @param value
101 * the symbol
102 * @param processId
103 * The process ID of the traced application
104 * @param parent
105 * the parent node
106 * @return an ICalledFunction with the specified properties
107 */
108 public static CalledStringFunction create(long start, long end, int depth, String value, int processId, @Nullable ICalledFunction parent) {
109 if (start > end) {
110 throw new IllegalArgumentException(Messages.TimeError + '[' + start + ',' + end + ']');
111 }
112 return new CalledStringFunction(start, end, value, depth, processId, parent);
113 }
114 }
This page took 0.032559 seconds and 5 git commands to generate.