Java tutorial
/** * Copyright 2014-2015 SHAF-WORK * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.shaf.shell.action; import org.shaf.client.net.ClientException; import com.google.common.collect.Sets; /** * The {@code AbstractAction} should be extended by any class interested in * providing specific functionality for performing command actions. * * @author Mykola Galushka */ public abstract class AbstractAction implements Action { protected final void validateNumberOfArgument(final String[] args, final int num) { if (args.length < num) throw new IllegalArgumentException("arguments number < " + num); } protected final boolean isProcessAvailable(final ActionContext context, final String command) throws ClientException { return Sets.newHashSet(context.getController().listProcesses().getTable().getColumn(0)).contains(command); } protected final boolean isJobAvailable(final ActionContext context, final String id) throws ClientException { return Sets.newHashSet(context.getController().listJobs().getTable().getColumn(0)).contains(id); } protected final boolean isUploadAvailable(final ActionContext context, final String alias) throws ClientException { return Sets.newHashSet(context.getController().listUploads().getTable().getColumn(0)).contains(alias); } protected final boolean isDownloadAvailable(final ActionContext context, final String alias) throws ClientException { return Sets.newHashSet(context.getController().listDownloads().getTable().getColumn(0)).contains(alias); } }