首页 > 其他 > 详细

Logger Rate Limiter

时间:2016-06-27 13:47:49      阅读:268      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!