Advertisement
spigotdev

Untitled

Dec 19th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package com.AsylumDevs.AsylumMines.Utils;
  2.  
  3. import java.util.Arrays;
  4. import java.util.function.Predicate;
  5.  
  6. class TimeScanner {
  7. private char[] time;
  8. private int index = 0;
  9.  
  10. public TimeScanner(String time) {
  11. this.time = time.toCharArray();
  12. }
  13.  
  14. public boolean hasNext() {
  15. return this.index < this.time.length - 1;
  16. }
  17.  
  18. public long nextLong() {
  19. return Long.parseLong(String.valueOf(this.next(Character::isDigit)));
  20. }
  21.  
  22. public String nextString() {
  23. return String.valueOf(this.next(Character::isAlphabetic));
  24. }
  25.  
  26. private char[] next(Predicate<Character> whichSatisfies) {
  27. int startIndex = this.index;
  28. while (++this.index < this.time.length && whichSatisfies.test(Character.valueOf(this.time[this.index]))) {
  29. }
  30. return Arrays.copyOfRange(this.time, startIndex, this.index);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement