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