锘??xml version="1.0" encoding="utf-8" standalone="yes"?>julia一区二区中文久久94 ,精品国产3级a,热久久视久久精品18亚洲精品http://www.aygfsteel.com/mstar/category/1573.html鎼炶蔣浠跺紑鍙戝氨鍍忚寮哄ジ,濡傛灉涓嶈兘鍙嶆姉,灝變韓鍙楀畠鍚э紒zh-cnTue, 27 Feb 2007 18:20:00 GMTTue, 27 Feb 2007 18:20:00 GMT60org.mstar.collection.TwoDimensionTablehttp://www.aygfsteel.com/mstar/archive/2005/06/01/5434.html榛戠伒榛戠伒Wed, 01 Jun 2005 15:12:00 GMThttp://www.aygfsteel.com/mstar/archive/2005/06/01/5434.htmlhttp://www.aygfsteel.com/mstar/comments/5434.htmlhttp://www.aygfsteel.com/mstar/archive/2005/06/01/5434.html#Feedback1http://www.aygfsteel.com/mstar/comments/commentRss/5434.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/5434.html闃呰鍏ㄦ枃

榛戠伒 2005-06-01 23:12 鍙戣〃璇勮
]]>
org.mstar.collection.Counterhttp://www.aygfsteel.com/mstar/archive/2005/06/01/5432.html榛戠伒榛戠伒Wed, 01 Jun 2005 13:11:00 GMThttp://www.aygfsteel.com/mstar/archive/2005/06/01/5432.htmlhttp://www.aygfsteel.com/mstar/comments/5432.htmlhttp://www.aygfsteel.com/mstar/archive/2005/06/01/5432.html#Feedback0http://www.aygfsteel.com/mstar/comments/commentRss/5432.htmlhttp://www.aygfsteel.com/mstar/services/trackbacks/5432.html榪欎釜綾諱富瑕佸姛鑳芥槸璁板綍鏀懼叆鍏朵腑鐨勭浉鍚屽璞$殑涓暟錛堢敤equals()姣旇緝錛?BR>
渚嬪錛?BR>
Counter c = new Counter();
c.add(
"One");
c.add(
"Two");
c.add(
"One");

c.
get("One"// Result is 2;
c.get("Two"// Result is 1;

榪欎釜綾葷殑鍚嶅瓧涔熻闇瑕佽浠ヤ笅銆?BR>榪樻湁浠涔堥渶瑕佹敼榪涚殑鍦版柟錛屾垨鑰呰繕闇瑕佸摢浜涙柟娉曪紝璇峰ぇ瀹舵彁紺恒?BR>
瀹炵幇濡備笅錛?BR>
 1package org.mstar.collection;
 2
 3import java.util.HashMap;
 4import java.util.Iterator;
 5import java.util.Map;
 6
 7
 8/**
 9 * @author mty
10 *
11 */

12public class Counter {
13    private Map map;
14    
15    public Counter(){
16        map = new HashMap();
17    }

18    
19    public void add(Object key){
20        if(map.containsKey(key)){
21            Integer i = (Integer)map.get(key);
22            int amount = i.intValue();
23            map.put(key,new Integer(++amount));
24        }
else{
25            map.put(key,new Integer(1));
26        }

27    }

28    
29    public void add(Object key,int amount){
30        if(map.containsKey(key)){
31            Integer i = (Integer)map.get(key);
32            int amount2 = i.intValue();
33            map.put(key,new Integer(amount+amount2));
34        }
else{
35            map.put(key,new Integer(amount));
36        }

37    }

38    
39    public Iterator iterator(){
40        return map.keySet().iterator();
41    }

42    
43    public int getCount(Object key){
44        Integer i = (Integer)map.get(key);
45        return i.intValue();
46    }

47    
48    public int[] countArray(){
49        int[] result = new int[map.size()];
50        Object[] keys = keyArray();        
51        for(int i=0;i<result.length;i++){
52            result[i] = getCount(keys[i]);
53        }

54        
55        return result;
56    }

57    
58    public Object[] keyArray(){        
59        return map.keySet().toArray();
60    }

61    
62    public void remove(Object key){
63        if(map.containsKey(key)){
64            Integer i = (Integer)map.get(key);
65            int amount = i.intValue();
66            map.put(key,new Integer(amount<0?0:--amount));
67        }
    
68    }

69    
70    public void remove(Object key,int amount){
71        if(map.containsKey(key)){
72            Integer i = (Integer)map.get(key);
73            int amount2 = i.intValue();
74            map.put(key,new Integer(amount2-amount<0?0:amount2-amount));
75        }

76    }

77    
78    public int size(){
79        return map.size();
80    }

81}



榛戠伒 2005-06-01 21:11 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 达日县| 陵水| 饶平县| 彰武县| 鸡西市| 鞍山市| 临澧县| 北票市| 疏勒县| 台南县| 蕉岭县| 建阳市| 博罗县| 镇雄县| 徐闻县| 墨脱县| 封丘县| 淮阳县| 遵义县| 田东县| 米林县| 龙里县| 基隆市| 微山县| 迁西县| 滁州市| 崇义县| 阜新市| 云林县| 安阳市| 开远市| 武鸣县| 林口县| 关岭| 淮滨县| 横山县| 容城县| 浦县| 天等县| 华蓥市| 麦盖提县|