Sample

int-f7573371dfd1-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines129

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5460–1; higher is more readable
Dorn0.7780–1; higher is more readable
Mi0.2820–1; higher is more readable
LLOC50Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.3790–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()); for (Map.Entry<Object, Object> entry : sourceMap.entrySet()) { 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()); for (MapEntry entry : targetEntries) { 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.4610.646−152.151
Source linesThe number of non-empty source lines.129+51.6
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.973−7.459

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

Score0.546

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.130−3.567
Indentation frequencyHow rapidly indentation changes from line to line.116+3.275
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.977−1.586
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.128.864+1.391
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.123.985+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.089+0.079

Intercept 0.07 + feature contributions = 1.257 (log-odds).
Score = sigmoid(1.257) = 0.778.

Score0.282
Score50
Run 1

The code is highly readable with clear structure and intent. It follows a logical organization: constructor, interface methods, main conversion logic, helper methods, and an inner class. Nesting is shallow, with only one level inside the loop and conditionals. Action granularity is appropriate, with mostly one action per line. Reading flow is natural, guiding the reader from type checks through conversion to map creation. The use of helper methods (canConvertKey, convertKey, etc.) improves clarity and reduces duplication. The 'Shortcut if possible...' comment clarifies the early return. Minor deductions: the convert method is somewhat long but still coherent, and the MapEntry inner class adds slight overhead but is well-encapsulated. Overall, the code is concise, well-documented, and easy to follow.

Run 2

The code is highly readable. The class has a single, well-documented responsibility, and methods are small and logically grouped. It uses clear, descriptive naming (e.g., canConvertKey, convertValue) and maintains a flat structure—the only nesting is a single for-loop and minor if-checks. Each line generally performs one action, improving clarity. A small inefficiency is that targetEntries are stored even when no conversion is needed, but this is minor. The internal MapEntry helper cleanly encapsulates key-value pairs, and comments clarify non-obvious shortcuts without being excessive. Overall, the structure, intent, and flow are excellent.

Run 3

The code is highly readable with a clear, logical structure. It follows a top-down organization: convert method first, then helper methods, and a small private static class at the end. Nesting is minimal—only one level inside loops and conditionals. Each conditional branch is simple and returns early where appropriate. Variable and method names are descriptive, making intent clear (e.g., canConvertKey, convertValue, copyRequired). The code is concise without being cryptic; the only slight verbosity is the MapEntry inner class, though it arguably improves clarity. Action granularity is good: most lines perform one logical operation, and the loop body uses temporary variables to avoid overcrowding. Reading flow is natural and linear. Overall, this is excellent production-quality code that balances readability, efficiency, and maintainability.

Run 1

Code Structure: Well organized into converter methods, focused helpers, and a small entry class. Nesting: Shallow loops and conditionals, with early returns keeping control flow flat. Clarity of intent: Descriptive names and class documentation clearly explain map conversion; identity comparisons and deferred copying require slightly more interpretation. Code length: Mostly concise, although parallel key/value helpers and the intermediate MapEntry class add some verbosity. Action granularity: Statements generally perform one action per line, making conversion steps easy to follow. Reading flow: Natural progression from validation to element conversion, copy detection, and target-map construction. The two-pass approach modestly increases cognitive load but remains readable.

Run 2

Code Structure: Well organized into converter methods, focused helpers, and a small entry holder. Nesting: Shallow conditionals and loops, with early returns keeping control flow flat. Clarity of intent: Descriptive names and class documentation clearly communicate map conversion; identity comparisons and deferred copying require some thought. Code length: Mostly concise, though parallel key/value helpers and the MapEntry wrapper introduce modest repetition and boilerplate. Action granularity: Statements generally perform one action per line, making transformations easy to follow. Reading flow: Natural progression from validation through conversion to target-map creation, with consistent formatting. The two-pass conversion strategy slightly interrupts straightforward reading, and a comment explaining why entries are buffered would improve clarity.

Run 3

Code Structure: Well organized into public conversion methods, focused helpers, and a small entry class. Nesting: Shallow loops and conditionals, with early returns reducing complexity. Clarity of intent: Descriptive names and class documentation clearly explain map conversion; identity comparisons and deferred copying require slightly more attention. Code length: Mostly concise, though parallel key/value helpers and the intermediate entry class add some verbosity. Action granularity: Statements generally perform one clear action per line, with appropriately wrapped longer calls. Reading flow: Conversion proceeds naturally from null handling through element conversion to reuse or reconstruction. The two-pass approach slightly interrupts the flow, and a brief explanation of why entries are buffered would improve readability.