相关疑难解决方法(0)

在Java中实现去抖动

对于我正在编写的一些代码,我可以debounce在Java中使用一个很好的通用实现.

public interface Callback {
  public void call(Object arg);
}

class Debouncer implements Callback {
    public Debouncer(Callback c, int interval) { ... }

    public void call(Object arg) { 
        // should forward calls with the same arguments to the callback c
        // but batch multiple calls inside `interval` to a single one
    }
}
Run Code Online (Sandbox Code Playgroud)

当使用相同的参数call()多次以interval毫秒为单位调用时,应该只调用一次回调函数.

可视化:

Debouncer#call  xxx   x xxxxxxx        xxxxxxxxxxxxxxx
Callback#call      x           x                      x  (interval is 2)
Run Code Online (Sandbox Code Playgroud)
  • 在某些Java标准库中是否存在(某种类似的)?
  • 你会如何实现?

java algorithm

22
推荐指数
2
解决办法
1万
查看次数

标签 统计

algorithm ×1

java ×1