battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Share
 

 java pauser class

Go down 
AuthorMessage
Moti Barski

Moti Barski

Posts : 316
Join date : 2011-08-02

java pauser class Empty
PostSubject: java pauser class   java pauser class EmptyTue Jan 22, 2019 10:13 pm

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:

_________________
MB over and out emp it up
Back to top Go down
View user profile
 
java pauser class
Back to top 
Page 1 of 1
 Similar topics
-
» Retrieving number of rows in a table

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: