我在网上打了一个别的写的程序,想学一下是怎么样实现的?我就用jd-gui把它给反编译了。其中有这样一个方法 public static void langEditorInit(HttpServletRequest request, HttpServletResponse response) throws Exception
{
StringBuilder tabs = new StringBuilder();
StringBuilder tree = new StringBuilder();
ConcurrentHashMap lans =
Str.getLangMap();
List ls = StringUtil.sortMapKey(lans); boolean isFirst = true; for (Map.Entry e : ls) {
String key = (String)e.getKey();
ConcurrentHashMap v = (ConcurrentHashMap)lans.get(key);
if (v.size() != 0) {
if (isFirst) {
isFirst = false;
} else {
tabs.append(',');
tree.append(',');
}
tabs.append("{title:");
tabs.append(StringUtil.quote(key));
tabs
.append(
StringUtil.concat(
",id:\"tab_", new String[] {
key,
"\",layout:\"fit\",items:[{xtype:\"textarea\",id:\"area_",
key, "\"}]" }));
tabs.append('}');
tree.append("{text:");
tree.append(StringUtil.quote(key));
tree.append(",iconCls:\"item_icon\",leaf:true");
tree.append('}');
}
}
request.setAttribute("langTabs", tabs.toString());
request.setAttribute("treeContent", tree.toString());
}public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map) {
return sortMapKey(map, false);
} public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map,
boolean keyAsNumber) {
List<Entry<String, ?>> list = new ArrayList<Entry<String, ?>>(map
.entrySet());
final boolean keyAsNum = keyAsNumber;
Collections.sort(list, new Comparator<Entry<String, ?>>() {
Collator collator = Collator.getInstance(); public int compare(Entry<String, ?> e1, Entry<String, ?> e2) {
if (keyAsNum)
return Integer.parseInt(e1.getKey())
- Integer.parseInt(e2.getKey());
else {
CollationKey key1 = collator.getCollationKey(e1.getKey()
.toLowerCase());
CollationKey key2 = collator.getCollationKey(e2.getKey()
.toLowerCase());
return key1.compareTo(key2);
}
}
});
return list;
}
我把它放到myeclip中时,for (Map.Entry e : ls) 这句提示"Map cannot be resolved to a type",这是什么原因啊?
我觉得应该是这里不对吧List ls = StringUtil.sortMapKey(lans);,不应该用List ls接收吧?
如果改成这样List<Entry<String, ?>> ls = StringUtil.sortMapKey(lans); ,提示是数据不匹配,有谁知道该怎么定义?谢谢!
{
StringBuilder tabs = new StringBuilder();
StringBuilder tree = new StringBuilder();
ConcurrentHashMap lans =
Str.getLangMap();
List ls = StringUtil.sortMapKey(lans); boolean isFirst = true; for (Map.Entry e : ls) {
String key = (String)e.getKey();
ConcurrentHashMap v = (ConcurrentHashMap)lans.get(key);
if (v.size() != 0) {
if (isFirst) {
isFirst = false;
} else {
tabs.append(',');
tree.append(',');
}
tabs.append("{title:");
tabs.append(StringUtil.quote(key));
tabs
.append(
StringUtil.concat(
",id:\"tab_", new String[] {
key,
"\",layout:\"fit\",items:[{xtype:\"textarea\",id:\"area_",
key, "\"}]" }));
tabs.append('}');
tree.append("{text:");
tree.append(StringUtil.quote(key));
tree.append(",iconCls:\"item_icon\",leaf:true");
tree.append('}');
}
}
request.setAttribute("langTabs", tabs.toString());
request.setAttribute("treeContent", tree.toString());
}public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map) {
return sortMapKey(map, false);
} public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map,
boolean keyAsNumber) {
List<Entry<String, ?>> list = new ArrayList<Entry<String, ?>>(map
.entrySet());
final boolean keyAsNum = keyAsNumber;
Collections.sort(list, new Comparator<Entry<String, ?>>() {
Collator collator = Collator.getInstance(); public int compare(Entry<String, ?> e1, Entry<String, ?> e2) {
if (keyAsNum)
return Integer.parseInt(e1.getKey())
- Integer.parseInt(e2.getKey());
else {
CollationKey key1 = collator.getCollationKey(e1.getKey()
.toLowerCase());
CollationKey key2 = collator.getCollationKey(e2.getKey()
.toLowerCase());
return key1.compareTo(key2);
}
}
});
return list;
}
我把它放到myeclip中时,for (Map.Entry e : ls) 这句提示"Map cannot be resolved to a type",这是什么原因啊?
我觉得应该是这里不对吧List ls = StringUtil.sortMapKey(lans);,不应该用List ls接收吧?
如果改成这样List<Entry<String, ?>> ls = StringUtil.sortMapKey(lans); ,提示是数据不匹配,有谁知道该怎么定义?谢谢!
解决方案 »
- 难道是Spring 的BUG?很诡异的问题。求解答
- tomcat默认读的conf/tomcat-users.xml文件如何改成读数据库?
- 使用token标记防止表单重复提交后,怎么登录不能正常使用了?大家帮我看看这个问题,webwor框架的
- xml 全局属性通配符问题怎么回事啊?
- spring可以不用安装其他插件直接发布成webservice么?
- 求助项目编译成war包放入weblogic里出错找不到类文件
- eclipse plug-in 和 struts 谢谢帮忙
- 为什么我在调用另外1台机器ejb时候客户端总是说java.lang.ClassCastException
- spring+hibernate配置双数据源的问题
- 求大佬指教 关于访问共享文件的问题
- Hibernate 4 需要的JDK 版本是多少?
- 如何获得一个Servlet执行的结果, 而不是输出到浏览器?
有没有import java.util.Map;
import java.util.Map.Entry;