Skip to content

Commit

Permalink
Minor renaming, shuffling/reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 30, 2024
1 parent 3986751 commit 0307057
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 66 deletions.
26 changes: 13 additions & 13 deletions src/main/java/tools/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,10 @@ public boolean hasNonNull(int index) {
public final Iterator<JsonNode> iterator() { return values(); }

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

/**
* Method for accessing all value nodes of this Node, iff
Expand All @@ -997,7 +997,7 @@ public Iterator<JsonNode> values() {
*
* @since 3.0
*/
public Spliterator<JsonNode> valuesSpliterator() {
public Spliterator<JsonNode> valueSpliterator() {
return Spliterators.spliteratorUnknownSize(values(), Spliterator.ORDERED);
}

Expand All @@ -1011,16 +1011,7 @@ public Spliterator<JsonNode> valuesSpliterator() {
*/
@Deprecated // since 2.19
public Iterator<Map.Entry<String, JsonNode>> fields() {
return ClassUtil.emptyIterator();
}

/**
* @return <code>Spliterator</code> 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>> fieldsSpliterator() {
return Spliterators.spliteratorUnknownSize(fields(), Spliterator.ORDERED);
return properties().iterator();
}

/**
Expand All @@ -1039,6 +1030,15 @@ 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
34 changes: 17 additions & 17 deletions src/main/java/tools/jackson/databind/node/ArrayNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,6 @@ public int size() {
@Override // since 2.10
public boolean isEmpty() { return _children.isEmpty(); }

/**
* {@inheritDoc}
*<p>
* NOTE: actual underlying implementation returns {@link java.util.ListIterator}
* from {@link java.util.List#listIterator()} that contains elements, since Jackson 2.18
* (before was only generic {@link java.util.Iterator}).
*/
@Override
public Iterator<JsonNode> values() {
return _children.listIterator();
}

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

@Override
public JsonNode get(int index) {
if ((index >= 0) && (index < _children.size())) {
Expand Down Expand Up @@ -265,6 +248,23 @@ public JsonNode required(int index) {
index, _children.size());
}

/**
* {@inheritDoc}
*<p>
* NOTE: actual underlying implementation returns {@link java.util.ListIterator}
* from {@link java.util.List#listIterator()} that contains elements, since Jackson 2.18
* (before was only generic {@link java.util.Iterator}).
*/
@Override
public Iterator<JsonNode> values() {
return _children.listIterator();
}

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

@Override // @since 2.19
public Stream<JsonNode> valueStream() {
return _children.stream();
Expand Down
56 changes: 22 additions & 34 deletions src/main/java/tools/jackson/databind/node/ObjectNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,6 @@ public int size() {
@Override
public boolean isEmpty() { return _children.isEmpty(); }

@Override
public Iterator<JsonNode> values() {
return _children.values().iterator();
}

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

@Override
public JsonNode get(int index) { return null; }

Expand All @@ -248,16 +238,6 @@ public JsonNode get(String propertyName) {
return _children.get(propertyName);
}

@Override
public Iterator<String> propertyNames() {
return _children.keySet().iterator();
}

@Override
public Spliterator<String> propertyNamesSpliterator() {
return _children.keySet().spliterator();
}

@Override
public JsonNode path(int index) {
return MissingNode.getInstance();
Expand All @@ -282,21 +262,29 @@ public JsonNode required(String propertyName) {
return _reportRequiredViolation("No value for property '%s' of `ObjectNode`", propertyName);
}

/**
* Method to use for accessing all properties (with both names
* and values) of this JSON Object.
*
* @deprecated since 2.19 Use instead {@link #properties()}.
*/
@Deprecated // since 2.19
@Override
public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
public Iterator<JsonNode> values() {
return _children.values().iterator();
}

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

@Override // @since 2.19
public Stream<JsonNode> valueStream() {
return _children.values().stream();
}

@Override
public Iterator<String> propertyNames() {
return _children.keySet().iterator();
}

@Override
public Spliterator<String> propertyNameSpliterator() {
return _children.keySet().spliterator();
}

/**
Expand All @@ -310,9 +298,9 @@ public Set<Map.Entry<String, JsonNode>> properties() {
return _children.entrySet();
}

@Override // @since 2.19
public Stream<JsonNode> valueStream() {
return _children.values().stream();
@Override
public Spliterator<Map.Entry<String, JsonNode>> propertySpliterator() {
return _children.entrySet().spliterator();
}

@Override // @since 2.19
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/tools/jackson/databind/node/ArrayNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public void testDirectCreation() throws Exception

assertStandardEquals(n);
assertFalse(n.values().hasNext());
assertEquals(0, n.valuesSpliterator().estimateSize());
assertEquals(0, n.valueSpliterator().estimateSize());
assertFalse(n.propertyNames().hasNext());
assertNotNull(n.propertyNamesSpliterator());
assertNotNull(n.propertyNameSpliterator());
assertTrue(n.isEmpty());
TextNode text = TextNode.valueOf("x");
n.add(text);
Expand Down

0 comments on commit 0307057

Please sign in to comment.