Sample

int-7b3305511883-I13

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

Matched original source

Lines90

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.610–1; higher is more readable
Dorn0.4380–1; higher is more readable
Mi0.4470–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6120–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.util.Comparator; import java.util.Spliterator; import org.jspecify.annotations.Nullable; /** * List returned by {@code ImmutableSortedSet.asList()} when the set isn't empty. * * @author Jared Levy * @author Louis Wasserman */ @GwtCompatible @SuppressWarnings("serial") final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E> implements SortedIterable<E> { ImmutableSortedAsList(ImmutableSortedSet<E> backingSet, ImmutableList<E> backingList) { super(backingSet, backingList); } @Override ImmutableSortedSet<E> delegateCollection() { return (ImmutableSortedSet<E>) super.delegateCollection(); } @Override public Comparator<? super E> comparator() { return delegateCollection().comparator(); } // Override indexOf() and lastIndexOf() to be O(log N) instead of O(N). @GwtIncompatible // ImmutableSortedSet.indexOf // TODO(cpovirk): consider manual binary search under GWT to preserve O(log N) lookup @Override public int indexOf(@Nullable Object target) { int index = delegateCollection().indexOf(target); // TODO(kevinb): reconsider if it's really worth making feeble attempts at // sanity for inconsistent comparators. // The equals() check is needed when the comparator isn't compatible with // equals(). return (index >= 0 && get(index).equals(target)) ? index : -1; } @GwtIncompatible // ImmutableSortedSet.indexOf @Override public int lastIndexOf(@Nullable Object target) { return indexOf(target); } @Override public boolean contains(@Nullable Object target) { // Necessary for ISS's with comparators inconsistent with equals. return indexOf(target) >= 0; } @GwtIncompatible // super.subListUnchecked does not exist; inherited subList is valid if slow /* * TODO(cpovirk): if we start to override indexOf/lastIndexOf under GWT, we'll want some way to * override subList to return an ImmutableSortedAsList for better performance. Right now, I'm not * sure there's any performance hit from our failure to override subListUnchecked under GWT */ @Override ImmutableList<E> subListUnchecked(int fromIndex, int toIndex) { ImmutableList<E> parentSubList = super.subListUnchecked(fromIndex, toIndex); return new RegularImmutableSortedSet<E>(parentSubList, comparator()).asList(); } @Override public Spliterator<E> spliterator() { return CollectSpliterators.indexed( size(), ImmutableList.SPLITERATOR_CHARACTERISTICS | Spliterator.SORTED | Spliterator.DISTINCT, delegateList()::get, comparator()); } // redeclare to help optimizers with b/310253115 @SuppressWarnings("RedundantOverride") @Override @J2ktIncompatible @GwtIncompatible Object writeReplace() { return super.writeReplace(); } }

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.2237.639−73.842
Source linesThe number of non-empty source lines.90+36
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.98−7.47

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

Score0.61

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.91−2.186
Indentation frequencyHow rapidly indentation changes from line to line.70+1.684
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.70−1.185
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.89.85+0.846
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97.912+0.775
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.98.956−0.526
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.069+0.274

Intercept 0.07 + feature contributions = -0.248 (log-odds).
Score = sigmoid(-0.248) = 0.438.

Score0.447
Score19
Run 1

The code is highly readable due to its clear structure, minimal nesting, and strong documentation. Each class and method has a well-defined purpose, with inherited methods documented via inline comments explaining complexity trade-offs (e.g., O(log N) optimizations). Naming is descriptive and follows Java conventions. The file is concise without sacrificing clarity; complex logic is isolated and justified. Comments address subtle concerns like comparator consistency and GWT compatibility, enhancing understanding without clutter. Most methods are one to three lines, keeping a natural reading flow. Slight deductions for the slightly awkward formatting of the last method’s annotation and rare reliance on comments to explain non-obvious invariant decisions, but overall this is exemplary readable code.

Run 2

The code is well-structured with clear class purpose and logical organization. It extends appropriate base classes and overrides methods sensibly. Nesting is minimal—conditional logic is flat and readable. Intent is mostly clear from method names and comments, though some comments are verbose or overly tentative ('feeble attempts', 'TODO' speculation). Code length is reasonable; each method is concise and focused. Action granularity is good—one operation per line in most cases. Reading flow is natural: class declaration, constructor, then method overrides in logical order. Minor deductions: some comments could be more decisive, and the writeReplace() method has inconsistent indentation. The @GwtIncompatible and @J2ktIncompatible annotations add noise but are necessary. Overall, this is production-quality readable code with only minor clarity improvements possible.

Run 3

The code is generally readable with clear class purpose and logical organization. The class hierarchy is evident, with methods grouping related functionality (comparator, indexOf, subListUnchecked, spliterator). Nesting is minimal and flat, with no deeply nested conditions or loops. Intent is mostly clear through descriptive method names and comments explaining non-obvious decisions like the equals() check and O(log N) optimization. However, there are some readability issues: the writeReplace() method has awkward indentation and multiple annotations that disrupt flow, and the subListUnchecked method contains a long comment that interrupts the natural reading sequence. The code is concise overall, avoiding unnecessary verbosity, though some comments could be more focused. Action granularity is good - one logical operation per line. Reading flow is generally natural but slightly hindered by annotation-heavy sections and the TODO comments. The type casting in delegateCollection() is clear but could benefit from a brief comment. Overall, the code demonstrates good practices but has minor organizational blemishes that prevent a higher score.

Run 1

Code Structure: Well-organized class with small, cohesive overrides and consistent delegation. Nesting: Flat methods with no deeply nested control flow. Clarity of intent: Descriptive method names and comments explain performance goals and comparator-related correctness; framework annotations and inheritance require some external knowledge. Code length: Implementation is concise, although lengthy TODO comments slightly interrupt readability. Action granularity: Statements generally perform one clear action, and the multiline spliterator construction remains readable. Reading flow: Methods progress naturally from delegation to lookup, sublists, iteration, and serialization. Minor distractions include the unexplained issue reference, abbreviated 'ISS', crowded annotation/comment blocks, and inconsistent indentation of writeReplace().

Run 2

Code Structure: Well-organized class with small, focused overrides and consistent delegation. Nesting: Essentially flat; the conditional expression in indexOf is straightforward. Clarity of intent: Descriptive names and comments explain performance goals and comparator/equals compatibility, though framework-specific annotations, abbreviations, and optimizer references require background knowledge. Code length: Implementation is concise, but lengthy TODO comments add some clutter. Action granularity: Statements generally perform one clear action per line; the multiline spliterator construction remains easy to follow. Reading flow: Methods progress naturally from delegation and lookup to sublists and iteration. Minor distractions include densely stacked annotations and comments, no blank line after the package declaration, and inconsistent indentation on writeReplace.

Run 3

Code Structure: Well-organized class with small, focused overrides and consistent delegation. Nesting: Almost entirely flat; the conditional expression in indexOf is straightforward. Clarity of intent: Descriptive method names and comments explain performance goals and comparator-versus-equals behavior, although inherited implementation details require external context. Code length: Concise implementation, with some lengthy TODO comments and compatibility annotations adding visual overhead. Action granularity: Statements generally perform one action per line; chained calls and the ternary remain easy to follow. Reading flow: Methods follow a logical progression from delegation and comparison to lookup, sublists, and traversal. Minor distractions include the unexplained ISS abbreviation, internal bug reference, and inconsistent indentation of writeReplace.