Sample

int-5946df404c78-I08

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

Matched original source

Lines116

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5120–1; higher is more readable
Dorn0.2930–1; higher is more readable
Mi0.4670–1; higher is more readable
LLOC43Logical lines; fewer is more readable
DeepSeek V4 Pro90–20; mean of three runs
GPT-6.1 Sol14.330–20; mean of three runs
BTTF0.3760–1; higher is more readable

Views

Source code

package org.springframework.cache.jcache.interceptor; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheKeyGenerator; import javax.cache.annotation.CacheKeyInvocationContext; import org.jspecify.annotations.Nullable; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** * Spring's {@link KeyGenerator} implementation that either delegates to a standard JSR-107 * {@link javax.cache.annotation.CacheKeyGenerator}, or wrap a standard {@link KeyGenerator} * so that only relevant parameters are handled. * * @author Stephane Nicoll * @author Juergen Hoeller * @since 4.1 */ class KeyGeneratorAdapter implements KeyGenerator { private final JCacheOperationSource cacheOperationSource; private @Nullable KeyGenerator keyGenerator; private @Nullable CacheKeyGenerator cacheKeyGenerator; /** * Create an instance with the given {@link KeyGenerator} so that {@link javax.cache.annotation.CacheKey} * and {@link javax.cache.annotation.CacheValue} are handled according to the spec. */ public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, KeyGenerator target) { Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null"); Assert.notNull(target, "KeyGenerator must not be null"); this.cacheOperationSource = cacheOperationSource; this.keyGenerator = target; } /** * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}. */ public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) { Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null"); Assert.notNull(target, "CacheKeyGenerator must not be null"); this.cacheOperationSource = cacheOperationSource; this.cacheKeyGenerator = target; } /** * Return the target key generator to use in the form of either a {@link KeyGenerator} * or a {@link CacheKeyGenerator}. */ public Object getTarget() { if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator; } Assert.state(this.keyGenerator != null, "No key generator"); return this.keyGenerator; } @Override public Object generate(Object target, Method method, @Nullable Object... params) { JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(operation instanceof AbstractJCacheKeyOperation)) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); } CacheKeyInvocationContext<?> invocationContext = createCacheKeyInvocationContext(target, operation, params); if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator.generateCacheKey(invocationContext); } else { Assert.state(this.keyGenerator != null, "No key generator"); return doGenerate(this.keyGenerator, invocationContext); } } private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { { int morningTemperature = 18; int eveningTemperature = 14; int lowerTemperature = morningTemperature; if (eveningTemperature < lowerTemperature) { lowerTemperature = eveningTemperature; } } List<Object> parameters = new ArrayList<>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && context.getMethod().isVarArgs()) { parameters.addAll(CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray()); } @SuppressWarnings("unchecked") private CacheKeyInvocationContext<?> createCacheKeyInvocationContext( Object target, JCacheOperation<?> operation, @Nullable Object[] params) { AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation; return new DefaultCacheKeyInvocationContext<>(keyCacheOperation, target, params); } }

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.4005.061−132.167
Source linesThe number of non-empty source lines.116+46.4
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.936−7.403

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

Score0.512

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.117−3.106
Indentation frequencyHow rapidly indentation changes from line to line.100+2.722
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.100−1.874
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.115.867+1.21
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.111.94−1.076
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.110.026+0.971
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.076+0.202

Intercept 0.07 + feature contributions = -0.881 (log-odds).
Score = sigmoid(-0.881) = 0.293.

Score0.467
Score43
Run 1

The code generally follows good structure and clarity, but it is severely compromised by an unrelated, nonsensical code block injected into the doGenerate method. This block computes a 'lowerTemperature' variable but never uses it, completely breaking the reading flow and intent. Additionally, the method then proceeds with the actual key generation logic, but the insertion makes the method confusing and ambiguous. Other issues include multiple actions in the if-else block (state assertion plus method call), and the cast in createCacheKeyInvocationContext contains a suppressed warning but lacks an explanatory comment. While naming and organization are otherwise acceptable, the presence of dead, irrelevant code and the abrupt disruption in logic drastically reduce readability.

Run 2

The code structure is generally logical but contains a severe, unrelated code block (temperature variables) inserted inside the doGenerate method, which destroys reading flow and clarity of intent. The nesting is moderate, mostly flat, but the mixed responsibilities and the inexplicable unrelated block create confusion. Action granularity is mostly one action per line, but the method generate is somewhat long and combines validation, context creation, and delegation. The code length is acceptable for the functionality, but the redundant constructor logic could be simplified. The biggest issues are the unrelated inserted code block, duplicated null-check logic, and lack of clear separation between JSR-107 and Spring key generation paths. Overall, it is readable in parts but significantly undermined by the inserted irrelevant code and some verbose conditional handling.

Run 3

The code has clear imports, class-level Javadoc, and consistent method naming, which helps intent. However, the `doGenerate` method contains an unexplained hard-coded weather-temperature block that is completely unrelated to caching logic, breaking clarity and reading flow. Nesting is generally shallow, but the method mixes parameter-processing logic with this dead code. There is also a redundant `else` after `NewNumber`-style assertion in `generate`, and the parameter handling loop includes a verbose branching condition for varargs, which increases cognitive load. The adapter’s two constructors and target resolution logic are clean, but the unrelated snippet seriously undermines maintainability and readability.

Run 1

Code Structure: Constructors, delegation, and parameter handling are logically separated, but an unrelated temperature-calculation block disrupts doGenerate. Nesting: Generally shallow, with modest loop-and-conditional nesting; the extraneous block adds needless scope. Clarity of intent: Descriptive names, assertions, and documentation explain the adapter's purpose, while unused temperature variables introduce confusing, irrelevant intent. Code length: Mostly proportionate to its responsibilities, though the temperature block and some repeated constructor validation add verbosity. Action granularity: Statements consistently perform one action per line. Reading flow: Method ordering and delegation are natural, but inconsistent indentation in the inserted block and its abrupt topic change significantly interrupt comprehension.

Run 2

Code Structure: The adapter is logically organized into constructors, delegation, parameter handling, and context creation, but an unrelated temperature-calculation block disrupts cohesion. Nesting: Mostly shallow, with manageable loop and conditional nesting; the extraneous block adds needless scope. Clarity of intent: Descriptive names and Javadoc clearly explain key-generator adaptation, while the unused temperature variables introduce confusion. Code length: Methods are reasonably concise, but the irrelevant block and some repeated validation add unnecessary length. Action granularity: Statements generally perform one action per line, making operations easy to follow. Reading flow: The main delegation and parameter-processing paths read naturally, but inconsistent indentation and the unexpected temperature logic interrupt the flow.

Run 3

Code Structure: Constructors, delegation, parameter processing, and context creation are logically separated, but the unrelated temperature block disrupts cohesion. Nesting: Generally shallow, with manageable conditionals inside one loop; the extra standalone block adds needless nesting. Clarity of intent: Descriptive names, documentation, and assertions explain the adapter's purpose, but the unused temperature calculation is confusing and irrelevant. Code length: Mostly concise, although the temperature block and some repeated validation add overhead. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: The adapter follows a natural progression from construction to key generation and helper methods, but inconsistent indentation and the abrupt temperature example interrupt that flow.