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