MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / hasNext

Method hasNext

java/src/org/openqa/selenium/json/JsonInput.java:353–384  ·  view source on GitHub ↗

Determine whether an element is pending for the current container from the JSON input stream. @return true if an element is pending; otherwise false @throws JsonException if no container is open @throws UncheckedIOException if an I/O exception is encountered

()

Source from the content-addressed store, hash-verified

351 * @throws UncheckedIOException if an I/O exception is encountered
352 */
353 public boolean hasNext() {
354 if (stack.isEmpty()) {
355 throw new JsonException(
356 "Unable to determine if an item has next when not in a container type. " + input);
357 }
358
359 skipWhitespace(input);
360 boolean seenElement = Boolean.TRUE.equals(containerHasElement.peekFirst());
361
362 if (input.peek() == ',') {
363 if (!seenElement) {
364 throw new JsonException("Unexpected ',' before first element of container. " + input);
365 }
366 input.read();
367 // We've moved past the separator, so we're once again expecting an element rather than
368 // another comma. Clear the flag so a repeat hasNext() before reading is a no-op.
369 clearSeenElement();
370 skipWhitespace(input);
371 JsonType afterComma = peek();
372 // Trailing comma leniency: '[1,]' and '{"a":1,}' are accepted.
373 return afterComma != JsonType.END_COLLECTION && afterComma != JsonType.END_MAP;
374 }
375
376 JsonType type = peek();
377 if (type == JsonType.END_COLLECTION || type == JsonType.END_MAP) {
378 return false;
379 }
380 if (seenElement) {
381 throw new JsonException("Expected ',' or end of container but saw " + type + ". " + input);
382 }
383 return true;
384 }
385
386 /**
387 * Process the opening square bracket of a JSON array.

Calls 6

skipWhitespaceMethod · 0.95
peekMethod · 0.95
clearSeenElementMethod · 0.95
readMethod · 0.65
isEmptyMethod · 0.45
equalsMethod · 0.45