Есть несколько классов в каждом из maven-модулей. Все классы делают одно и то же, - хранят два списка -- список команд и список их опций. В каждом модуле команды и их опции разные, но сами классы очень похожи. Хотелось бы как-то это оптимизировать, чтобы не было таких похожих классов. Возможно через интерфейс, или дополнительный класс-builder. Посоветуйте, как правильно это сделать. Вот примеры этих классов:
public class PersonListCommandsAndOptions {
private OptionDescription fileOption = new OptionDescription
("file", "f", "file name", true);
private OptionDescription nameTrueOption = new OptionDescription
("name", "n", "name of person", true);
private OptionDescription nameFalseOption = new OptionDescription
("name", "n", "name of person", false);
private OptionDescription surnameTrueOption = new OptionDescription
("surname", "s", "surname of person", true);
private OptionDescription surnameFalseOption = new OptionDescription
("surname", "s", "surname of person", false);
private OptionDescription ageTrueOption = new OptionDescription
("age", "a", "age of person", true);
private OptionDescription ageFalseOption = new OptionDescription
("age", "a", "age of person", false);
private OptionDescription emailTrueOption = new OptionDescription
("email", "e", "person email address", true);
private OptionDescription emailFalseOption = new OptionDescription
("email", "e", "person email address", false);
private OptionDescription idTrueOption = new OptionDescription
("id", "i", "ID of person", true);
private OptionDescription idFalseOption = new OptionDescription
("id", "i", "ID of person", false);
private OptionDescription outOption = new OptionDescription
("out", "o", "what needs to be replaced", true);
private OptionDescription toOption = new OptionDescription
("to", "t", "what will be replaced", true);
private CommandDescription addPersonCmd = new CommandDescription("add", "a", "added to file",
new AddCommand(), fileOption, nameTrueOption, surnameTrueOption, ageTrueOption, emailTrueOption);
private CommandDescription clearPersonCmd = new CommandDescription("clear", "c",
"full clear of file", new ClearCommand(), fileOption);
private CommandDescription findPersonCmd = new CommandDescription("find", "f", "record search",
new FindCommand(), fileOption, nameFalseOption, surnameFalseOption, ageFalseOption, emailFalseOption,
idFalseOption);
private CommandDescription helpPersonCmd = new CommandDescription("help", "h", "help",
new HelpCommand());
private CommandDescription replacePersonCmd = new CommandDescription("replace", "r",
"replace content", new ReplaceCommand(), fileOption, outOption, toOption);
private CommandDescription viewPersonCmd = new CommandDescription("view", "v",
"view all file content", new ViewAllCommand(), fileOption);
private List<OptionDescription> personOptions = Arrays.asList(fileOption, nameTrueOption, nameFalseOption,
surnameTrueOption, surnameFalseOption, ageTrueOption, ageFalseOption, emailTrueOption, emailFalseOption,
idTrueOption, idFalseOption, outOption, toOption);
private List<CommandDescription> personCommands = Arrays.asList(addPersonCmd, clearPersonCmd, findPersonCmd,
helpPersonCmd, replacePersonCmd, viewPersonCmd);
public List<OptionDescription> getPersonOptions() {
return personOptions;
}
public List<CommandDescription> getPersonCommands(){
return personCommands;
}}
public class ClientListCommandsAndOptions {
private OptionDescription fileOption = new OptionDescription
("file", "f", "file name", true);
private OptionDescription jsonOption = new OptionDescription
("json", "j", "name of JSON-object", true);
private OptionDescription nameTrueOption = new OptionDescription
("name", "n", "name of client", true);
private OptionDescription nameFalseOption = new OptionDescription
("name", "n", "name of client", false);
private OptionDescription surnameTrueOption = new OptionDescription
("surname", "s", "surname of client", true);
private OptionDescription surnameFalseOption = new OptionDescription
("surname", "s", "surname of client", false);
private OptionDescription passportTrueOption = new OptionDescription
("passport", "x", "passport number of client", true);
private OptionDescription passportFalseOption = new OptionDescription
("passport", "x", "passport number of client", false);
private OptionDescription phoneTrueOption = new OptionDescription
("phone", "y", "client's phone number", true);
private OptionDescription phoneFalseOption = new OptionDescription
("phone", "y", "client's phone number", false);
private OptionDescription accountTrueOption = new OptionDescription
("account", "z", "account of client in the bank", true);
private OptionDescription accountFalseOption = new OptionDescription
("account", "z", "account of client in the bank", false);
private OptionDescription idTrueOption = new OptionDescription
("id", "i", "ID of client", true);
private OptionDescription idFalseOption = new OptionDescription
("id", "i", "ID of client", false);
private OptionDescription outOption = new OptionDescription
("out", "o", "what needs to be replaced", true);
private OptionDescription toOption = new OptionDescription
("to", "t", "what will be replaced", true);
private CommandDescription addClientCmd = new CommandDescription("add", "a", "added to file",
new AddCmd(), fileOption, jsonOption, nameTrueOption, surnameTrueOption, passportTrueOption,
phoneTrueOption, accountTrueOption);
private CommandDescription clearClientCmd = new CommandDescription("clear", "c",
"full clear of file", new ClearCmd(), fileOption, jsonOption);
private CommandDescription findClientCmd = new CommandDescription("find", "f", "record search",
new FindCmd(), fileOption, nameFalseOption, surnameFalseOption, passportFalseOption, phoneFalseOption,
accountFalseOption, idFalseOption);
private CommandDescription helpClientCmd = new CommandDescription("help", "h", "help",
new HelpCmd());
private CommandDescription replaceClientCmd = new CommandDescription("replace", "r",
"replace content", new ReplaceCmd(), fileOption, jsonOption, outOption, toOption);
private CommandDescription viewClientCmd = new CommandDescription("view", "v",
"view all file content", new ViewCmd(), fileOption);
private List<OptionDescription> clientOptions = Arrays.asList(fileOption, jsonOption, nameTrueOption,
nameFalseOption, surnameTrueOption, surnameFalseOption, passportTrueOption, passportFalseOption,
phoneTrueOption, phoneFalseOption, accountTrueOption, accountFalseOption, idTrueOption, idFalseOption,
outOption, toOption);
private List<CommandDescription> clientCommands = Arrays.asList(addClientCmd, clearClientCmd, findClientCmd,
helpClientCmd, replaceClientCmd, viewClientCmd);
public List<OptionDescription> getClientsOptions() {
return clientOptions;
}
public List<CommandDescription> getClientCommands(){
return clientCommands;
}}