File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ class AuthenticationManager {
2
+
3
+ Map <String , Integer > map ;
4
+ int timeToLive ;
5
+
6
+ public AuthenticationManager (int timeToLive ) {
7
+ map = new HashMap <>();
8
+ this .timeToLive = timeToLive ;
9
+ }
10
+
11
+ public void generate (String tokenId , int currentTime ) {
12
+ map .put (tokenId , currentTime );
13
+ }
14
+
15
+ public void renew (String tokenId , int currentTime ) {
16
+ if (map .containsKey (tokenId ) && map .get (tokenId ) + timeToLive > currentTime ) {
17
+ map .put (tokenId , currentTime );
18
+ }
19
+ }
20
+
21
+ public int countUnexpiredTokens (int currentTime ) {
22
+ return (int ) map .entrySet ().stream ()
23
+ .filter (entry -> entry .getValue () + timeToLive > currentTime ).count ();
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Your AuthenticationManager object will be instantiated and called as such:
29
+ * AuthenticationManager obj = new AuthenticationManager(timeToLive);
30
+ * obj.generate(tokenId,currentTime);
31
+ * obj.renew(tokenId,currentTime);
32
+ * int param_3 = obj.countUnexpiredTokens(currentTime);
33
+ */
You can’t perform that action at this time.
0 commit comments