package innovimax.mixthem;

import java.io.File;

/**
* <p>Rule additional parameters management.</p>
* @author Innovimax
* @version 1.0
*/
public class RuleParam {

	private static final String TYPE_STRING = "string";
	private static final String TYPE_INTEGER = "integer";

	private final String name;	
	private final boolean required;
	private final String type;

	/**
 	* Creates a rule parameter.
 	* @param name The name of the parameter
 	* @param required Equals true if this parameter is required
 	*/
	RuleParam(String name, boolean required, String type) {
		this.name = name;
		this.required = required;
		this.type = type;
	}

	/**
	* Returns the name of the rule parameter.
	* @return The name of the rule parameter
	*/	
	String getName() {
		return this.name;
	}

	/**
 	* Returns true if this parameter is required.
 	* @return Returns true if this parameter is required
 	*/
	boolean isRequired() {
		return this.required;
	}


	/**
 	* Returns true if the parameter value is correct.
 	* @param value The value of the parameter on command line
 	* @return Returns true if the parameter value is correct
 	*/
	boolean checkValue(String value) {
		switch (this.type) {
        	case TYPE_STRING:
    			File file = new File(value);
        		if (file.exists()) {
        			return false;
        		} else {
        			return true;
        		}
        	case TYPE_INTEGER:
            	try {
            		Integer number = new Integer(value);
            		return true;
            	} catch (Exception e) {
            		return false;
            	}
            default:
            	return false;
		}
	}

	// This is the unique optional parameter of rule _RANDOM_ALT_LINE
	static RuleParam RANDOM_ALT_LINE_SEED = new RuleParam("seed", false, TYPE_INTEGER);
	// This is the first optional parameter of rule _JOIN
	static RuleParam JOIN_COL1 = new RuleParam("col1", false, TYPE_STRING);
	// This is the second optional parameter of rule _JOIN
	static RuleParam JOIN_COL2 = new RuleParam("col2", false, TYPE_STRING);

}

@@ -52,20 +52,49 @@
 **%0A* %3Cp%3E
-Rule
+This is a detailed enumeration of
  additio
@@ -93,24 +93,29 @@
  additional 
+rule 
 parameters m
@@ -116,19 +116,8 @@
 ters
- management
 .%3C/p
@@ -167,13 +167,12 @@
 lic 
-class
+enum
  Rul
@@ -183,116 +183,135 @@
 am %7B
-%0A%0A%09private static final String TYPE_STRING = %22string%22;%0A%09private static final String TYPE_INTEGER = %22integer%22
+ %0A%09_SEED(%22seed%22, false, ParamType._INTEGER),%0A%09_COL1(%22col1%22, false, ParamType._STRING),%0A%09_COL2(%22col2%22, false, ParamType._STRING)
 ;%0A%0A%09
@@ -336,17 +336,16 @@
 ng name;
-%09
 %0A%09privat
@@ -389,167 +389,34 @@
 nal 
-String type;%0A%0A%09/**%0A %09* Creates a rule parameter.%0A %09* @param name The name of the parameter%0A %09* @param required Equals true if this parameter is required%0A %09*/%0A%09
+ParamType type;%0A%0A%09private 
 Rule
@@ -452,22 +452,25 @@
 quired, 
-String
+ParamType
  type) %7B
@@ -562,16 +562,22 @@
 rns the 
+alias 
 name of 
@@ -570,38 +570,34 @@
 alias name of th
-e rule
+is
  parameter.%0A%09* @
@@ -607,16 +607,22 @@
 urn The 
+alias 
 name of 
@@ -627,14 +627,10 @@
 f th
-e rule
+is
  par
@@ -643,11 +643,17 @@
 %0A%09*/
-%09
 %0A%09
+public 
 Stri
@@ -692,25 +692,24 @@
 e;%0A%09%7D%0A%0A%09/**%0A
- 
 %09* Returns t
@@ -709,34 +709,33 @@
 turns true if th
-is
+e
  parameter is re
@@ -742,17 +742,16 @@
 quired.%0A
- 
 %09* @retu
@@ -749,33 +749,25 @@
 %0A%09* @return 
-Returns t
+T
 rue if this 
@@ -759,26 +759,25 @@
 n True if th
-is
+e
  parameter i
@@ -787,22 +787,28 @@
 equired%0A
- 
 %09*/%0A%09
+public 
 boolean 
@@ -850,16 +850,155 @@
 ed;%0A%09%7D%0A%0A
+%09/**%0A%09* Returns the type of this parameter.%0A%09* @return The type of this parameter%0A%09*/%0A%09public ParamType getType() %7B%0A%09%09return this.type;%0A%09%7D%0A
 %0A%09/**%0A %09
@@ -1244,20 +1244,16 @@
   %09case 
-TYPE
 _STRING:
@@ -1414,20 +1414,16 @@
   %09case 
-TYPE
 _INTEGER
@@ -1661,416 +1661,6 @@
 %09%7D%0A%0A
-%09// This is the unique optional parameter of rule _RANDOM_ALT_LINE%0A%09static RuleParam RANDOM_ALT_LINE_SEED = new RuleParam(%22seed%22, false, TYPE_INTEGER);%0A%09// This is the first optional parameter of rule _JOIN%0A%09static RuleParam JOIN_COL1 = new RuleParam(%22col1%22, false, TYPE_STRING);%0A%09// This is the second optional parameter of rule _JOIN%0A%09static RuleParam JOIN_COL2 = new RuleParam(%22col2%22, false, TYPE_STRING);%0A%0A
 %7D%0A

Update RuleParam.java