| /*=============================================================================# |
| # Copyright (c) 2008, 2020 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.r.core.model; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.statet.jcommons.lang.Builder; |
| import org.eclipse.statet.jcommons.lang.NonNull; |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| import org.eclipse.statet.jcommons.lang.Nullable; |
| |
| import org.eclipse.statet.r.core.model.ArgsDefinition.Arg; |
| |
| |
| /** |
| * Builder for {@link ArgsDefinition} |
| */ |
| @NonNullByDefault |
| public final class ArgsBuilder implements Builder<ArgsDefinition> { |
| |
| |
| private final List<Arg> args= new ArrayList<>(); |
| |
| |
| public ArgsBuilder() { |
| } |
| |
| |
| public ArgsBuilder add(final @Nullable String name) { |
| this.args.add(new Arg(this.args.size(), name, 0, null)); |
| return this; |
| } |
| |
| public ArgsBuilder add(final @Nullable String... name) { |
| for (int i= 0; i < name.length; i++) { |
| this.args.add(new Arg(this.args.size(), name[i], 0, null)); |
| } |
| return this; |
| } |
| |
| public ArgsBuilder add(final @Nullable String name, final int type) { |
| this.args.add(new Arg(this.args.size(), name, type, null)); |
| return this; |
| } |
| |
| public ArgsBuilder add(final @Nullable String name, final int type, final @Nullable String className) { |
| this.args.add(new Arg(this.args.size(), name, type, className)); |
| return this; |
| } |
| |
| |
| @Override |
| public ArgsDefinition build() { |
| return new ArgsDefinition(this.args.toArray(new @NonNull Arg[this.args.size()])); |
| } |
| |
| } |