package org.nutz.mvc.init;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;

import org.nutz.lang.Strings;
import org.nutz.lang.meta.Pair;

public class AtMap {

	private Map<String, String> ats;

	public AtMap() {
		ats = new HashMap<String, String>();
	}

	public AtMap add(String key, String actionPath) {
		ats.put(Strings.trim(key), Strings.trim(actionPath));
		return this;
	}

	public Set<String> keys() {
		return ats.keySet();
	}

	public int size() {
		return ats.size();
	}

	public String get(String key) {
		return ats.get(key);
	}

	public AtMap clear() {
		ats.clear();
		return this;
	}

	public List<Pair<String>> getList(String... regexs) {
		List<Pair<String>> list = new ArrayList<Pair<String>>(ats.size());
		Set<Entry<String, String>> ens = ats.entrySet();
		for (Entry<String, String> en : ens) {
			if (null == regexs || regexs.length == 0)
				list.add(new Pair<String>(en.getKey(), en.getValue()));
			else {
				for (String regex : regexs)
					if (Pattern.matches(regex, en.getKey())) {
						list.add(new Pair<String>(en.getKey(), en.getValue()));
						break;
					}
			}
		}
		return list;
	}

}

@@ -181,41 +181,8 @@
 et;%0D
-%0Aimport java.util.regex.Pattern;%0D
 %0A%0D%0Ai
@@ -420,24 +420,125 @@
 ionPath) %7B%0D%0A
+%09%09if (actionPath.endsWith(%22/*%22))%0D%0A%09%09%09actionPath = actionPath.substring(0, actionPath.length() - 2);%0D%0A
 %09%09ats.put(St
@@ -886,21 +886,23 @@
 ring... 
+p
 re
-gex
+fixe
 s) %7B%0D%0A%09%09
@@ -1063,16 +1063,46 @@
 ens) %7B%0D%0A
+%09%09%09String key = en.getKey();%0D%0A
 %09%09%09if (n
@@ -1112,23 +1112,27 @@
  == 
+p
 re
-gex
+fixe
 s %7C%7C 
+p
 re
-gex
+fixe
 s.le
@@ -1169,35 +1169,27 @@
 air%3CString%3E(
-en.getKey()
+key
 , en.getValu
@@ -1227,21 +1227,24 @@
 ing 
+p
 re
-ge
+fi
 x : 
+p
 re
-gex
+fixe
 s)%0D%0A
@@ -1256,42 +1256,29 @@
 if (
-Pattern.matches(regex, en.getKey()
+key.startsWith(prefix
 )) %7B
@@ -1311,27 +1311,19 @@
 String%3E(
-en.getKey()
+key
 , en.get

修正一下 AtMap，用正则表达式太慢了