Sample

int-685e079a5885-I12

Inline all eligible single-use intermediate local variables

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 Pro180–20; mean of three runs
GPT-6.1 Sol180–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. The structure is logical and well-organized, with a clear class purpose documented in Javadoc. The method is concise and purpose-built. Nesting is shallow, with a single if-else chain inside an outer if that handles primitive types. Intent is immediately clear: return the JLS default for a given type. Action granularity is consistent, with one meaningful operation per line (cast and return). The reading flow is natural, checking non-null first, then handling primitives, and finally returning null for objects. The if-else chain is straightforward and avoids unnecessary complexity. Minor deductions: using both primitive wrappers and constants (FLOAT_DEFAULT, DOUBLE_DEFAULT) without explanation slightly breaks consistency, and repeated 'return (T)' casts add some visual noise. Overall, excellent readability in a utility method.

Run 3

The code is highly readable. Structure is logical: a final utility class with a private constructor, clear constant declarations, and a single-purpose method. Nesting is shallow—a two-level if/else chain is manageable given the unavoidable enumeration of primitives. Intent is clearly documented via Javadoc and method naming. Code length is appropriate; it handles all eight primitive types without redundancy. Each return statement is on its own line, maintaining action granularity. Reading flow is natural: null check, primitive verification, type-by-type dispatch, then fallback null return. The only minor blemish is the repetitive if/else chain, but a switch would not materially improve clarity for Class objects. Overall, this is a model of straightforward utility code.

Run 1

Code Structure: A well-organized utility class with a single focused method, clearly separated constants, and useful documentation. Nesting: Limited to two conditional levels; the primitive-type guard adds minor indentation. Clarity of intent: Descriptive names and Javadoc make the purpose and special cases explicit, though generic casts introduce slight complexity. Code length: Appropriately concise; the repetitive conditional chain is justified by distinct primitive types. Action granularity: Each statement performs one clear action, with no crowded lines. Reading flow: Validation, primitive checks, type-specific returns, and the null fallback follow a natural sequence. Minor drawbacks are the long else-if chain and lack of spacing between package and import sections.

Run 2

Code Structure: A focused utility class with clearly organized constants and a single public method. Nesting: Only two levels, though the outer primitive check adds some indentation. Clarity of intent: Descriptive names and precise documentation make the default-value behavior explicit; generic casts introduce minor complexity. Code length: Appropriately concise, with repetitive branches justified by distinct primitive types. Action granularity: Each statement performs one clear action, and each branch returns a single value. Reading flow: Validation, primitive dispatch, and the null fallback follow a natural sequence. Minor drawbacks are the lengthy else-if chain and cramped spacing around the package and imports.

Run 3

Code Structure: A focused utility class with logically organized constants and a single public method. Nesting: Only two conditional levels, though the outer primitive check adds slight indentation. Clarity of intent: Descriptive names and precise documentation clearly explain the default-value behavior, including null for void and reference types. Code length: Appropriately concise; the repetitive type checks are straightforward and justified. Action granularity: Each check and return performs one clear action, with no crowded statements. Reading flow: Validation, primitive handling, and the final null fallback follow a natural sequence. Minor drawbacks are the lengthy else-if chain and unchecked generic casts, which require some Java type-system knowledge.