Commit | Line | Data |
---|---|---|
364dcfaf BH |
1 | /********************************************************************** |
2 | * Copyright (c) 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.ArrayList; | |
18 | import java.util.List; | |
19 | ||
20 | import org.eclipse.jdt.annotation.Nullable; | |
21 | import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput; | |
22 | ||
23 | import com.google.common.collect.ImmutableList; | |
24 | ||
25 | /** | |
26 | * Class for defining command input for remote command execution. | |
27 | * | |
28 | * @author Bernd Hufmann | |
29 | */ | |
30 | public class CommandInput implements ICommandInput { | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Attributes | |
34 | // ------------------------------------------------------------------------ | |
35 | /** The input as list of Strings. */ | |
36 | private final List<String> fInput = new ArrayList<>(); | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Accessors | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
42 | @Override | |
43 | public List<String> getInput() { | |
44 | return checkNotNull(ImmutableList.copyOf(fInput)); | |
45 | } | |
46 | ||
47 | // ------------------------------------------------------------------------ | |
48 | // Operations | |
49 | // ------------------------------------------------------------------------ | |
50 | @Override | |
51 | public void add(@Nullable String segment) { | |
52 | if (segment != null) { | |
53 | fInput.add(segment); | |
54 | } | |
55 | } | |
56 | ||
57 | @Override | |
c07150f8 | 58 | public void addAll(List<String> segments) { |
364dcfaf BH |
59 | for (String segment : segments) { |
60 | add(segment); | |
61 | } | |
62 | } | |
63 | ||
64 | /** | |
65 | * Creates a single command string from a command line list. | |
66 | * | |
67 | * @return single command string | |
68 | */ | |
69 | @Override | |
70 | public String toString() { | |
71 | StringBuilder builder = new StringBuilder(); | |
72 | for (String segment : getInput()) { | |
73 | builder.append(segment).append(' '); | |
74 | } | |
75 | return nullToEmptyString(builder.toString().trim()); | |
76 | } | |
77 | } |