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
CommitLineData
2d8d933f
SF
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
10package org.eclipse.tracecompass.internal.analysis.timing.core.callgraph;
11
12import org.eclipse.jdt.annotation.Nullable;
13import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
14
15/**
16 * Factory to create {@link ICalledFunction}s.
17 *
18 * @author Matthew Khouzam
19 */
56898baa 20public final class CalledFunctionFactory {
2d8d933f
SF
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
c2845a63
BH
40 * @param processId
41 * The process ID of the traced application
2d8d933f
SF
42 * @param parent
43 * the parent node
c2845a63 44 * @return an ICalledFunction with the specified properties
2d8d933f 45 */
c2845a63 46 public static AbstractCalledFunction create(long start, long end, int depth, ITmfStateValue stateValue, int processId, @Nullable ICalledFunction parent) {
2d8d933f 47 switch (stateValue.getType()) {
2d8d933f 48 case INTEGER:
c2845a63 49 return create(start, end, depth, stateValue.unboxInt(), processId, parent);
2d8d933f 50 case LONG:
c2845a63 51 return create(start, end, depth, stateValue.unboxLong(), processId, parent);
2d8d933f 52 case STRING:
c2845a63 53 return create(start, end, depth, stateValue.unboxStr(), processId, parent);
56898baa
MK
54 case CUSTOM:
55 // Fall through
56 case DOUBLE:
57 // Fall through
58 case NULL:
59 // Fall through
2d8d933f
SF
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
c2845a63
BH
77 * @param processId
78 * The process ID of the traced application
2d8d933f
SF
79 * @param parent
80 * the parent node
81 * @return an ICalledFunction with the specified propertiess
82 */
c2845a63 83 private static CalledFunction create(long start, long end, int depth, long value, int processId, @Nullable ICalledFunction parent) {
2d8d933f
SF
84 if (start > end) {
85 throw new IllegalArgumentException(Messages.TimeError + '[' + start + ',' + end + ']');
86 }
c2845a63 87 return new CalledFunction(start, end, value, depth, processId, parent);
2d8d933f
SF
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
c2845a63
BH
102 * @param processId
103 * The process ID of the traced application
2d8d933f
SF
104 * @param parent
105 * the parent node
fdf2d9bb 106 * @return an ICalledFunction with the specified properties
2d8d933f 107 */
56898baa 108 public static CalledStringFunction create(long start, long end, int depth, String value, int processId, @Nullable ICalledFunction parent) {
2d8d933f
SF
109 if (start > end) {
110 throw new IllegalArgumentException(Messages.TimeError + '[' + start + ',' + end + ']');
111 }
c2845a63 112 return new CalledStringFunction(start, end, value, depth, processId, parent);
2d8d933f
SF
113 }
114}
This page took 0.029942 seconds and 5 git commands to generate.