001package org.unix4j.unix.sed; 002 003import org.unix4j.unix.Sed; 004 005/** 006 * Factory for the {@link Sed sed} command returning 007 * a new command instance from every signature method. 008 */ 009public final class SedFactory implements Sed.Interface<SedCommand> { 010 011 /** 012 * The singleton instance of this factory. 013 */ 014 public static final SedFactory INSTANCE = new SedFactory(); 015 016 /** 017 * Private, only used to create singleton instance. 018 */ 019 private SedFactory() { 020 super(); 021 } 022 023 @Override 024 public SedCommand sed(String... args) { 025 final SedArguments sedArgs = new SedArguments(args); 026 return new SedCommand(sedArgs); 027 } 028 029 @Override 030 public SedCommand sed(String script) { 031 final SedArguments sedArgs = new SedArguments(); 032 sedArgs.setScript(script); 033 return new SedCommand(sedArgs); 034 } 035 036 @Override 037 public SedCommand sed(String regexp, String replacement) { 038 final SedArguments sedArgs = new SedArguments(); 039 sedArgs.setRegexp(regexp); 040 sedArgs.setReplacement(replacement); 041 return new SedCommand(sedArgs); 042 } 043 044 @Override 045 public SedCommand sed(String regexp, String replacement, int... occurrence) { 046 final SedArguments sedArgs = new SedArguments(); 047 sedArgs.setRegexp(regexp); 048 sedArgs.setReplacement(replacement); 049 sedArgs.setOccurrence(occurrence); 050 return new SedCommand(sedArgs); 051 } 052 053 @Override 054 public SedCommand sed(SedOptions options, String regexp) { 055 final SedArguments sedArgs = new SedArguments(options); 056 sedArgs.setRegexp(regexp); 057 return new SedCommand(sedArgs); 058 } 059 060 @Override 061 public SedCommand sed(SedOptions options, String string1, String string2) { 062 final SedArguments sedArgs = new SedArguments(options); 063 sedArgs.setString1(string1); 064 sedArgs.setString2(string2); 065 return new SedCommand(sedArgs); 066 } 067 068 @Override 069 public SedCommand sed(SedOptions options, String string1, String string2, int... occurrence) { 070 final SedArguments sedArgs = new SedArguments(options); 071 sedArgs.setString1(string1); 072 sedArgs.setString2(string2); 073 sedArgs.setOccurrence(occurrence); 074 return new SedCommand(sedArgs); 075 } 076}