码迷,mamicode.com
首页 > 其他好文 > 详细

Logger Rate Limiter

时间:2016-06-27 13:48:16      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

 1 public class Logger {
 2     private Map<String, Integer> data;
 3     /** Initialize your data structure here. */
 4     public Logger() {
 5         data = new HashMap<>();
 6     }
 7     
 8     /** Returns true if the message should be printed in the given timestamp, otherwise returns false.
 9         If this method returns false, the message will not be printed.
10         The timestamp is in seconds granularity. */
11     public boolean shouldPrintMessage(int timestamp, String message) {
12         if (!data.containsKey(message) || timestamp - data.get(message) >= 10) {
13             data.put(message, timestamp);
14             return true;
15         }
16         return false;
17     }
18 }
19 
20 /**
21  * Your Logger object will be instantiated and called as such:
22  * Logger obj = new Logger();
23  * boolean param_1 = obj.shouldPrintMessage(timestamp,message);
24  */

 

Logger Rate Limiter

标签:

原文地址:http://www.cnblogs.com/shuashuashua/p/5619852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!