Guava 23 `edgeValueOrDefault` missing edge returns non-default value
See original GitHub issueIn Guava 23…
Assume nodeA
exists but #nodeU
does not exist. Execute:
graph.edgeValueOrDefault(nodeA, nodeU, 5)
The result is null
. I would expect the result to be 5
, given that there is no edge between nodeA
and non-existent nodeU
. Guava 22 an earlier have the expected behavior.
I see that Guava 23 now returns an Optional
for edgeValue
, so the statement can easily be converted to graph.edgeValue(nodeA, nodeU, 5).orElse(5)
, however if this is the intended behavior of the edgeValueOrDefault
method for this situation, it deserves some additional explanation in the Javadoc. Or simply deprecate this method and recommend people transition to edgeValue().orElse()
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
ValueGraph (Guava: Google Core Libraries for Java 22.0 API)
An interface for graph-structured data, whose edges have associated non-unique values. A graph is composed of a set of nodes and a set...
Read more >com.google.common.graph.ValueGraph.edgeValueOrDefault ...
Returns the value of the edge that connects endpoints (in the order, if any, specified by endpoints), if one is present; otherwise, returns...
Read more >Network (Guava: Google Core Libraries for Java 22.0 API)
An interface for graph-structured data, whose edges are unique objects. ... Returns the edges whose incident nodes in this network include node ....
Read more >Graphs (Guava: Google Core Libraries for Java 20.0 API)
Returns true if graph has at least one cycle. A cycle is defined as a non-empty subset of edges in a graph arranged...
Read more >graph api in guava 20.0 does not include edge as an object
As you can see, edge in a graph is an EndpointPair of two nodes. Internal data structure for this edge contains start node...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed (see above commit). Thanks, @rocketraman.
Somehow I completely failed to notice this issue previously; my apologies.
The behavior of
edgeValueOrDefault()
wasn’t intended to change from 22.0 to 23.0; I introduced a regression when doing some internal refactoring that apparently wasn’t caught by our tests. Sorry about that.I’ll get a fix out for that as soon as I can.