Sample

int-f5cedf13269c-I13

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

Matched original source

Lines137

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5330–1; higher is more readable
Dorn0.7880–1; higher is more readable
Mi0.2820–1; higher is more readable
LLOC54Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3650–1; higher is more readable

Views

Source code

package org.springframework.core.convert.support; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; import org.jspecify.annotations.Nullable; import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; /** * Converts a Map to another Map. * * <p>First, creates a new Map of the requested targetType with a size equal to the * size of the source Map. Then copies each element in the source map to the target map. * Will perform a conversion from the source map's parameterized K,V types to the target * map's parameterized types K,V if necessary. * * @author Keith Donald * @author Juergen Hoeller * @since 3.0 */ final class MapToMapConverter implements ConditionalGenericConverter { private final ConversionService conversionService; public MapToMapConverter(ConversionService conversionService) { this.conversionService = conversionService; } @Override public Set<ConvertiblePair> getConvertibleTypes() { return Collections.singleton(new ConvertiblePair(Map.class, Map.class)); } @Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { return canConvertKey(sourceType, targetType) && canConvertValue(sourceType, targetType); } @Override public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } @SuppressWarnings("unchecked") Map<Object, Object> sourceMap = (Map<Object, Object>) source; // Shortcut if possible... boolean copyRequired = !targetType.getType().isInstance(source); if (!copyRequired && sourceMap.isEmpty()) { return sourceMap; } TypeDescriptor keyDesc = targetType.getMapKeyTypeDescriptor(); TypeDescriptor valueDesc = targetType.getMapValueTypeDescriptor(); List<MapEntry> targetEntries = new ArrayList<>(sourceMap.size()); { java.util.Iterator<?> loopIterator = (sourceMap.entrySet()).iterator(); while (loopIterator.hasNext()) { Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) loopIterator.next(); Object sourceKey = entry.getKey(); Object sourceValue = entry.getValue(); Object targetKey = convertKey(sourceKey, sourceType, keyDesc); Object targetValue = convertValue(sourceValue, sourceType, valueDesc); targetEntries.add(new MapEntry(targetKey, targetValue)); if (sourceKey != targetKey || sourceValue != targetValue) { copyRequired = true; } } } if (!copyRequired) { return sourceMap; } Map<Object, Object> targetMap = CollectionFactory.createMap(targetType.getType(), (keyDesc != null ? keyDesc.getType() : null), sourceMap.size()); { java.util.Iterator<?> loopIteratorA = (targetEntries).iterator(); while (loopIteratorA.hasNext()) { MapEntry entry = (MapEntry) loopIteratorA.next(); entry.addToMap(targetMap); } } return targetMap; } // internal helpers private boolean canConvertKey(TypeDescriptor sourceType, TypeDescriptor targetType) { return ConversionUtils.canConvertElements(sourceType.getMapKeyTypeDescriptor(), targetType.getMapKeyTypeDescriptor(), this.conversionService); } private boolean canConvertValue(TypeDescriptor sourceType, TypeDescriptor targetType) { return ConversionUtils.canConvertElements(sourceType.getMapValueTypeDescriptor(), targetType.getMapValueTypeDescriptor(), this.conversionService); } private @Nullable Object convertKey(Object sourceKey, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) { if (targetType == null) { return sourceKey; } return this.conversionService.convert(sourceKey, sourceType.getMapKeyTypeDescriptor(sourceKey), targetType); } private @Nullable Object convertValue(Object sourceValue, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) { if (targetType == null) { return sourceValue; } return this.conversionService.convert(sourceValue, sourceType.getMapValueTypeDescriptor(sourceValue), targetType); } private static class MapEntry { private final @Nullable Object key; private final @Nullable Object value; public MapEntry(@Nullable Object key, @Nullable Object value) { this.key = key; this.value = value; } public void addToMap(Map<Object, Object> map) { map.put(this.key, this.value); } } }

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.5160.734−170.304
Source linesThe number of non-empty source lines.137+54.8
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.978−7.467

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

Score0.533

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.138−3.85
Indentation frequencyHow rapidly indentation changes from line to line.124+3.552
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.123.978−1.586
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.136.84+1.503
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.123.993+1.196
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.094+0.027

Intercept 0.07 + feature contributions = 1.31 (log-odds).
Score = sigmoid(1.31) = 0.788.

Score0.282
Score54
Run 1

The code is generally clear, with good class structure and meaningful method names. However, the 'convert' method has some readability issues: the iteration blocks use awkward 'loopIterator' variables and explicit Iterator syntax instead of for-each loops, making the code feel more verbose and less natural to read. The nested braces around the while loops add visual noise without clear purpose. The logic for detecting whether copying is required is spread across the loop, which slightly obscures intent. The helper methods are well-separated and concise, but the overall flow in 'convert' could be simplified. The use of blocks to isolate loops is unconventional and disrupts reading flow. While the code is not deeply nested or ambiguous overall, the iteration style and block usage reduce its clarity compared to idiomatic Java.

Run 2

The code has clear structure with separated methods and a helper class, but suffers from several readability issues. The convert method contains unnatural iteration using raw iterator variables with extra braces, which interrupts the established concise style and creates unnecessary boilerplate. The action granularity in these loops is awkward — multiple operations per line with explicit type casts. Reading flow is disrupted by the non-idiomatic loops that could use enhanced for-each. Nesting is mostly flat, which is good. The intent of the converter is clear from the Javadoc and method names, though the two-phase build approach (accumulate entries, then populate map) adds cognitive overhead. Code length is reasonable overall but the loop constructs make it unnecessarily long. The @SuppressWarnings and explicit casts further reduce clarity. Overall, solid conceptual organization with inconsistent implementation style.

Run 3

The code is logically structured with clear responsibilities and helpful comments, but readability suffers from inconsistent and awkward iteration blocks that interrupt the natural flow. The use of raw Map.Entry casts and manual iterator loops in separate scoped blocks adds unnecessary noise compared to standard for-each syntax. Nesting is generally shallow, and methods are concise with single-purpose actions. However, the 'copyRequired' logic is slightly scattered across the main method, and the second iteration block repeats the same awkward pattern. Overall, the code is maintainable but could be significantly improved by replacing the iterator blocks with direct for-each loops and consolidating related logic.

Run 1

Code Structure: Well organized into interface methods, conversion helpers, and a small entry class. Nesting: Mostly shallow, with early returns, though redundant blocks around iterator loops add unnecessary nesting. Clarity of intent: Documentation, descriptive names, and explicit key/value conversion make the purpose clear; the deferred-copy strategy requires some attention. Code length: Reasonable overall, but manual iterators, casts, and temporary entry storage introduce verbosity; enhanced for-loops would simplify traversal. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: Conversion proceeds logically from validation through entry conversion to target-map creation, but inconsistent indentation, fully qualified iterator types, unnecessary parentheses, and mechanical iterator names interrupt otherwise natural flow.

Run 2

Code Structure: Well organized into conversion logic, focused helpers, and a small entry class. Nesting: Mostly shallow, with early returns reducing complexity; unnecessary blocks around iterator loops add nesting. Clarity of intent: Descriptive names, documentation, and explicit key/value conversion make the purpose clear, although copyRequired and the two-stage collection process require some attention. Code length: Reasonably concise overall, but manual iterator loops, casts, and extra blocks are more verbose than enhanced for-loops. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: The progression from validation through conversion to map creation is logical, but inconsistent loop indentation, fully qualified iterator declarations, redundant parentheses, and generic iterator names disrupt readability.

Run 3

Code Structure: Well organized into conversion methods, focused helpers, and a small entry class. Nesting: Early returns keep nesting moderate, although redundant blocks around iterator loops add visual depth. Clarity of intent: Descriptive names and documentation explain map conversion and copy avoidance; reference-identity checks require some thought. Code length: Mostly justified, but explicit iterators, casts, and extra blocks are more verbose than enhanced for-loops. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: The progression from validation to entry conversion, copy detection, and target creation is logical. Inconsistent loop indentation, fully qualified iterator types, and awkward names such as loopIteratorA interrupt otherwise readable formatting.