From 8dabf86641301b1de0fb91e083fea5a6c529814f Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 14 Oct 2019 00:19:03 +0000 Subject: [PATCH] Renamed some method parameters to completely avoid variable shadowing. --- src/io/nayuki/fastqrcodegen/QrCode.java | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/io/nayuki/fastqrcodegen/QrCode.java b/src/io/nayuki/fastqrcodegen/QrCode.java index b629391..6f43d93 100644 --- a/src/io/nayuki/fastqrcodegen/QrCode.java +++ b/src/io/nayuki/fastqrcodegen/QrCode.java @@ -231,16 +231,16 @@ public final class QrCode { * @param ver the version number to use, which must be in the range 1 to 40 (inclusive) * @param ecl the error correction level to use * @param dataCodewords the bytes representing segments to encode (without ECC) - * @param mask the mask pattern to use, which is either −1 for automatic choice or from 0 to 7 for fixed choice + * @param msk the mask pattern to use, which is either −1 for automatic choice or from 0 to 7 for fixed choice * @throws NullPointerException if the byte array or error correction level is {@code null} * @throws IllegalArgumentException if the version or mask value is out of range, * or if the data is the wrong length for the specified version and error correction level */ - public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int mask) { + public QrCode(int ver, Ecc ecl, byte[] dataCodewords, int msk) { // Check arguments and initialize fields if (ver < MIN_VERSION || ver > MAX_VERSION) throw new IllegalArgumentException("Version value out of range"); - if (mask < -1 || mask > 7) + if (msk < -1 || msk > 7) throw new IllegalArgumentException("Mask value out of range"); version = ver; size = ver * 4 + 17; @@ -253,7 +253,7 @@ public final class QrCode { // Compute ECC, draw modules, do masking byte[] allCodewords = addEccAndInterleave(dataCodewords); drawCodewords(tpl.dataOutputBitIndexes, allCodewords); - this.mask = handleConstructorMasking(tpl.masks, mask); + this.mask = handleConstructorMasking(tpl.masks, msk); } @@ -345,9 +345,9 @@ public final class QrCode { // Draws two copies of the format bits (with its own error correction code) // based on the given mask and this object's error correction level field. - private void drawFormatBits(int mask) { + private void drawFormatBits(int msk) { // Calculate error correction code and pack bits - int data = errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3 + int data = errorCorrectionLevel.formatBits << 3 | msk; // errCorrLvl is uint2, mask is uint3 int rem = data; for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); @@ -440,35 +440,35 @@ public final class QrCode { // before masking. Due to the arithmetic of XOR, calling applyMask() with // the same mask value a second time will undo the mask. A final well-formed // QR Code needs exactly one (not zero, two, etc.) mask applied. - private void applyMask(int[] mask) { - if (mask.length != modules.length) + private void applyMask(int[] msk) { + if (msk.length != modules.length) throw new IllegalArgumentException(); - for (int i = 0; i < mask.length; i++) - modules[i] ^= mask[i]; + for (int i = 0; i < msk.length; i++) + modules[i] ^= msk[i]; } // A messy helper function for the constructor. This QR Code must be in an unmasked state when this // method is called. The 'mask' argument is the requested mask, which is -1 for auto or 0 to 7 for fixed. // This method applies and returns the actual mask chosen, from 0 to 7. - private int handleConstructorMasking(int[][] masks, int mask) { - if (mask == -1) { // Automatically choose best mask + private int handleConstructorMasking(int[][] masks, int msk) { + if (msk == -1) { // Automatically choose best mask int minPenalty = Integer.MAX_VALUE; for (int i = 0; i < 8; i++) { applyMask(masks[i]); drawFormatBits(i); int penalty = getPenaltyScore(); if (penalty < minPenalty) { - mask = i; + msk = i; minPenalty = penalty; } applyMask(masks[i]); // Undoes the mask due to XOR } } - assert 0 <= mask && mask <= 7; - applyMask(masks[mask]); // Apply the final choice of mask - drawFormatBits(mask); // Overwrite old format bits - return mask; // The caller shall assign this value to the final-declared field + assert 0 <= msk && msk <= 7; + applyMask(masks[msk]); // Apply the final choice of mask + drawFormatBits(msk); // Overwrite old format bits + return msk; // The caller shall assign this value to the final-declared field }