All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tobedevoured.command.CommandMethod Maven / Gradle / Ivy

The newest version!
package com.tobedevoured.command;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Model of a Method annotation by @Command
 * 
 * @author Michael Guymon
 *
 */
public class CommandMethod {

	private String name;
	private String methodName;
	private Map paramTypes;
	private Map defaults;
	private boolean exit = true;
	private boolean logResult = false;
	private Object result;
	
	/**
	 * Construct with the CommandMethod's field's name
	 * 
	 * @param name String
	 */
	public CommandMethod( String name ) {
		this(name, null);
	}
	
	/**
	 * Construct with the CommandMethod's name and the field's name
	 * 
	 * @param name String
	 * @param methodName String
	 */
	public CommandMethod( String name, String methodName ) {
		this.name = name;
		this.methodName = methodName;
		this.paramTypes = new LinkedHashMap();
		this.defaults   = new LinkedHashMap();
	}

	public String getName() {
		return name;
	}

	/**
	 * Add a method param
	 *  
	 * @param name String
	 * @param type Clazz
	 */
	public void addParam( String name, Class type ) {
		paramTypes.put( name, type );
	}
	
	/**
	 * Add a method param with a default value 
	 * 
	 * @param name String 
	 * @param type Class
	 * @param defaultValue Object
	 */
	public void addParam(String name, Class type, Object defaultValue) {
		addParam( name, type );
		defaults.put( name, defaultValue );
	}
	
	/**
	 * Map of method params
	 * 
	 * @return Map
	 */
	public Map getParamTypes() {
		return paramTypes;
	}

	public Class[] getParamTypesArray() {
		return paramTypes.values().toArray( new Class[paramTypes.size()] );
	}
	
	public Map getDefaults() {
		return defaults;
	}
	
	public boolean hasParams() {
		return paramTypes.size() > 0; 
	}

	public String getMethodName() {
		return methodName;
	}

	/**
	 * Should this CommandMethod exit after execution
	 * 
	 * @return boolean
	 */
	public boolean isExit() {
		return exit;
	}

	/**
	 * Set if this CommandMethod should exist after execution
	 * 
	 * @param exit boolean
	 */
	public void setExit(boolean exit) {
		this.exit = exit;
	}

	/**
	 * Should this CommandMethod log the result of the execution
	 * 
	 * @return boolean
	 */
	public boolean isLogResult() {
		return logResult;
	}

	/**
	 * Set if this CommandMethod should log the result of the execution
	 * 
	 * @param logResult boolean
	 */
	public void setLogResult(boolean logResult) {
		this.logResult = logResult;
	}

	/**
	 * Get the result of the CommandMethod's execution
	 * 
	 * @return Object
	 */
	public Object getResult() {
		return result;
	}

	/**
	 * Set the result of the CommandMethod's execution
	 * 
	 * @param result Object
	 */
	public void setResult(Object result) {
		this.result = result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy