@Test
    public void test_when_test1() throws Exception {
        String[] strs = {"e", "ee", "ea", "ei", "ie", "i", "y", "e", "e", "ea", "a", "e", "ir", "ar", "or", "ear", "e", "a", "o", "u", "or", "er", "oo", "o", "u", "ew", "ui", "oe", "ou", "oo", "oul", "u", "o", "a", "al", "au", "aw", "or", "oar", "ore", "ar", "oor", "ou", "al", "ar", "a", "o", "u", "ou", "a", "ai", "ay", "ei", "i", "y", "oy", "oi", "o", "oa", "oe", "ow", "ou", "ow", "ear", "ere", "ea", "eer", "are", "air", "ear", "ere", "our", "oor", "ure"};
        log.info("=====>strs.length: " + strs.length);
        List<String> list = Arrays.asList(strs);
        Set set = new HashSet(list);
        Object[] strsvm = set.toArray(new String[0]);
        Arrays.sort(strsvm);
        List<Object> strsvmDm = Arrays.asList(strsvm);
        List<Map> strings = new TreeList();
        for (int i = 0; i < strsvm.length; i++) {
            Object o = strsvm[i];
            int count = 0;
            Map map = new TreeMap();
            for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); ) {
                String next =  iterator.next();
                if (next.matches(o.toString())) {
                    count++;
                }
            }
            if (count == 0) count = 1;
            map.put("count", count);
            map.put("value", o);
            strings.add(map);

        }
        if (null != strings&& strings.size()>0) {
            Collections.sort(strings,new Comparator<Map>() {
                @Override
                public int compare(Map o1, Map o2) {
                    int ret = 0;
                    //比较两个对象的顺序,如果前者小于、等于或者大于后者,则分别返回-1/0/1
                    ret = o1.get("count").toString().compareTo(o2.get("count").toString());//逆序的话就用o2.compareTo(o1)即可
                    return ret;
                }
            });
        }
        // 输出
        int sum = 0;
        for (Iterator<Map> iterator = strings.iterator(); iterator.hasNext(); ) {
            Map next =  iterator.next();
//            log.warn("=====>next: " + next);
            Object vmCount = next.get("count");
            Object value = next.get("value");
            System.out.print("=====>value: " + value+"   \t\t"+vmCount);
            Integer vmCountInt = Integer.valueOf(vmCount.toString());
            sum = sum + vmCountInt;
            System.out.println();
        }

    }

 

posted on 2017-10-27 13:12  天之城  阅读(471)  评论(0编辑  收藏  举报