look code
这是一个漏桶
package bucket;
public class LeakyBucket {
//桶容量
private int maxVolume;
//流出速率
private int maxOutSpeed;
//当前容量
private int volume;
//当前流出量
private int stream;
public LeakyBucket() {
this.maxVolume = 10;
this.maxOutSpeed = 2;
this.volume = 0;
this.stream = 0;
}
//流入一滴水
public boolean inputWater(){
if (volume < maxVolume){
volume++;
return true;
}
return false;
}
//流出一滴水,添加一滴当前流出量
public boolean outputWater(){
if(volume >0){
if (stream < maxOutSpeed){
stream++;
volume--;
return true;
}
return false;
}
System.err.println("当前容量异常");
return false;
}
//任务完成减少流量
public void