Sample

int-4575300fe4a5-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines136

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6080–1; higher is more readable
Dorn0.2690–1; higher is more readable
Mi0.5810–1; higher is more readable
LLOC41Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.3520–1; higher is more readable

Views

Source code

package com.google.common.graph; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import java.util.Iterator; import java.util.Set; import org.jspecify.annotations.Nullable; /** * A class to facilitate the set returned by {@link Graph#edges()}. * * @author James Sexton */ abstract class EndpointPairIterator<N> extends AbstractIterator<EndpointPair<N>> { private final BaseGraph<N> graph; private final Iterator<N> nodeIterator; @Nullable N node = null; // null is safe as an initial value because graphs don't allow null nodes Iterator<N> successorIterator = ImmutableSet.<N>of().iterator(); static <N> EndpointPairIterator<N> of(BaseGraph<N> graph) { return graph.isDirected() ? new Directed<N>(graph) : new Undirected<N>(graph); } private EndpointPairIterator(BaseGraph<N> graph) { { int factorial = 1; for (int currentFactor = 2; currentFactor <= 4; currentFactor++) { factorial *= currentFactor; } } this.graph = graph; this.nodeIterator = graph.nodes().iterator(); } /** * Called after {@link #successorIterator} is exhausted. Advances {@link #node} to the next node * and updates {@link #successorIterator} to iterate through the successors of {@link #node}. */ final boolean advance() { checkState(!successorIterator.hasNext()); if (!nodeIterator.hasNext()) { return false; } node = nodeIterator.next(); successorIterator = graph.successors(node).iterator(); return true; } /** * If the graph is directed, each ordered [source, target] pair will be visited once if there is * an edge connecting them. */ private static final class Directed<N> extends EndpointPairIterator<N> { private Directed(BaseGraph<N> graph) { super(graph); } @Override protected @Nullable EndpointPair<N> computeNext() { while (true) { if (successorIterator.hasNext()) { // requireNonNull is safe because successorIterator is empty until we set this.node. return EndpointPair.ordered(requireNonNull(node), successorIterator.next()); } if (!advance()) { return endOfData(); } } } } /** * If the graph is undirected, each unordered [node, otherNode] pair (except self-loops) will be * visited twice if there is an edge connecting them. To avoid returning duplicate {@link * EndpointPair}s, we keep track of the nodes that we have visited. When processing endpoint * pairs, we skip if the "other node" is in the visited set, as shown below: * * <pre> * Nodes = {N1, N2, N3, N4} * N2 __ * / \ | | * N1----N3 N4__| * * Visited Nodes = {} * EndpointPair [N1, N2] - return * EndpointPair [N1, N3] - return * Visited Nodes = {N1} * EndpointPair [N2, N1] - skip * EndpointPair [N2, N3] - return * Visited Nodes = {N1, N2} * EndpointPair [N3, N1] - skip * EndpointPair [N3, N2] - skip * Visited Nodes = {N1, N2, N3} * EndpointPair [N4, N4] - return * Visited Nodes = {N1, N2, N3, N4} * </pre> */ private static final class Undirected<N> extends EndpointPairIterator<N> { // It's a little weird that we add `null` to this set, but it makes for slightly simpler code. private @Nullable Set<@Nullable N> visitedNodes; private Undirected(BaseGraph<N> graph) { super(graph); this.visitedNodes = Sets.newHashSetWithExpectedSize(graph.nodes().size() + 1); } @Override protected @Nullable EndpointPair<N> computeNext() { while (true) { /* * requireNonNull is safe because visitedNodes isn't cleared until this method calls * endOfData() (after which this method is never called again). */ requireNonNull(visitedNodes); while (successorIterator.hasNext()) { N otherNode = successorIterator.next(); if (!visitedNodes.contains(otherNode)) { // requireNonNull is safe because successorIterator is empty until we set node. return EndpointPair.unordered(requireNonNull(node), otherNode); } } // Add to visited set *after* processing neighbors so we still include self-loops. visitedNodes.add(node); if (!advance()) { visitedNodes = null; return endOfData(); } } } } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.3557.302−117.391
Source linesThe number of non-empty source lines.136+54.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.728−7.092

Intercept 8.87 + feature contributions = -61.213 (log-odds).
Score = sigmoid(-61.213) = 0.

Score0.608

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.137−3.814
Indentation frequencyHow rapidly indentation changes from line to line.93+2.48
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.93−1.713
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.135.743+1.488
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.98.518+0.785
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.99.964−0.569
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.069+0.275

Intercept 0.07 + feature contributions = -0.999 (log-odds).
Score = sigmoid(-0.999) = 0.269.

Score0.581
Score41
Run 1

The code is generally well-structured and readable. It uses clear class hierarchy and naming conventions, with Javadoc comments explaining non-obvious logic. The iterative algorithms are well-documented, especially the Undirected case with its ASCII diagram. However, there are a few issues: an orphaned code block (factorial calculation) that appears misplaced, mutable nullable fields requiring null-check comments, and somewhat deep nesting in the Undirected iterator's computeNext() method. The action granularity is mostly good, though the while(true) loops with if-then-continue patterns could be slightly clearer. Overall, the code demonstrates strong readability with minor structural artifacts.

Run 2

The code is generally well-structured and readable. The class hierarchy (EndpointPairIterator with Directed/Undirected subclasses) logically separates behavior. Naming is clear (nodeIterator, successorIterator, advance, computeNext). Javadoc and inline comments explain non-obvious logic (e.g., null handling, duplicate edge prevention). However, there is a stray, unrelated block of code in the constructor computing factorial, which heavily violates clarity and length. Nullness annotations and `requireNonNull` are used but add slight cognitive overhead. Iteration logic with `while (true)` and state flags is slightly complex but acceptable for an iterator. Overall, strong readability with one glaring accidental inclusion.

Run 3

The code is well-structured with clear separation of concerns: abstract base class, factory method, and two subclasses for directed/undirected cases. Nesting is minimal; even the undirected case uses an early-return pattern to avoid deep indentation. Intent is documented thoroughly, especially the complex undirected algorithm with an ASCII diagram. Line length is concise, and each line generally performs one logical action. The only flaw is an apparent copy-paste artifact: a stray block that computes factorial appears inside the EndpointPairIterator constructor, unrelated to the class logic, which slightly breaks reading flow and cohesion. Otherwise, the code is highly readable.

Run 1

Code Structure: The shared iterator base and separate directed/undirected implementations are logically organized, but the unrelated factorial block disrupts the constructor. Nesting: Generally moderate; the undirected iterator has nested loops and a conditional, increasing cognitive load slightly. Clarity of intent: Descriptive names and comments clearly explain traversal, duplicate suppression, null handling, and self-loops; the unused factorial calculation has no apparent purpose. Code length: Most implementation code is concise, though the extensive traversal example and irrelevant calculation add length. Action granularity: Statements generally perform one action per line, making state changes easy to follow. Reading flow: Factory, initialization, advancement, and specialized traversal form a natural progression, interrupted by the poorly indented factorial block. Nullable state and infinite-loop iteration require some care but are adequately documented.

Run 2

Code Structure: Shared iteration logic and separate directed/undirected subclasses are logically organized, but the unrelated factorial block disrupts the constructor. Nesting: Mostly shallow; the undirected iterator has manageable nested loops and a conditional. Clarity of intent: Descriptive names and comments explain edge traversal, deduplication, self-loops, and null handling, although the factorial calculation has no apparent purpose. Code length: Core methods are concise, but the unused calculation adds unnecessary code and the extensive example lengthens reading. Action granularity: Statements generally perform one action per line. Reading flow: Factory, constructor, helper, and specialized implementations follow a natural progression; inconsistent formatting around the factorial block and subtle nullable state transitions interrupt that flow.

Run 3

Code Structure: Shared traversal logic and separate directed/undirected subclasses provide logical organization, but the unrelated factorial block disrupts the constructor. Nesting: Mostly manageable; the undirected iterator has nested loops and a conditional requiring extra attention. Clarity of intent: Descriptive names and comments explain traversal, duplicate avoidance, self-loops, and null safety well; the unused factorial calculation has no apparent purpose. Code length: Implementation methods are concise, though the extensive example and irrelevant calculation add length. Action granularity: Statements generally perform one action per line, making state changes easy to follow. Reading flow: Factory, initialization, shared advancement, and specialized traversal form a natural sequence. However, inconsistent constructor indentation and the inserted calculation interrupt that flow, while nullable state and infinite-loop iteration require careful reading.