Sample

int-ecb86316517a-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines134

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.8490–1; higher is more readable
Dorn0.2380–1; higher is more readable
Mi0.4680–1; higher is more readable
LLOC31Logical lines; fewer is more readable
DeepSeek V4 Pro11.670–20; mean of three runs
GPT-6.1 Sol13.330–20; mean of three runs
BTTF0.560–1; higher is more readable

Views

Source code

package com.google.common.escape; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; import java.util.Map; import org.jspecify.annotations.Nullable; /** * A {@link CharEscaper} that uses an array to quickly look up replacement characters for a given * {@code char} value. An additional safe range is provided that determines whether {@code char} * values without specific replacements are to be considered safe and left unescaped or should be * escaped in a general way. * * <p>A good example of usage of this class is for Java source code escaping where the replacement * array contains information about special ASCII characters such as {@code \\t} and {@code \\n} * while {@link #escapeUnsafe} is overridden to handle general escaping of the form {@code \\uxxxx}. * * <p>The size of the data structure used by {@link ArrayBasedCharEscaper} is proportional to the * highest valued character that requires escaping. For example a replacement map containing the * single character '{@code \}{@code u1000}' will require approximately 16K of memory. If you need * to create multiple escaper instances that have the same character replacement mapping consider * using {@link ArrayBasedEscaperMap}. * * @author Sven Mawson * @author David Beaumont * @since 15.0 */ @GwtCompatible public abstract class ArrayBasedCharEscaper extends CharEscaper { // The replacement array (see ArrayBasedEscaperMap). private final char[][] replacements; // The number of elements in the replacement array. private final int replacementsLength; // The first character in the safe range. private final char safeMin; // The last character in the safe range. private final char safeMax; /** * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe * range. If {@code safeMax < safeMin} then no characters are considered safe. * * <p>If a character has no mapped replacement then it is checked against the safe range. If it * lies outside that, then {@link #escapeUnsafe} is called, otherwise no escaping is performed. * * @param replacementMap a map of characters to their escaped representations * @param safeMin the lowest character value in the safe range * @param safeMax the highest character value in the safe range */ protected ArrayBasedCharEscaper( Map<Character, String> replacementMap, char safeMin, char safeMax) { this(ArrayBasedEscaperMap.create(replacementMap), safeMin, safeMax); } /** * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe * range. If {@code safeMax < safeMin} then no characters are considered safe. This initializer is * useful when explicit instances of ArrayBasedEscaperMap are used to allow the sharing of large * replacement mappings. * * <p>If a character has no mapped replacement then it is checked against the safe range. If it * lies outside that, then {@link #escapeUnsafe} is called, otherwise no escaping is performed. * * @param escaperMap the mapping of characters to be escaped * @param safeMin the lowest character value in the safe range * @param safeMax the highest character value in the safe range */ protected ArrayBasedCharEscaper(ArrayBasedEscaperMap escaperMap, char safeMin, char safeMax) { checkNotNull(escaperMap); // GWT specific check (do not optimize) this.replacements = escaperMap.getReplacementArray(); this.replacementsLength = replacements.length; if (!((safeMax < safeMin))) {} else { // If the safe range is empty, set the range limits to opposite extremes // to ensure the first test of either value will (almost certainly) fail. safeMax = Character.MIN_VALUE; safeMin = Character.MAX_VALUE; } this.safeMin = safeMin; this.safeMax = safeMax; } /* * This is overridden to improve performance. Rough benchmarking shows that this almost doubles * the speed when processing strings that do not require any escaping. */ @Override public final String escape(String s) { checkNotNull(s); // GWT specific check (do not optimize). for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!(((c < replacementsLength && replacements[c] != null) || c > safeMax || c < safeMin))) {} else { return escapeSlow(s, i); } } return s; } /** * Escapes a single character using the replacement array and safe range values. If the given * character does not have an explicit replacement and lies outside the safe range then {@link * #escapeUnsafe} is called. * * @return the replacement characters, or {@code null} if no escaping was required */ @Override protected final char @Nullable [] escape(char c) { if (!((c < replacementsLength))) {} else { char[] chars = replacements[c]; if (chars != null) { return chars; } } if (!((c >= safeMin && c <= safeMax))) {} else { return null; } return escapeUnsafe(c); } /** * Escapes a {@code char} value that has no direct explicit value in the replacement array and * lies outside the stated safe range. Subclasses should override this method to provide * generalized escaping for characters. * * <p>Note that arrays returned by this method must not be modified once they have been returned. * However it is acceptable to return the same array multiple times (even for different input * characters). * * @param c the character to escape * @return the replacement characters, or {@code null} if no escaping was required */ // TODO(dbeaumont,cpovirk): Rename this something better once refactoring done protected abstract char @Nullable [] escapeUnsafe(char c); }

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.2350.045−77.551
Source linesThe number of non-empty source lines.134+53.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.621−6.931

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

Score0.849

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.135−3.744
Indentation frequencyHow rapidly indentation changes from line to line.64+1.477
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.133.796+1.46
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.64−1.048
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.105.356+0.895
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.106.963−0.865
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.036+0.589

Intercept 0.07 + feature contributions = -1.165 (log-odds).
Score = sigmoid(-1.165) = 0.238.

Score0.468
Score31
Run 1

The code is moderately readable due to good documentation and clear field naming, but is significantly hindered by bizarre inverted conditionals. The patterns 'if (!(condition)) {} else { ... }' are confusing and disrupt natural reading flow, making the logic harder to follow than necessary. Additionally, the constructor and escape method arguments are swapped from their declaration order, and the class has relatively high complexity with multiple responsibilities. While the overall structure and conceptual clarity are acceptable, the unnatural conditional style and occasional verbosity prevent higher readability.

Run 2

The code has good Javadoc documentation and clear field/variable names, but readability is severely impacted by unusual inverted conditional patterns using empty if blocks with else statements. For example, `if (!((safeMax < safeMin))) {} else { ... }` and `if (!(((c < replacementsLength && replacements[c] != null) || c > safeMax || c < safeMin))) {} else { ... }` are confusing and break natural reading flow. The double negation and empty blocks force readers to mentally invert logic, violating the 'one action per line' and 'clear intent' principles. The class structure is logical and the code length is reasonable, but the nesting complexity from these inverted conditionals makes the logic hard to follow. The safe range adjustment in the constructor could be clearer with a simple direct condition rather than the awkward empty if/else pattern.

Run 3

The code is generally well-structured with clear class-level documentation, meaningful field names, and logical method organization. However, readability is notably hampered by several awkward inverted conditional constructs (e.g., `if (!((safeMax < safeMin))) {} else { ... }`), which appear to be artifacts of a debugger or automated transformation. These empty blocks and double negatives obscure intent and break reading flow. The `escape(String)` method likewise contains a convoluted condition with an empty `if` block, making it difficult to follow at a glance. Method lengths are reasonable, and action granularity is mostly one-per-line, but the unnatural conditionals reduce clarity and make the code feel tangled despite the otherwise clean structure. Comments are helpful, though some explain what could be clearer through simpler logic.

Run 1

Code Structure: Fields, constructors, and escaping methods are logically organized with clear responsibilities. Nesting: Generally shallow, with only a loop and a small nested replacement check. Clarity of intent: Descriptive names and thorough documentation explain replacement lookup and safe ranges, but negated conditions, redundant parentheses, and empty if branches obscure straightforward decisions. Code length: Implementation is reasonably concise; repeated constructor documentation and unnecessary conditional syntax add bulk. Action granularity: Most lines perform a single action, although inline empty branches and else clauses compress control flow awkwardly. Reading flow: Constructor delegation and early returns support natural progression, but repeatedly placing meaningful work in else branches forces readers to mentally invert conditions. Direct positive conditions would substantially improve readability.

Run 2

Code Structure: Fields, constructors, and escaping methods are logically organized with clear responsibilities. Nesting: Mostly shallow, with only a loop and a small nested replacement check. Clarity of intent: Descriptive names and thorough documentation explain the escaping rules, but repeated negated conditions with empty if branches and operative else branches obscure straightforward logic. Code length: Implementation is reasonably concise, though duplicated constructor documentation and redundant parentheses add bulk. Action granularity: Most statements perform one action per line, but inline empty branches compress control flow awkwardly. Reading flow: Method ordering and early returns are natural; however, inverted conditionals repeatedly force readers to mentally simplify expressions, particularly the compound condition in escape(String). Replacing these constructs with direct positive conditions would substantially improve readability.

Run 3

Code Structure: Fields, constructors, and escaping methods are logically organized, with clear separation of responsibilities. Nesting: Mostly shallow, although empty if branches followed by else blocks introduce unnecessary structural complexity. Clarity of intent: Descriptive names and thorough documentation explain the escaping rules, but negated conditions, redundant parentheses, and empty branches obscure otherwise straightforward checks. Code length: Implementation is reasonably concise; repeated constructor documentation and verbose conditional syntax add avoidable length. Action granularity: Most lines perform one action, but compressed empty-if/else statements combine control-flow elements and hinder scanning. Reading flow: The class progresses naturally from configuration to string and character escaping, yet readers must repeatedly mentally invert conditions to understand the active branches. Replacing these constructs with direct positive conditions would substantially improve readability.