Sample

int-8b1dd118477a-I13

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

Matched original source

Lines88

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6290–1; higher is more readable
Dorn0.450–1; higher is more readable
Mi0.1120–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol18.330–20; mean of three runs
BTTF0.4670–1; higher is more readable

Views

Source code

package com.google.common.collect; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.LinkedHashMap; import org.jspecify.annotations.Nullable; /** * A {@code Multiset} implementation with predictable iteration order. Its iterator orders elements * according to when the first occurrence of the element was added. When the multiset contains * multiple instances of an element, those instances are consecutive in the iteration order. If all * occurrences of an element are removed, after which that element is added to the multiset, the * element will appear at the end of the iteration. * * <p>See the Guava User Guide article on <a href= * "https://github.com/google/guava/wiki/NewCollectionTypesExplained#multiset">{@code Multiset}</a>. * * @author Kevin Bourrillion * @author Jared Levy * @since 2.0 */ @GwtCompatible public final class LinkedHashMultiset<E extends @Nullable Object> extends AbstractMapBasedMultiset<E> { /** Creates a new, empty {@code LinkedHashMultiset} using the default initial capacity. */ public static <E extends @Nullable Object> LinkedHashMultiset<E> create() { return new LinkedHashMultiset<>(); } /** * Creates a new, empty {@code LinkedHashMultiset} with the specified expected number of distinct * elements. * * @param distinctElements the expected number of distinct elements * @throws IllegalArgumentException if {@code distinctElements} is negative */ public static <E extends @Nullable Object> LinkedHashMultiset<E> create(int distinctElements) { return new LinkedHashMultiset<>(distinctElements); } /** * Creates a new {@code LinkedHashMultiset} containing the specified elements. * * <p>This implementation is highly efficient when {@code elements} is itself a {@link Multiset}. * * @param elements the elements that the multiset should contain */ public static <E extends @Nullable Object> LinkedHashMultiset<E> create( Iterable<? extends E> elements) { LinkedHashMultiset<E> multiset = create(Multisets.inferDistinctElements(elements)); Iterables.addAll(multiset, elements); return multiset; } private LinkedHashMultiset() { super(new LinkedHashMap<E, Count>()); } private LinkedHashMultiset(int distinctElements) { super(Maps.newLinkedHashMapWithExpectedSize(distinctElements)); } /** * @serialData the number of distinct elements, the first element, its count, the second element, * its count, and so on */ @GwtIncompatible @J2ktIncompatible private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); Serialization.writeMultiset(this, stream); } @GwtIncompatible @J2ktIncompatible private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); int distinctElements = stream.readInt(); setBackingMap(new LinkedHashMap<E, Count>()); Serialization.populateMultiset(this, stream, distinctElements); } @GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0; }

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.2055.329−67.826
Source linesThe number of non-empty source lines.88+35.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.81−7.216

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

Score0.629

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.89−2.115
Indentation frequencyHow rapidly indentation changes from line to line.60+1.338
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.60−0.956
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.87.891+0.819
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97.742+0.773
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.966−0.569
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.052+0.44

Intercept 0.07 + feature contributions = -0.2 (log-odds).
Score = sigmoid(-0.2) = 0.45.

Score0.112
Score19
Run 1

This code demonstrates excellent readability. The structure is logical, with clear separation of factory methods, constructors, and serialization logic. Javadoc documentation is thorough and helpful, particularly for public APIs. Nesting is minimal and flat. Intent is highly clear—each method has a descriptive name and purpose. Code length is appropriate; there's no unnecessary verbosity. Action granularity is good, with one operation per line in most cases. Reading flow is natural and follows a sensible order: class declaration, factory methods, constructors, then serialization. The only minor issues are the odd indentation on the @GwtIncompatible annotations for writeObject and readObject, and the slightly compressed format of the serialVersionUID declaration. These are cosmetic and don't significantly impact readability.

Run 2

The code is well-structured and highly readable. It follows clear class organization with static factory methods before constructors, consistent Javadoc, and logical grouping of fields. Nesting is minimal, with only small methods and no deep indentation. Intent is clear: each method's purpose is obvious from its name and documentation. The code is concise, avoiding unnecessary verbosity while maintaining clarity. Action granularity is good—each line performs one focused operation (e.g., creating a map, adding elements). Reading flow is natural: class-level documentation, factory methods in logical order, private constructors, then serialization. Minor deductions: the serialization method indentation is slightly inconsistent, and the `E extends @Nullable Object` type bound adds slight verbosity. Overall, this is exemplary Java library code that adheres to conventions and maintains excellent readability.

Run 3

The code is highly readable with a clear, logical structure. The class is well-organized: static factory methods first, private constructors, then serialization logic. Javadoc is thorough and explains both the class's behavior and the rationale behind factory parameters. Nesting is minimal and flat, with no complex control flow. Intent is immediately clear—each factory method and constructor is concise and named descriptively. Line length is appropriate, and each statement occupies its own line, with braces consistently placed. Readability is slightly reduced by the unusual indentation of the @GwtIncompatible and @J2ktIncompatible annotations on the private serialization methods, and the import grouping is slightly compressed, but these are minor style issues. Overall, the code follows clean, predictable conventions, making it easy to scan and understand.

Run 1

Code Structure: Logically organized into documented factory methods, private constructors, and serialization helpers. Nesting: Very flat, with no nested control flow. Clarity of intent: Descriptive names and thorough Javadoc clearly explain construction and iteration behavior; inherited implementation details require some external context. Code length: Concise implementation with useful documentation rather than unnecessary logic. Action granularity: Each statement performs one clear action, though the final field declaration combines annotations and declaration on one line. Reading flow: Consistent method grouping and straightforward statements make the code easy to follow. Minor indentation inconsistencies in the serialization method declarations and compressed annotations on serialVersionUID slightly reduce visual consistency.

Run 2

Code Structure: Factory methods, constructors, and serialization hooks are logically grouped. Nesting: Methods are flat, with no nested control flow. Clarity of intent: Descriptive names and thorough Javadoc explain iteration behavior, creation options, and serialization; inherited helpers require some external context. Code length: The implementation is concise, and documentation adds useful context rather than unnecessary complexity. Action granularity: Executable statements generally perform one action per line, although the final field declaration compresses annotations and modifiers together. Reading flow: The progression from public creation methods to private implementation details is natural. Minor formatting issues, particularly inconsistent indentation of serialization method declarations and missing spacing after the package declaration, slightly reduce readability.

Run 3

Code Structure: Factory methods, constructors, and serialization hooks are logically grouped with clear responsibilities. Nesting: Methods are flat, with no nested control flow. Clarity of intent: Descriptive names and useful Javadoc explain creation options and iteration-order guarantees; inherited behavior and serialization helpers require some external context. Code length: The implementation is concise, and documentation adds useful context rather than unnecessary verbosity. Action granularity: Executable statements generally perform one action per line, although the final declaration crowds annotations and the field onto one line. Reading flow: Consistent method ordering and short bodies make the code easy to follow. Minor formatting issues, particularly extra indentation on serialization method declarations and missing spacing after the package declaration, slightly reduce polish.