Skip to content

Commit

Permalink
no need for spliterator methods when collections are public (#4882)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Jan 4, 2025
1 parent 1e0aa7c commit 25f39ae
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 47 deletions.
2 changes: 0 additions & 2 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ Versions: 3.x (for earlier see VERSION-2.x)
#4820: Change JDK baseline for Jackson 3.0 from Java 8 to Java 17
#4835: Remove dynamic work-arounds wrt accessing `Record` definition
#4840: Increase minimum Android SDK required to 34 for Jackson 3.0
#4865: Add spliterator support in `JsonNode`
(contributed by @pjfanning)
#4875: Remove `JsonNode.fields()` from 3.0
#4879: Rename `TextNode` as `StringNode`; `JsonNode.xxxTextYyy()` (mostly) as
`JsonNode.xxxStringYyy()` [JSTEP-3]
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/tools/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -1050,18 +1050,14 @@ public boolean hasNonNull(int index) {
*/

/**
* Same as calling {@link #values()}; implemented so that
* convenience "for-each" loop can be used for looping over elements
* Implemented so that convenience "for-each" loop can be used for looping over elements
* of JSON Array constructs.
*/
@Override
public final Iterator<JsonNode> iterator() { return values().iterator(); }

/**
* Same as calling {@link #valueSpliterator()}.
*/
@Override
public final Spliterator<JsonNode> spliterator() { return valueSpliterator(); }
public final Spliterator<JsonNode> spliterator() { return values().spliterator(); }

/**
* Method for accessing all value nodes of this Node, iff
Expand All @@ -1073,18 +1069,6 @@ public Collection<JsonNode> values() {
return Collections.emptyList();
}

/**
* Method for accessing all value nodes of this Node, iff
* this node is a JSON Array or Object node. In case of Object node,
* field names (keys) are not included, only values.
* For other types of nodes, returns empty <code>Spliterator</code>.
*
* @since 3.0
*/
public Spliterator<JsonNode> valueSpliterator() {
return values().spliterator();
}

/**
* Accessor that will return properties of {@code ObjectNode}
* similar to how {@link Map#entrySet()} works;
Expand All @@ -1098,15 +1082,6 @@ public Set<Map.Entry<String, JsonNode>> properties() {
return Collections.emptySet();
}

/**
* @return {@code Spliterator} that can be used to traverse all key/value pairs
* for object nodes; empty spliterator (no contents) for other types
* @since 3.0
*/
public Spliterator<Map.Entry<String, JsonNode>> propertySpliterator() {
return properties().spliterator();
}

/**
* Returns a stream of all value nodes of this Node, iff
* this node is an {@code ArrayNode} or {@code ObjectNode}.
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/tools/jackson/databind/node/ArrayNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,12 @@ public JsonNode required(int index) {
/**
* {@inheritDoc}
*<p>
* NOTE: actual underlying implementation returns {@link java.util.ListIterator}
* from {@link java.util.List#listIterator()} that contains elements.
* NOTE: this returns the live <code>List</code> and not a copy.
*/
@Override
public Collection<JsonNode> values() {
return _children;
}

@Override
public Spliterator<JsonNode> valueSpliterator() {
return _children.spliterator();
}

@Override
public Stream<JsonNode> valueStream() {
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/tools/jackson/databind/node/ObjectNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,6 @@ public Collection<JsonNode> values() {
return _children.values();
}

@Override
public Spliterator<JsonNode> valueSpliterator() {
return _children.values().spliterator();
}

@Override // @since 2.19
public Stream<JsonNode> valueStream() {
return _children.values().stream();
Expand All @@ -302,11 +297,6 @@ public Set<Map.Entry<String, JsonNode>> properties() {
return _children.entrySet();
}

@Override
public Spliterator<Map.Entry<String, JsonNode>> propertySpliterator() {
return _children.entrySet().spliterator();
}

@Override // @since 2.19
public Stream<Map.Entry<String, JsonNode>> propertyStream() {
return _children.entrySet().stream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void testDirectCreation() throws Exception

assertStandardEquals(n);
assertFalse(n.values().iterator().hasNext());
assertEquals(0, n.valueSpliterator().estimateSize());
assertTrue(n.propertyNames().isEmpty());
assertTrue(n.isEmpty());
StringNode text = StringNode.valueOf("x");
Expand Down

0 comments on commit 25f39ae

Please sign in to comment.