Sample

int-109590781a81-I13

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

Matched original source

Lines53

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8540–1; higher is more readable
Dorn0.4970–1; higher is more readable
Mi0.5840–1; higher is more readable
LLOC23Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol18.330–20; mean of three runs
BTTF0.4480–1; higher is more readable

Views

Source code

package com.google.common.base; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import org.jspecify.annotations.Nullable; /** * This class provides default values for all Java types, as defined by the JLS. * * @author Ben Yu * @since 1.0 */ @J2ktIncompatible @GwtIncompatible public final class Defaults { private Defaults() {} private static final Double DOUBLE_DEFAULT = 0d; private static final Float FLOAT_DEFAULT = 0f; /** * Returns the default value of {@code type} as defined by JLS --- {@code 0} for numbers, {@code * false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types and * {@code void}, {@code null} is returned. */ @SuppressWarnings({ "unchecked", "BooleanLiteral" // `(T) false` would produce an error }) public static <T> @Nullable T defaultValue(Class<T> type) { checkNotNull(type); if (type.isPrimitive()) { if (type == boolean.class) { return (T) Boolean.FALSE; } else if (type == char.class) { return (T) Character.valueOf('\0'); } else if (type == byte.class) { return (T) Byte.valueOf((byte) 0); } else if (type == short.class) { return (T) Short.valueOf((short) 0); } else if (type == int.class) { return (T) Integer.valueOf(0); } else if (type == long.class) { return (T) Long.valueOf(0L); } else if (type == float.class) { return (T) FLOAT_DEFAULT; } else if (type == double.class) { return (T) DOUBLE_DEFAULT; } } return null; } }

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.1795.802−59.261
Source linesThe number of non-empty source lines.53+21.2
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.895−7.343

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

Score0.854

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.54−0.876
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97.981+0.776
Indentation frequencyHow rapidly indentation changes from line to line.43+0.75
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.43−0.566
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.97.981−0.485
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.52.848+0.329
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.098−0.012

Intercept 0.07 + feature contributions = -0.013 (log-odds).
Score = sigmoid(-0.013) = 0.497.

Score0.584
Score23
Run 1

The code is highly readable. It has a clear, logical structure: a private constructor, constants, and a single public method. The method's Javadoc clearly explains the intent and edge cases. Nesting is shallow (only two levels), and action granularity is one action per line within the if-else chain. The chain of primitive type checks is explicit and follows a natural order, though it is somewhat verbose; a switch statement or map could reduce length, but the current form prioritizes clarity. The only minor drawbacks are the unchecked casts and the suppressions, which slightly obscure the type-safety rationale. Overall, the code is straightforward, self-documenting, and easy to follow.

Run 2

The code is highly readable. It has clear structure: a private constructor, documented constants, and a single well-named public method. The method checks for null, then uses a straightforward if-else chain for primitives, returning null for non-primitives and void. Nesting is shallow (two levels). Intent is explicit—mapping each primitive to its JLS default. The method is concise but could be slightly improved by replacing the long if-else chain with a switch expression or separate helper map. One action per line is mostly respected, and reading flow is natural: validate input, handle primitives in logical order, else return null. Minor points: the Javadoc explains behavior well, and comments note JLS intent. The only slightly verbose part is the repeated cast syntax, but this is necessary for generic return type. Overall, very maintainable and clear.

Run 3

The code is well-structured with clear intent: a utility class providing default values for Java types. The class is properly encapsulated with a private constructor, constants, and a single public method. Nesting is shallow—only two levels deep within the primitive type checks. The chain of `else if` statements is flat and readable, though somewhat repetitive. Each action is on its own line, and the reading flow is natural. The method is concise but could be improved by using a switch or map to reduce repetitive `else if` blocks. The Javadoc is helpful, and the annotations and imports are standard. Overall, the code is highly readable with minor opportunities for simplification.

Run 1

Code Structure: Well organized, with constants, a private constructor, and one focused public method. Nesting: Only two levels deep; the outer primitive check adds slight indentation but remains easy to follow. Clarity of intent: Descriptive names and precise documentation clearly explain default values, including null for reference types and void. Code length: Concise overall, though the repetitive type-check chain adds some length. Action granularity: Each check and return performs a single clear action, with no crowded statements. Reading flow: The method proceeds naturally from null validation to primitive-type handling and a final null fallback. Consistent formatting and explicit branches make behavior straightforward to inspect.

Run 2

Code Structure: A focused utility class with logically organized constants and a single public method. Nesting: Shallow overall, although the primitive check adds an extra level around the conditional chain. Clarity of intent: Descriptive names and precise documentation clearly explain default values, including null for reference types and void. Code length: Appropriately concise; the repetitive branches are straightforward rather than unnecessarily verbose. Action granularity: Each check and return performs one clear action, without compound statements. Reading flow: Validation, primitive dispatch, and the null fallback follow a natural sequence. Minor readability costs come from repeated generic casts, the long else-if chain, and tightly spaced package/import declarations.

Run 3

Code Structure: A well-organized utility class with constants and a single focused method. Nesting: Only two levels, though an early return for non-primitive types could flatten the method. Clarity of intent: Descriptive names and precise documentation clearly explain default values, including null for reference types and void. Code length: Appropriately concise; the repetitive conditional chain is straightforward and justified by explicit type handling. Action granularity: Each statement performs one clear action, with separate validation, comparisons, and returns. Reading flow: The method proceeds naturally from input validation to primitive-type dispatch and a null fallback. Minor readability costs come from unchecked generic casts and the slight inconsistency between cached floating-point defaults and directly constructed wrapper values.