code: public boolean hasNext(Pattern pattern) {
          ensureOpen();
          if (pattern == null)
              throw new NullPointerException();
          hasNextPattern = null;
          saveState();
  
          while (true) {
              if (getCompleteTokenInBuffer(pattern) != null) {
                  matchValid = true;
                  cacheResult();
                  return revertState(true);
              }
              if (needInput)
                  readInput();
              else
                  return revertState(false);
          }
      }
docs: Returns true if the next complete token matches the specified pattern.
  A complete token is prefixed and postfixed by input that matches
  the delimiter pattern. This method may block while waiting for input.
  The scanner does not advance past any input.
  
  @param pattern the pattern to scan for
  @return true if and only if this scanner has another token matching
  the specified pattern
  @throws IllegalStateException if this scanner is closed