001package org.unix4j.command; 002 003import org.unix4j.builder.CommandBuilder; 004import org.unix4j.context.ExecutionContext; 005import org.unix4j.io.NullOutput; 006import org.unix4j.processor.LineProcessor; 007 008/** 009 * A command that performs no operation. Useful as initial command in a 010 * {@link CommandBuilder}. The {@link #join(Command)} method returns the joined 011 * command only, that is, this {@code nop} command is eliminated. 012 */ 013public class NoOp extends AbstractCommand<NoOp.Args> { 014 015 /** 016 * Arguments for NoOp. 017 */ 018 public static final class Args implements Arguments<Args> { 019 @Override 020 public Args getForContext(ExecutionContext context) { 021 return this;//no arguments, hence the same for all contexts 022 } 023 } 024 025 /** 026 * The "nop" command name. 027 */ 028 public static final String NAME = "nop"; 029 /** 030 * The singleton instance. 031 */ 032 public static final NoOp INSTANCE = new NoOp(); 033 034 /** 035 * Private constructor for singleton {@link #INSTANCE}. 036 */ 037 private NoOp() { 038 super(NAME, new Args()); 039 } 040 041 /** 042 * Returns the given {@code next} command eliminating this {@code NoOp} 043 * command in a join. 044 * 045 * @return the {@code next} command argument 046 */ 047 @Override 048 public Command<?> join(Command<?> next) { 049 return next; 050 } 051 052 @Override 053 public LineProcessor execute(ExecutionContext context, LineProcessor output) { 054 return NullOutput.ABORT; 055 } 056}