java pauser class 2s3mco

this class will be used to pause processes that run repeatedly.
it is very simple and very useful

Code:


public class Pauser {
 private int limit;
 private int counter;

 public int getLimit() {
 return limit;
 }

 public void setLimit(int limit) {
 this.limit = limit;
 }

 public Pauser(int limit) {
 super();
 this.limit = limit;
 this.counter = 0;
 }

 public Boolean pause() {
 if (counter == limit) {
 counter = 0;
 return false;
 } else {
 counter++;
 }
 return true;
 }
}


example :

Code:

Pauser p1 = new Pauser(2);
 System.out.println(p1.pause());
 System.out.println(p1.pause());
 System.out.println(p1.pause());
 System.out.println(p1.pause());
 System.out.println(p1.pause());
 System.out.println(p1.pause());
 System.out.println(p1.pause());
 System.out.println(p1.pause());

output :
true
true
false
true
true
false
true
true

hadouken ! :tu: