javaの列挙型 enum

#javaの列挙型 enum

C言語のポインタ配列に疑似するjavaの窮苦。。
---
```java:Functions.java
package method.call;

import java.util.HashMap;
import java.util.Map;

import method.call.Jumper.__EnumFunc__;

public class Functions {
	// Entry 01
	public void method_func_01(Map<String, String> par) {
		System.out.printf("\t<result>01 done.</result>%n\t<arguments>%s</arguments>%n", par);
	}

	public Map<String, String> parameters_func_01(__EnumFunc__ e) {
		return safetyMap(e.getParameter());
	}
	
	// Entry 02
	public void method_func_02(ParameterFunction02 par) {
		System.out.printf("\t<result>02 done.</result>%n\t<arguments>%s</arguments>%n", par);
	}
	
	public ParameterFunction02 parameters_func_02(__EnumFunc__ e) {
		Object p = e.getParameter();
		return (p instanceof ParameterFunction02) ? (ParameterFunction02)p : new ParameterFunction02();
	}
	
	// Entry 03
	public void method_func_03(Map<String, String> par) {
		System.out.printf("\t<result>03 done.</result>%n\t<arguments>%s</arguments>%n", par);
	}

	public Map<String, String> parameters_func_03(__EnumFunc__ e) {
		return safetyMap(e.getParameter());
	}

    static <K, V> Map<K, V> safetyMap(Object objectMap) {
    	if (objectMap == null) {
    		return null;
    	}
    	
    	@SuppressWarnings("unchecked")
		Map<K, V> map = (Map<K, V>) (objectMap);
    	
        return new HashMap<K, V>(map);
    }
}
```
---
```java:ParameterFunction02.java
package method.call;

import java.util.HashMap;
import java.util.Map;

public class ParameterFunction02 {
	String s1;
	String s2;
	Map<String, Object> o1 = new HashMap<String, Object>();
	
	public String toString() {
		StringBuffer work = new StringBuffer(128);
		work.append("s1=").append("[").append(s1).append("],");
		work.append("s2=").append("[").append(s2).append("],");
		work.append("o1=").append("[").append(o1).append("]");
		
		return work.toString();
	}
}
```
---
```java:Jumper.java
package method.call;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

public class Jumper extends Functions {
	
	public static void main(String[] args) throws Exception {
        Jumper j = new Jumper();
		j.mainEntry();
	}
	
	
	public void mainEntry() throws Exception {
		List<__EnumFunc__> listFunc = new ArrayList<__EnumFunc__>();
		
		Map<String, Object> info = buildRunData();
		
		for (Iterator<Entry<String, Object>> it = info.entrySet().iterator(); it.hasNext();) {
			setEntryData(listFunc, it.next());
		}
		
		System.out.println();
		
		for (__EnumFunc__ entry : listFunc) {
			System.out.printf("<%s parameter=\"%s\">%n", entry.strLabel, entry.getParameter());
			entry.call(this, entry);
			System.out.printf("</%s>%n%n", entry.strLabel);
		}
	}
	
	private Map<String, Object> buildRunData() {
		Map<String, Object> info = new TreeMap<String, Object>();
		
		info.put("__Entry_01__", new HashMap<String, Object>(2){
			private static final long serialVersionUID = 1L;
			{
				put("pkey1", 123456);
				put("pkey2", "abcd");
			} 
		});
		info.put("__Entry_02__", new ParameterFunction02() {
			{
				this.s1 = "A01";
				this.s2 = "B99";
				this.o1.put("key3", 654321);
				this.o1.put("key4", "dcba");
			}
		});
		info.put("__Entry_03__", new HashMap<String, Object>(3){
			private static final long serialVersionUID = 1L;
			{
				put("pkey1", 123456);
				put("pkey2", "abcd");
				put("pkey3", 2);
			} 
		});
		
		return info;
	}
	
	private __EnumFunc__ setEntryData(List<__EnumFunc__> list, Entry<String, Object> e) {
		String key = e.getKey();
		
		__EnumFunc__ eFunc = __EnumFunc__.safeValueOf(key); 
		
		if (eFunc.intValue >= 0) {
			System.out.printf("[setEntryData]key:%s, parameter = (%s)%n", key, e.getValue());
			eFunc.putParameter(e.getValue());
			list.add( eFunc ); 
		}
		
		return eFunc;
	}
	
	private static final String __NoEntry__ = "NoFunction";
	private static final String __Lable01__ = "Function01";
	private static final String __Lable02__ = "Function02";
	private static final String __Lable03__ = "Function03";
	
	enum __EnumFunc__ {
		  __Entry_01__ ( 1, __Lable01__) { void call(Jumper me, method.call.Jumper.__EnumFunc__ e) throws Exception {me.method_func_01 (me.parameters_func_01 (e)); } }
		, __Entry_02__ ( 2, __Lable02__) { void call(Jumper me, method.call.Jumper.__EnumFunc__ e) throws Exception {me.method_func_02 (me.parameters_func_02 (e)); } }
		, __Entry_03__ ( 3, __Lable03__) { void call(Jumper me, method.call.Jumper.__EnumFunc__ e) throws Exception {me.method_func_03 (me.parameters_func_03 (e)); } }
		, __Excluded__ (-1, __NoEntry__)
		;
		
		private int intValue;
		private String strLabel;
		
		private Object parameter;
		
		private __EnumFunc__(int n, String s) {
			this.intValue = n;
			this.strLabel = s;
		}
		
		void putParameter(Object v) {
			this.parameter = v;
		}
		
		int getValue() {
			return this.intValue;
		}
		
		String getLabel() {
			return this.strLabel;
		}
		
		Object getParameter() {
			return this.parameter;
		}
		
		static __EnumFunc__ safeValueOf(final String s) {
			__EnumFunc__ funcJumper = __Excluded__;
			
			try {
				funcJumper = method.call.Jumper.__EnumFunc__.valueOf(s);
			} catch (Exception e) {
			}
			
			return funcJumper;
		}
		
		void call(Jumper me, method.call.Jumper.__EnumFunc__ e) throws Exception {
			return;
		}
	}
}
```
---
実行結果：
<pre>
[setEntryData]key:__Entry_01__, parameter = ({pkey2=abcd, pkey1=123456})
[setEntryData]key:__Entry_02__, parameter = (s1=[A01],s2=[B99],o1=[{key4=dcba, key3=654321}])
[setEntryData]key:__Entry_03__, parameter = ({pkey3=2, pkey2=abcd, pkey1=123456})

&lt;Function01 parameter="{pkey2=abcd, pkey1=123456}"&gt;
	&lt;result&gt;01 done.&lt;/result&gt;
	&lt;arguments&gt;{pkey2=abcd, pkey1=123456}&lt;/arguments&gt;
&lt;/Function01&gt;

&lt;Function02 parameter="s1=[A01],s2=[B99],o1=[{key4=dcba, key3=654321}]"&gt;
	&lt;result&gt;02 done.&lt;/result&gt;
	&lt;arguments&gt;s1=[A01],s2=[B99],o1=[{key4=dcba, key3=654321}]&lt;/arguments&gt;
&lt;/Function02&gt;

&lt;Function03 parameter="{pkey3=2, pkey2=abcd, pkey1=123456}"&gt;
	&lt;result&gt;03 done.&lt;/result&gt;
	&lt;arguments&gt;{pkey3=2, pkey2=abcd, pkey1=123456}&lt;/arguments&gt;
&lt;/Function03&gt;
</pre>