Sample

int-c55fd25596d9-I13

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

Matched original source

Lines175

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5950–1; higher is more readable
Dorn0.1680–1; higher is more readable
Mi0.7490–1; higher is more readable
LLOC58Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol16.330–20; mean of three runs
BTTF0.4710–1; higher is more readable

Views

Source code

package org.springframework.http; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; import org.jspecify.annotations.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; /** * {@code HttpHeaders} variant that can only be read, not written to. * * <p>This caches the parsed representations of the "Accept" and "Content-Type" * headers and will get out of sync with the backing map if it is mutated at runtime. * * @author Brian Clozel * @author Sam Brannen * @since 5.1.1 */ class ReadOnlyHttpHeaders extends HttpHeaders { private static final long serialVersionUID = -8578554704772377436L; private @Nullable MediaType cachedContentType; @SuppressWarnings("serial") private @Nullable List<MediaType> cachedAccept; ReadOnlyHttpHeaders(MultiValueMap<String, String> headers) { super(headers); } @Override public @Nullable MediaType getContentType() { if (this.cachedContentType != null) { return this.cachedContentType; } else { MediaType contentType = super.getContentType(); this.cachedContentType = contentType; return contentType; } } @Override public List<MediaType> getAccept() { if (this.cachedAccept != null) { return this.cachedAccept; } else { List<MediaType> accept = super.getAccept(); this.cachedAccept = accept; return accept; } } @Override public void clearContentHeaders() { // No-op. } @Override public @Nullable List<String> get(String headerName) { List<String> values = this.headers.get(headerName); return (values != null ? Collections.unmodifiableList(values) : null); } @Override public void add(String headerName, @Nullable String headerValue) { throw new UnsupportedOperationException(); } @Override public void addAll(String key, List<? extends String> headerValues) { throw new UnsupportedOperationException(); } @Override public void addAll(HttpHeaders values) { throw new UnsupportedOperationException(); } @Override public void set(String headerName, @Nullable String headerValue) { throw new UnsupportedOperationException(); } @Override public void setAll(Map<String, String> values) { throw new UnsupportedOperationException(); } @Override public Map<String, String> toSingleValueMap() { return Collections.unmodifiableMap(this.headers.toSingleValueMap()); } @SuppressWarnings("removal") @Override @Deprecated(since = "7.0", forRemoval = true) public Map<String, String> asSingleValueMap() { return Collections.unmodifiableMap(this.headers.asSingleValueMap()); } @SuppressWarnings("removal") @Override @Deprecated(since = "7.0", forRemoval = true) public MultiValueMap<String, String> asMultiValueMap() { return CollectionUtils.unmodifiableMultiValueMap(this.headers); } @Override public Set<String> headerNames() { return Collections.unmodifiableSet(super.headerNames()); } @Override public List<String> put(String key, List<String> value) { throw new UnsupportedOperationException(); } @Override public @Nullable List<String> putIfAbsent(String headerName, List<String> headerValues) { throw new UnsupportedOperationException(); } @Override public void putAll(@Nullable HttpHeaders values) { throw new UnsupportedOperationException(); } @Override public void putAll(Map<? extends String, ? extends List<String>> headers) { throw new UnsupportedOperationException(); } @Override public List<String> remove(String key) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public Set<Entry<String, List<String>>> headerSet() { return super.headerSet().stream().map(SimpleImmutableEntry::new) .collect(Collectors.collectingAndThen( Collectors.toCollection(LinkedHashSet::new), // Retain original ordering of entries Collections::unmodifiableSet)); } @Override public void forEach(BiConsumer<? super String, ? super List<String>> action) { { java.util.Iterator<?> loopIterator = (this.headers.keySet()).iterator(); while (loopIterator.hasNext()) { String name = (String) loopIterator.next(); List<String> values = this.headers.get(name); action.accept(name, (values != null ? Collections.unmodifiableList(values) : Collections.emptyList())); } } } }

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.5708.062−188.366
Source linesThe number of non-empty source lines.175+70
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.5.106−7.659

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

Score0.595

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.176−5.195
Indentation frequencyHow rapidly indentation changes from line to line.163+4.901
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.164−3.342
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.174.836+2.034
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.108.926+0.953
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.108.977−0.951
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.104−0.07

Intercept 0.07 + feature contributions = -1.6 (log-odds).
Score = sigmoid(-1.6) = 0.168.

Score0.749
Score58
Run 1

The ReadOnlyHttpHeaders class exhibits clear structure and intent. It extends HttpHeaders and systematically overrides mutating methods with UnsupportedOperationException, making the read-only behavior explicit. Nesting is minimal, and method lengths are concise. Action granularity is mostly one per line, with occasional ternary expressions that remain readable. The caching logic for getContentType and getAccept is straightforward. Import statements are organized but could be slightly tidied. One minor deviation occurs in the forEach method, which has an unnecessary extra block and could use a simpler iteration pattern. Overall, the code is highly readable, with clear purpose and consistent design, though the forEach implementation slightly complicates an otherwise clean flow.

Run 2

The code is highly readable, with clear structure and intent. The class is well-documented, imports are organized, and methods are logically grouped. Read-only behavior is consistently enforced via exceptions or unmodifiable wrappers, making the design obvious. Nesting is minimal—only simple if/else blocks for caching and a stream pipeline in headerSet(). Clarity of intent is strong: method names and no-op comments explain behavior. Action granularity is mostly one action per line, though stream and forEach implementations are slightly dense. Reading flow is natural, with constructors, cache getters, blocking mutators, and read-only accessors following a logical order. Minor deductions: the forEach method has unnecessary braces and a manual iterator that could be simplified, and the headerSet() stream is a bit complex. Overall, the code is concise and maintainable.

Run 3

The code is generally readable with a clear logical structure and consistent patterns. Class intent is well documented. Methods are short and mostly flat, with simple if/else caching logic. Most mutating methods are concise one-liners throwing UnsupportedOperationException, which clearly signals read-only intent. However, a few issues reduce clarity: the forEach method has an unnecessary extra brace block and uses a verbose while-loop iterator instead of a simpler for-each or stream, disrupting natural reading flow. The headerSet method uses a multi-line stream chain that is reasonably formatted but somewhat dense. Import ordering is slightly inconsistent. Overall, the code is maintainable and intentions are clear, but minor stylistic inconsistencies and verbose constructs prevent a higher score.

Run 1

Code Structure: Well-organized class with short overrides, although read methods and prohibited mutation methods are somewhat interspersed. Nesting: Mostly shallow; forEach adds an unnecessary block around its loop, and caching methods use avoidable else branches after returns. Clarity of intent: The class documentation, descriptive names, unmodifiable wrappers, and explicit exceptions clearly communicate read-only behavior. Code length: Reasonably concise given the required overrides, though repetitive exception-only methods and verbose iterator code increase length. Action granularity: Most lines perform one clear action; the stream pipeline and callback invocation combine several operations but remain understandable. Reading flow: Consistent annotations and formatting generally support easy scanning, but forEach breaks the style with irregular indentation, a fully qualified raw-looking iterator declaration, redundant parentheses, and a cast. An enhanced for-loop would improve it.

Run 2

Code Structure: The class is logically organized around cached reads, read-only views, and blocked mutations, though related methods could be grouped more consistently. Nesting: Most methods are flat; caching uses shallow branches, while forEach adds an unnecessary block around its loop. Clarity of intent: The class documentation, descriptive names, and consistent UnsupportedOperationException overrides clearly communicate its purpose. Code length: Most methods are concise; repetitive overrides are largely justified by the interface, but forEach is unnecessarily verbose. Action granularity: Statements generally perform one action each, although headerSet combines several transformations in a moderately dense stream pipeline. Reading flow: Consistent annotations and short methods support scanning, but the raw-style iterator, cast, fully qualified type, and inconsistent indentation in forEach disrupt the otherwise natural flow.

Run 3

Code Structure: The class is logically organized around cached reads, read-only views, and rejected mutations, though related methods could be grouped more consistently. Nesting: Most methods are flat; caching uses simple conditionals, while forEach adds an unnecessary block around its loop. Clarity of intent: Naming, overrides, and class documentation clearly establish the read-only purpose and caching caveat. Code length: Methods are short; repetitive mutation overrides are largely necessary, but redundant else branches and verbose iteration add avoidable length. Action granularity: Most lines perform one action, although the headerSet stream chain and forEach callback expression combine several transformations. Reading flow: Consistent method formatting supports scanning, but forEach breaks that consistency with unusual indentation, a fully qualified raw-looking iterator declaration, and an explicit cast. Overall, the code is readily understandable with localized stylistic distractions.