Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.io.Serializable;
  2. import java.util.Date;
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. public final class FixdedDelayJobData implements Serializable {
  6.  
  7. private static final long serialVersionUID = 1L;
  8.  
  9. private long delay;
  10. private TimeUnit delayUnit;
  11.  
  12. public FixdedDelayJobData(long delay) {
  13. this(delay, TimeUnit.SECONDS);
  14. }
  15.  
  16. public FixdedDelayJobData(long delay, final TimeUnit delayUnit) {
  17. if (delay == 0) {
  18. throw new IllegalArgumentException("Delay cannot be zero");
  19. }
  20. if (delayUnit == null) {
  21. throw new IllegalArgumentException("Delay Unit should be provided");
  22. }
  23. this.delay = delay;
  24. this.delayUnit = delayUnit;
  25. }
  26.  
  27. public Date getNextScheduleDate() {
  28. return new Date(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, delayUnit));
  29. }
  30.  
  31. @Override
  32. public String toString() {
  33. return "FixdedDelayJobData [delay=" + delay + ", delayUnit=" + delayUnit + "]";
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement