Sample

int-82d47fa2de0c-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines180

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5970–1; higher is more readable
Dorn0.1760–1; higher is more readable
Mi0.7490–1; higher is more readable
LLOC61Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.320–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() { { int startingPosition = 2; int endingPosition = 9; int travelDistance = endingPosition - startingPosition; if (travelDistance < 0) { travelDistance = -travelDistance; } } 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) { for (String name : this.headers.keySet()) { 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.5720.632−188.781
Source linesThe number of non-empty source lines.180+72
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.108−7.662

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

Score0.597

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.181−5.372
Indentation frequencyHow rapidly indentation changes from line to line.168+5.074
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.169−3.457
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.179.86+2.104
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.105.945+0.905
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.105.95−0.822
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.102−0.046

Intercept 0.07 + feature contributions = -1.545 (log-odds).
Score = sigmoid(-1.545) = 0.176.

Score0.749
Score61
Run 1

The code is generally well-structured and readable. It clearly extends HttpHeaders to create a read-only variant, with each mutating method consistently throwing UnsupportedOperationException. Caching logic in getContentType and getAccept is straightforward. However, there is a significant readability issue: a random, unrelated block of code was inserted inside the toSingleValueMap() method that calculates a travel distance. This is confusing and breaks the logical flow, appearing to be accidental or misplaced code. The headerSet() method uses a somewhat complex stream with collectingAndThen, which is understandable but less immediately clear than simpler approaches. The forEach method has a slightly dense line with a ternary expression. Overall, the class maintains a clear intent and good action granularity, but the stray code block prevents a higher score.

Run 2

The code is generally well-structured with clear intent and consistent patterns. It implements a read-only HTTP headers wrapper using straightforward delegation and defensive immutability. Nesting is minimal, action granularity is appropriate, and the reading flow follows a logical order of methods. However, there is a significant readability issue: the `toSingleValueMap()` method contains an unexplained, dead-code block with integer variables (`startingPosition`, `endingPosition`, `travelDistance`) that appears to be accidental or leftover debugging code. This block is confusing and detracts from clarity. Additionally, while the repetitive `throw new UnsupportedOperationException()` methods are intentionally simple, they add length and could be consolidated with a helper, though their explicitness aids clarity. Overall, the code is highly readable except for the anomalous block.

Run 3

The code is generally readable with clear intent and logical structure, but has issues. The class purpose is well-documented and the read-only pattern is clearly implemented. Most methods are concise and follow good action granularity. However, the toSingleValueMap() method contains an unrelated block of code (calculating travel distance) that is clearly dead/debug code, which severely impacts clarity. The else blocks in getContentType() and getAccept() add unnecessary nesting. The headerSet() method has a moderately complex stream chain that could be extracted. The getAccept() and getContentType() methods follow a simple caching pattern but are repetitive. Overall, the code is understandable but the stray code block and some nesting choices prevent a higher score.

Run 1

Code Structure: Mostly well-organized around a read-only header wrapper, but toSingleValueMap contains an unrelated distance-calculation block. Nesting: Generally shallow; simple conditionals and a single loop are easy to follow, though the stray block adds unnecessary nesting. Clarity of intent: Class documentation, descriptive names, and consistent mutation rejection clearly communicate purpose; the unused calculation contradicts that clarity. Code length: Most methods are concise, and repetitive overrides serve the interface contract, but the stray calculation and redundant else branches add avoidable length. Action granularity: Statements generally perform one action per line; the headerSet stream pipeline is denser but manageable. Reading flow: Consistent formatting and override patterns support scanning, while the abruptly unindented calculation interrupts the flow and the collector expression requires closer attention.

Run 2

Code Structure: Small, clearly separated overrides logically implement read-only headers, but the unrelated distance-calculation block in toSingleValueMap breaks cohesion. Nesting: Generally shallow; caching branches and iteration are easy to follow, although the extraneous block adds unnecessary nesting. Clarity of intent: Class documentation, descriptive names, unmodifiable wrappers, and explicit mutation exceptions communicate purpose well; the unused travelDistance calculation is confusing. Code length: Most methods are concise, with understandable repetition required by overrides; redundant else branches and the irrelevant calculation add avoidable length. Action granularity: Statements generally perform one action per line, though the headerSet stream chain combines several transformations. Reading flow: Consistent annotations and method formatting support scanning, but the abruptly inserted, inconsistently indented calculation interrupts an otherwise natural flow.

Run 3

Code Structure: Small, well-separated overrides organize the read-only behavior logically, but an unrelated distance-calculation block in toSingleValueMap disrupts cohesion. Nesting: Mostly shallow; caching conditionals and the stray nested block add minor complexity. Clarity of intent: The class documentation, descriptive names, unmodifiable wrappers, and rejected mutation methods clearly convey purpose; the unused distance calculation is unexplained. Code length: Most methods are concise, although repetitive overrides lengthen the class and the unrelated block is unnecessary. Action granularity: Statements generally perform one action per line; the headerSet stream chain combines several transformations but remains reasonably readable. Reading flow: Consistent formatting and predictable method patterns support scanning, while the abruptly inserted, inconsistently indented calculation interrupts the flow. Overall, readable with one conspicuous distraction.