001package com.streamconverter.command; 002 003/** 004 * コマンド設定クラス 005 * 006 * <p>CommandFactoryで使用するコマンドの設定情報を保持します。 コマンドクラスとコンストラクタ引数を含みます。 007 */ 008public class CommandConfig { 009 private final Class<? extends IStreamCommand> commandClass; 010 private final Object[] args; 011 private final String description; 012 013 /** 014 * コンストラクタ 015 * 016 * @param commandClass コマンドクラス 017 * @param args コンストラクタ引数 018 */ 019 public CommandConfig(Class<? extends IStreamCommand> commandClass, Object... args) { 020 this.commandClass = commandClass; 021 this.args = args; 022 this.description = commandClass.getSimpleName(); 023 } 024 025 /** 026 * 説明付きコンストラクタ 027 * 028 * @param commandClass コマンドクラス 029 * @param description コマンドの説明 030 * @param args コンストラクタ引数 031 */ 032 public CommandConfig( 033 Class<? extends IStreamCommand> commandClass, String description, Object... args) { 034 this.commandClass = commandClass; 035 this.args = args; 036 this.description = description; 037 } 038 039 /** 040 * コマンドクラスを取得 041 * 042 * @return コマンドクラス 043 */ 044 public Class<? extends IStreamCommand> getCommandClass() { 045 return commandClass; 046 } 047 048 /** 049 * コンストラクタ引数を取得 050 * 051 * @return コンストラクタ引数のコピー 052 */ 053 public Object[] getArgs() { 054 return args.clone(); 055 } 056 057 /** 058 * コマンドの説明を取得 059 * 060 * @return コマンドの説明 061 */ 062 public String getDescription() { 063 return description; 064 } 065 066 @Override 067 public String toString() { 068 return String.format( 069 "CommandConfig{class=%s, description='%s', args=%d}", 070 commandClass.getSimpleName(), description, args.length); 071 } 072}