-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvtoken.py
60 lines (52 loc) · 1.47 KB
/
pvtoken.py
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
56
57
58
59
60
class PvToken:
def __init__(self, token_id, token_value):
"""
:param token_id:
:type token_id: int
:param token_value: token value
:type token_value: str
"""
self.id = token_id
self.value = token_value
def __str__(self):
return 'Token(' + str(self.id) + ',' + str(self.value) + ')'
def get_id(self):
"""
Return the token id
:return: token id
:rtype: int
"""
return self.id
def get_value(self):
"""
Return the token value
:return: token value
:rtype: str
"""
return str(self.value)
def match(self, token_id):
"""
Check whether a token has a certain id
:param token_id: token id
:type token_id: int
:return true if token id matches the specified id
:rtype: bool
"""
return True if self.id == token_id else False
def is_in(self, token_id_list):
"""
Check whether a token id is in a list of possible id's
:param token_id_list: list of token id's
:type token_id_list: list
:return: true if the token id is in the list
:rtype: bool
"""
return True if self.id in token_id_list else False
if __name__ == '__main__':
t1 = PvToken(1, "23")
t2 = PvToken(2, "abc")
t3 = PvToken(1, "hello")
print(t1 == t2)
print(t1 == t3)
print(t2.match(2))
print(t2.match(4))