-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToken.java
More file actions
55 lines (43 loc) · 1006 Bytes
/
Copy pathToken.java
File metadata and controls
55 lines (43 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.Map;
//import java.util.ArrayList;
import java.util.HashMap;
public class Token{
private Map<String, Integer> tokens = new HashMap<>();
private int amount = 0;
public Token(){}
// 新增值到Map-tokens
public void addMap(String token) {
if(tokens.containsKey(token)) {
int timeTmp = tokens.get(token);
timeTmp++;
tokens.replace(token, timeTmp);
} else {
tokens.put(token, 1);
}
// System.out.println("addMap: "+token);
addAmount();
}
// 印出Map-tokens
public void pMap() {
System.out.println(tokens);
}
// 增加數量
public void addAmount() {
amount++;
}
// 確認token是否已被宣告
public boolean token_defined(String t){
if(tokens.containsKey(t)){
return true;
}
return false;
}
// get amount
public int get_Amount(){
return this.amount;
}
// get Map<String, Integer>
public Map<String, Integer> get_TokenMap(){
return this.tokens;
}
}