Sample

int-eadb85c48b69-I13

Lower every eligible classic and enhanced for loop to a while loop

Matched original source

Lines51

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6050–1; higher is more readable
Dorn0.5210–1; higher is more readable
Mi0.5180–1; higher is more readable
LLOC15Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol190–20; mean of three runs
BTTF0.6240–1; higher is more readable

Views

Source code

package com.google.common.graph; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; import com.google.common.collect.UnmodifiableIterator; import java.util.AbstractSet; import java.util.Map; import org.jspecify.annotations.Nullable; /** * A class to represent the set of edges connecting an (implicit) origin node to a target node. * * <p>The {@link #nodeToOutEdge} map means this class only works on networks without parallel edges. * See {@link MultiEdgesConnecting} for a class that works with parallel edges. * * @author James Sexton * @param <E> Edge parameter type */ final class EdgesConnecting<E> extends AbstractSet<E> { private final Map<?, E> nodeToOutEdge; private final Object targetNode; EdgesConnecting(Map<?, E> nodeToEdgeMap, Object targetNode) { this.nodeToOutEdge = checkNotNull(nodeToEdgeMap); this.targetNode = checkNotNull(targetNode); } @Override public UnmodifiableIterator<E> iterator() { E connectingEdge = getConnectingEdge(); return (connectingEdge == null) ? ImmutableSet.<E>of().iterator() : Iterators.singletonIterator(connectingEdge); } @Override public int size() { return getConnectingEdge() == null ? 0 : 1; } @Override public boolean contains(@Nullable Object edge) { E connectingEdge = getConnectingEdge(); return connectingEdge != null && connectingEdge.equals(edge); } private @Nullable E getConnectingEdge() { return nodeToOutEdge.get(targetNode); } }

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.1511.099−49.866
Source linesThe number of non-empty source lines.51+20.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.818−7.228

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

Score0.605

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.99.808+0.806
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.52−0.805
Indentation frequencyHow rapidly indentation changes from line to line.43+0.75
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.981−0.57
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.43−0.566
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.50.762+0.3
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.087+0.1

Intercept 0.07 + feature contributions = 0.086 (log-odds).
Score = sigmoid(0.086) = 0.521.

Score0.518
Score15
Run 1

The code is highly readable. The class has a clear, single responsibility and is well-documented. The structure is logical, with a private helper method (getConnectingEdge) eliminating duplication. Nesting is minimal — all methods are flat, with only simple null checks. Intent is unambiguous: the class represents edges connecting two nodes in a graph without parallel edges. The code length is appropriate, with concise methods and no unnecessary verbosity. Each line performs a single logical action, and the reading flow is natural — constructor, iterator, size, contains, then the private helper. The only minor point is the conditional expression in iterator() spans multiple lines, but the formatting is standard and readable. Overall, this is exemplary clean Java code.

Run 2

The code is highly readable with clear structure and intent. The class has a single, well-documented responsibility: representing edges from an implicit origin to a target node in a network without parallel edges. The constructor validates inputs using Preconditions, and each method is concise with focused, single-purpose logic. Nesting is minimal—only simple ternary expressions are used, maintaining flat control flow. The private helper method getConnectingEdge() reduces duplication and improves clarity. Javadoc and @Nullable annotations enhance understanding of edge cases. The iterator method leverages Guava utilities effectively. Minor deductions for the slightly terse ternary usage and reliance on Guava-specific APIs, which may require familiarity with the library.

Run 3

The code is well-structured, with clear separation of concerns and a simple, flat hierarchy. Nesting is minimal, with only one ternary expression and no deep indentation. The intent is evident from the class name, Javadoc, and method names, making the purpose unambiguous. Code length is concise, avoiding unnecessary verbosity while maintaining clarity. Action granularity is appropriate, with most methods performing a single logical operation per line or per method. The reading flow is logical: constructor, iterator, size, contains, then the private helper. Null checks via Preconditions and the @Nullable annotation add clarity. Overall, the code is highly readable, with only minor potential improvements like extracting the repeated getConnectingEdge() calls if performance or readability were a concern.

Run 1

Code Structure: A focused class with logically grouped fields, constructor, set operations, and a private lookup helper. Nesting: Essentially flat; simple conditional expressions avoid nested control flow. Clarity of intent: Descriptive names and documentation clearly explain the edge-set abstraction and its restriction against parallel edges. Code length: Concise, with short methods and little redundancy. Action granularity: Each statement performs one clear action; conditional expressions remain easy to understand. Reading flow: Natural progression from initialization to public behavior and implementation detail. Minor readability costs come from the multiline ternary in iterator() and the slightly inconsistent nodeToEdgeMap/nodeToOutEdge naming.

Run 2

Code Structure: Fields, constructor, overridden set operations, and a shared lookup helper are logically organized. Nesting: Methods are flat, with simple conditional expressions and no nested control flow. Clarity of intent: Descriptive names and class documentation clearly explain the single-edge model and restriction against parallel edges. Code length: The implementation is concise without sacrificing clarity; the helper avoids repeating the map lookup expression. Action granularity: Each statement performs a focused operation, with only straightforward conditional logic combined in return expressions. Reading flow: The progression from initialization to public operations and the private helper is natural. Minor readability costs come from the multiline ternary in iterator() and the inconsistent naming between nodeToEdgeMap and nodeToOutEdge.

Run 3

Code Structure: Fields, constructor, collection overrides, and a private lookup helper are logically organized. Nesting: Methods are flat, with only simple conditional expressions. Clarity of intent: Descriptive names and class documentation clearly explain the single-edge set abstraction and its restriction against parallel edges. Code length: The implementation is concise without unnecessary logic or repetition. Action granularity: Statements generally perform one action per line; conditional expressions remain compact and understandable. Reading flow: Consistent formatting and straightforward method bodies make the code easy to follow. Minor readability costs come from the multiline ternary in iterator() and the constructor parameter name differing from the corresponding field name.