8bc9d4ab12af621b11282c69685d9e73b2f740be
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.remote.core / src / org / eclipse / tracecompass / internal / tmf / remote / core / shell / CommandResult.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.tracecompass.internal.tmf.remote.core.shell;
13
14 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
21
22 import com.google.common.collect.ImmutableList;
23
24 /**
25 * Class containing command result of remote command execution.
26 *
27 * @author Bernd Hufmann
28 */
29 @NonNullByDefault
30 public class CommandResult implements ICommandResult {
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35 /** The result of the command. 0 if successful else > 0 */
36 private final int fResult;
37
38 /** The output as list of Strings. */
39 private final List<String> fOutput;
40
41 /** The error stream output as list of Strings. */
42 private final List<String> fErrorOutput;
43
44 // ------------------------------------------------------------------------
45 // Constructor
46 // ------------------------------------------------------------------------
47
48 /**
49 * Constructor
50 *
51 * @param result
52 * The result of the command
53 * @param output
54 * The output, as an array of strings
55 * @param errorOutput
56 * THe error output as an array of strings
57 */
58 public CommandResult(int result, String[] output, String[] errorOutput) {
59 fResult = result;
60 fOutput = checkNotNull(ImmutableList.copyOf(output));
61 fErrorOutput = checkNotNull(ImmutableList.copyOf(errorOutput));
62 }
63
64 // ------------------------------------------------------------------------
65 // Accessors
66 // ------------------------------------------------------------------------
67
68 @Override
69 public int getResult() {
70 return fResult;
71 }
72
73 @Override
74 public List<String> getOutput() {
75 return fOutput;
76 }
77
78 @Override
79 public List<String> getErrorOutput() {
80 return fErrorOutput;
81 }
82
83 @Override
84 public String toString() {
85 StringBuffer ret = new StringBuffer();
86 ret.append("Error Output:\n"); //$NON-NLS-1$
87 for (String string : fErrorOutput) {
88 ret.append(string).append("\n"); //$NON-NLS-1$
89 }
90 ret.append("Return Value: "); //$NON-NLS-1$
91 ret.append(fResult);
92 ret.append("\n"); //$NON-NLS-1$
93 for (String string : fOutput) {
94 ret.append(string).append("\n"); //$NON-NLS-1$
95 }
96 return nullToEmptyString(ret.toString());
97 }
98 }
This page took 0.034388 seconds and 4 git commands to generate.