diff --git a/android/src/com/google/zxing/client/android/Contents.java b/android/src/com/google/zxing/client/android/Contents.java index 1cfff173f..258f5ef07 100755 --- a/android/src/com/google/zxing/client/android/Contents.java +++ b/android/src/com/google/zxing/client/android/Contents.java @@ -28,6 +28,9 @@ public final class Contents { private Contents() { } + /** + * Contains type constants used when sending Intents. + */ public static final class Type { /** * Plain text. Use Intent.putExtra(DATA, string). This can be used for URLs too, but string diff --git a/android/src/com/google/zxing/client/android/HttpHelper.java b/android/src/com/google/zxing/client/android/HttpHelper.java index 5a1543d57..6808d8d8f 100644 --- a/android/src/com/google/zxing/client/android/HttpHelper.java +++ b/android/src/com/google/zxing/client/android/HttpHelper.java @@ -45,7 +45,10 @@ public final class HttpHelper { private HttpHelper() { } - + + /** + * Enumeration of supported HTTP content types + */ public enum ContentType { /** HTML-like content type, including HTML, XHTML, etc. */ HTML, diff --git a/android/src/com/google/zxing/client/android/Intents.java b/android/src/com/google/zxing/client/android/Intents.java index 6e59e8082..4ed483c4b 100755 --- a/android/src/com/google/zxing/client/android/Intents.java +++ b/android/src/com/google/zxing/client/android/Intents.java @@ -26,6 +26,9 @@ public final class Intents { private Intents() { } + /** + * Constants related to the {@link Scan#ACTION} Intent. + */ public static final class Scan { /** * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return @@ -174,6 +177,9 @@ public final class Intents { } } + /** + * Constants related to the scan history and retrieving history items. + */ public static final class History { public static final String ITEM_NUMBER = "ITEM_NUMBER"; @@ -182,6 +188,9 @@ public final class Intents { } } + /** + * Constants related to the {@link Encode#ACTION} Intent. + */ public static final class Encode { /** * Send this intent to encode a piece of data as a QR code and display it full screen, so @@ -220,6 +229,9 @@ public final class Intents { } } + /** + * Constants related to the {@link SearchBookContents#ACTION} Intent. + */ public static final class SearchBookContents { /** * Use Google Book Search to search the contents of the book provided. @@ -240,6 +252,9 @@ public final class Intents { } } + /** + * Constants related to the {@link WifiConnect#ACTION} Intent. + */ public static final class WifiConnect { /** * Internal intent used to trigger connection to a wi-fi network. @@ -265,6 +280,9 @@ public final class Intents { } } + /** + * Constants related to the {@link Share#ACTION} Intent. + */ public static final class Share { /** * Give the user a choice of items to encode as a barcode, then render it as a QR Code and diff --git a/android/src/com/google/zxing/client/android/PreferencesFragment.java b/android/src/com/google/zxing/client/android/PreferencesFragment.java index d934edb93..fcd6ba551 100644 --- a/android/src/com/google/zxing/client/android/PreferencesFragment.java +++ b/android/src/com/google/zxing/client/android/PreferencesFragment.java @@ -30,6 +30,11 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; +/** + * Implements support for barcode scanning preferences. + * + * @see PreferencesActivity + */ public final class PreferencesFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { diff --git a/android/src/com/google/zxing/client/android/camera/open/CameraFacing.java b/android/src/com/google/zxing/client/android/camera/open/CameraFacing.java index 20fd4e3c5..ece13104a 100755 --- a/android/src/com/google/zxing/client/android/camera/open/CameraFacing.java +++ b/android/src/com/google/zxing/client/android/camera/open/CameraFacing.java @@ -16,6 +16,9 @@ package com.google.zxing.client.android.camera.open; +/** + * Enumeration of directions a camera may face: front or back. + */ public enum CameraFacing { BACK, // must be value 0! diff --git a/android/src/com/google/zxing/client/android/camera/open/OpenCamera.java b/android/src/com/google/zxing/client/android/camera/open/OpenCamera.java index ddac7345b..974c35254 100755 --- a/android/src/com/google/zxing/client/android/camera/open/OpenCamera.java +++ b/android/src/com/google/zxing/client/android/camera/open/OpenCamera.java @@ -18,6 +18,9 @@ package com.google.zxing.client.android.camera.open; import android.hardware.Camera; +/** + * Represents an open {@link Camera} and its metadata, like facing direction and orientation. + */ public final class OpenCamera { private final int index; diff --git a/android/src/com/google/zxing/client/android/camera/open/OpenCameraInterface.java b/android/src/com/google/zxing/client/android/camera/open/OpenCameraInterface.java index 24e0f13a1..7d13ddea1 100644 --- a/android/src/com/google/zxing/client/android/camera/open/OpenCameraInterface.java +++ b/android/src/com/google/zxing/client/android/camera/open/OpenCameraInterface.java @@ -19,6 +19,9 @@ package com.google.zxing.client.android.camera.open; import android.hardware.Camera; import android.util.Log; +/** + * Abstraction over the {@link Camera} API that helps open them and return their metadata. + */ public final class OpenCameraInterface { private static final String TAG = OpenCameraInterface.class.getName(); diff --git a/android/src/com/google/zxing/client/android/clipboard/ClipboardInterface.java b/android/src/com/google/zxing/client/android/clipboard/ClipboardInterface.java index 3ba060378..9c3924d09 100644 --- a/android/src/com/google/zxing/client/android/clipboard/ClipboardInterface.java +++ b/android/src/com/google/zxing/client/android/clipboard/ClipboardInterface.java @@ -21,6 +21,9 @@ import android.content.ClipboardManager; import android.content.Context; import android.util.Log; +/** + * Abstraction over the {@link ClipboardManager} API that manages copying and pasting. + */ public final class ClipboardInterface { private static final String TAG = ClipboardInterface.class.getSimpleName(); diff --git a/android/src/com/google/zxing/client/android/history/HistoryActivity.java b/android/src/com/google/zxing/client/android/history/HistoryActivity.java index 24c47c044..2c63c2e26 100644 --- a/android/src/com/google/zxing/client/android/history/HistoryActivity.java +++ b/android/src/com/google/zxing/client/android/history/HistoryActivity.java @@ -38,6 +38,9 @@ import com.google.zxing.client.android.CaptureActivity; import com.google.zxing.client.android.Intents; import com.google.zxing.client.android.R; +/** + * The activity for interacting with the scan history. + */ public final class HistoryActivity extends ListActivity { private static final String TAG = HistoryActivity.class.getSimpleName(); diff --git a/android/src/com/google/zxing/client/android/history/HistoryItem.java b/android/src/com/google/zxing/client/android/history/HistoryItem.java index 45da8bd30..e667cfd95 100644 --- a/android/src/com/google/zxing/client/android/history/HistoryItem.java +++ b/android/src/com/google/zxing/client/android/history/HistoryItem.java @@ -18,6 +18,9 @@ package com.google.zxing.client.android.history; import com.google.zxing.Result; +/** + * Represents one item in the scan history. + */ public final class HistoryItem { private final Result result; diff --git a/android/src/com/google/zxing/client/android/result/supplement/SupplementalInfoRetriever.java b/android/src/com/google/zxing/client/android/result/supplement/SupplementalInfoRetriever.java index 6aa8533fa..a0b927336 100644 --- a/android/src/com/google/zxing/client/android/result/supplement/SupplementalInfoRetriever.java +++ b/android/src/com/google/zxing/client/android/result/supplement/SupplementalInfoRetriever.java @@ -38,6 +38,10 @@ import com.google.zxing.client.result.ParsedResult; import com.google.zxing.client.result.ProductParsedResult; import com.google.zxing.client.result.URIParsedResult; +/** + * Superclass of implementations which can asynchronously retrieve more information + * about a barcode scan. + */ public abstract class SupplementalInfoRetriever extends AsyncTask { private static final String TAG = "SupplementalInfo"; diff --git a/android/src/com/google/zxing/client/android/share/AppPickerActivity.java b/android/src/com/google/zxing/client/android/share/AppPickerActivity.java index 778beafb8..2b05c2bd8 100644 --- a/android/src/com/google/zxing/client/android/share/AppPickerActivity.java +++ b/android/src/com/google/zxing/client/android/share/AppPickerActivity.java @@ -25,6 +25,9 @@ import android.widget.ListView; import java.util.List; +/** + * Activity for picking an installed application to share via Intent. + */ public final class AppPickerActivity extends ListActivity { private AsyncTask> backgroundTask; diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java index 813c53efc..c19b3861c 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkActivity.java @@ -23,6 +23,9 @@ import android.os.Environment; import android.view.View; import android.widget.TextView; +/** + * Activity that runs barcode scanning benchmarks. + */ public final class BenchmarkActivity extends Activity { private View runBenchmarkButton; diff --git a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java index 7191a3341..4fd2bfded 100644 --- a/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java +++ b/androidtest/src/com/google/zxing/client/androidtest/BenchmarkAsyncTask.java @@ -33,6 +33,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +/** + * Asynchronous task which actually runs benchmarks and collects timing.z + */ public final class BenchmarkAsyncTask extends AsyncTask { private static final String TAG = BenchmarkAsyncTask.class.getSimpleName(); diff --git a/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java b/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java index 496c1f856..3c66fb171 100755 --- a/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java +++ b/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java @@ -42,6 +42,9 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; +/** + * Main test app activity. + */ public final class ZXingTestActivity extends Activity { private static final String TAG = ZXingTestActivity.class.getSimpleName(); diff --git a/core/src/main/java/com/google/zxing/aztec/AztecDetectorResult.java b/core/src/main/java/com/google/zxing/aztec/AztecDetectorResult.java index f262e0e6d..8341578d4 100644 --- a/core/src/main/java/com/google/zxing/aztec/AztecDetectorResult.java +++ b/core/src/main/java/com/google/zxing/aztec/AztecDetectorResult.java @@ -20,6 +20,12 @@ import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DetectorResult; +/** + *

Extends {@link DetectorResult} with more information specific to the Aztec format, + * like the number of layers and whether it's compact.

+ * + * @author Sean Owen + */ public final class AztecDetectorResult extends DetectorResult { private final boolean compact; diff --git a/core/src/main/java/com/google/zxing/aztec/AztecWriter.java b/core/src/main/java/com/google/zxing/aztec/AztecWriter.java index a078a9bb0..508d32789 100644 --- a/core/src/main/java/com/google/zxing/aztec/AztecWriter.java +++ b/core/src/main/java/com/google/zxing/aztec/AztecWriter.java @@ -26,6 +26,9 @@ import com.google.zxing.common.BitMatrix; import java.nio.charset.Charset; import java.util.Map; +/** + * Renders an Aztec code as a {@link BitMatrix}. + */ public final class AztecWriter implements Writer { private static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1"); diff --git a/core/src/main/java/com/google/zxing/client/result/AddressBookParsedResult.java b/core/src/main/java/com/google/zxing/client/result/AddressBookParsedResult.java index 291ebfccf..51e009c79 100644 --- a/core/src/main/java/com/google/zxing/client/result/AddressBookParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/AddressBookParsedResult.java @@ -17,6 +17,9 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes contact information, like that in an address book + * entry. + * * @author Sean Owen */ public final class AddressBookParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java b/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java index 48b92a6bc..0bca993e3 100644 --- a/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java @@ -28,6 +28,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** + * Represents a parsed result that encodes a calendar event at a certain time, optionally + * with attendees and a location. + * * @author Sean Owen */ public final class CalendarParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/EmailAddressParsedResult.java b/core/src/main/java/com/google/zxing/client/result/EmailAddressParsedResult.java index 06c4075a4..a5bcd4425 100644 --- a/core/src/main/java/com/google/zxing/client/result/EmailAddressParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/EmailAddressParsedResult.java @@ -17,6 +17,9 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes an email message including recipients, subject + * and body text. + * * @author Sean Owen */ public final class EmailAddressParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/ExpandedProductParsedResult.java b/core/src/main/java/com/google/zxing/client/result/ExpandedProductParsedResult.java index 6053100d4..0355519a8 100644 --- a/core/src/main/java/com/google/zxing/client/result/ExpandedProductParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/ExpandedProductParsedResult.java @@ -29,6 +29,9 @@ package com.google.zxing.client.result; import java.util.Map; /** + * Represents a parsed result that encodes extended product information as encoded + * by the RSS format, like weight, price, dates, etc. + * * @author Antonio Manuel Benjumea Conde, Servinform, S.A. * @author Agustín Delgado, Servinform, S.A. */ diff --git a/core/src/main/java/com/google/zxing/client/result/GeoParsedResult.java b/core/src/main/java/com/google/zxing/client/result/GeoParsedResult.java index 6eaad1ebb..3a2cae6a4 100644 --- a/core/src/main/java/com/google/zxing/client/result/GeoParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/GeoParsedResult.java @@ -17,6 +17,9 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes a geographic coordinate, with latitude, + * longitude and altitude. + * * @author Sean Owen */ public final class GeoParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/ISBNParsedResult.java b/core/src/main/java/com/google/zxing/client/result/ISBNParsedResult.java index 51b63ff82..ebf11c55f 100644 --- a/core/src/main/java/com/google/zxing/client/result/ISBNParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/ISBNParsedResult.java @@ -17,6 +17,8 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes a product ISBN number. + * * @author jbreiden@google.com (Jeff Breidenbach) */ public final class ISBNParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/ProductParsedResult.java b/core/src/main/java/com/google/zxing/client/result/ProductParsedResult.java index 95cfad016..66a5c9b8c 100644 --- a/core/src/main/java/com/google/zxing/client/result/ProductParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/ProductParsedResult.java @@ -17,6 +17,8 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes a product by an identifier of some kind. + * * @author dswitkin@google.com (Daniel Switkin) */ public final class ProductParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/SMSParsedResult.java b/core/src/main/java/com/google/zxing/client/result/SMSParsedResult.java index 69c806c84..176078e09 100644 --- a/core/src/main/java/com/google/zxing/client/result/SMSParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/SMSParsedResult.java @@ -17,6 +17,9 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes an SMS message, including recipients, subject + * and body text. + * * @author Sean Owen */ public final class SMSParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/TelParsedResult.java b/core/src/main/java/com/google/zxing/client/result/TelParsedResult.java index 8b6c6f879..fb606f2c6 100644 --- a/core/src/main/java/com/google/zxing/client/result/TelParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/TelParsedResult.java @@ -17,6 +17,8 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes a telephone number. + * * @author Sean Owen */ public final class TelParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/URIParsedResult.java b/core/src/main/java/com/google/zxing/client/result/URIParsedResult.java index b360de92e..e26e361b4 100644 --- a/core/src/main/java/com/google/zxing/client/result/URIParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/URIParsedResult.java @@ -19,6 +19,8 @@ package com.google.zxing.client.result; import java.util.regex.Pattern; /** + * A simple result type encapsulating a URI that has no further interpretation. + * * @author Sean Owen */ public final class URIParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/client/result/VINParsedResult.java b/core/src/main/java/com/google/zxing/client/result/VINParsedResult.java index dddd7d022..79f722d63 100644 --- a/core/src/main/java/com/google/zxing/client/result/VINParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/VINParsedResult.java @@ -17,7 +17,9 @@ package com.google.zxing.client.result; - +/** + * Represents a parsed result that encodes a Vehicle Identification Number (VIN). + */ public final class VINParsedResult extends ParsedResult { private final String vin; diff --git a/core/src/main/java/com/google/zxing/client/result/WifiParsedResult.java b/core/src/main/java/com/google/zxing/client/result/WifiParsedResult.java index 39dec351d..44c937abe 100644 --- a/core/src/main/java/com/google/zxing/client/result/WifiParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/WifiParsedResult.java @@ -17,6 +17,8 @@ package com.google.zxing.client.result; /** + * Represents a parsed result that encodes wifi network information, like SSID and password. + * * @author Vikram Aggarwal */ public final class WifiParsedResult extends ParsedResult { diff --git a/core/src/main/java/com/google/zxing/common/detector/MathUtils.java b/core/src/main/java/com/google/zxing/common/detector/MathUtils.java index 82aa03943..ec7080d89 100644 --- a/core/src/main/java/com/google/zxing/common/detector/MathUtils.java +++ b/core/src/main/java/com/google/zxing/common/detector/MathUtils.java @@ -16,6 +16,9 @@ package com.google.zxing.common.detector; +/** + * General math-related and numeric utility functions. + */ public final class MathUtils { private MathUtils() { @@ -34,16 +37,42 @@ public final class MathUtils { return (int) (d + (d < 0.0f ? -0.5f : 0.5f)); } + /** + * @param aX point A x coordinate + * @param aY point A y coordinate + * @param bX point B x coordinate + * @param bY point B y coordinate + * @return Euclidean distance between points A and B + */ public static float distance(float aX, float aY, float bX, float bY) { float xDiff = aX - bX; float yDiff = aY - bY; return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); } + /** + * @param aX point A x coordinate + * @param aY point A y coordinate + * @param bX point B x coordinate + * @param bY point B y coordinate + * @return Euclidean distance between points A and B + */ public static float distance(int aX, int aY, int bX, int bY) { int xDiff = aX - bX; int yDiff = aY - bY; return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); } + /** + * @param array values to sum + * @return sum of values in array + */ + public static int sum(int[] array) { + int count = 0; + for (int a : array) { + count += a; + } + return count; + } + } diff --git a/core/src/main/java/com/google/zxing/oned/rss/AbstractRSSReader.java b/core/src/main/java/com/google/zxing/oned/rss/AbstractRSSReader.java index e86b394de..1ec78b244 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/AbstractRSSReader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/AbstractRSSReader.java @@ -17,8 +17,13 @@ package com.google.zxing.oned.rss; import com.google.zxing.NotFoundException; +import com.google.zxing.common.detector.MathUtils; import com.google.zxing.oned.OneDReader; +/** + * Superclass of {@link OneDReader} implementations that read barcodes in the RSS family + * of formats. + */ public abstract class AbstractRSSReader extends OneDReader { private static final float MAX_AVG_VARIANCE = 0.2f; @@ -34,7 +39,7 @@ public abstract class AbstractRSSReader extends OneDReader { private final int[] oddCounts; private final int[] evenCounts; - protected AbstractRSSReader(){ + protected AbstractRSSReader() { decodeFinderCounters = new int[4]; dataCharacterCounters = new int[8]; oddRoundingErrors = new float[4]; @@ -78,12 +83,9 @@ public abstract class AbstractRSSReader extends OneDReader { throw NotFoundException.getNotFoundInstance(); } + @Deprecated protected static int count(int[] array) { - int count = 0; - for (int a : array) { - count += a; - } - return count; + return MathUtils.sum(array); } protected static void increment(int[] array, float[] errors) { diff --git a/core/src/main/java/com/google/zxing/oned/rss/DataCharacter.java b/core/src/main/java/com/google/zxing/oned/rss/DataCharacter.java index 167930000..d8d9a9613 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/DataCharacter.java +++ b/core/src/main/java/com/google/zxing/oned/rss/DataCharacter.java @@ -16,6 +16,9 @@ package com.google.zxing.oned.rss; +/** + * Encapsulates a since character value in an RSS barcode, including its checksum information. + */ public class DataCharacter { private final int value; diff --git a/core/src/main/java/com/google/zxing/oned/rss/FinderPattern.java b/core/src/main/java/com/google/zxing/oned/rss/FinderPattern.java index 492aec977..e9007309d 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/FinderPattern.java +++ b/core/src/main/java/com/google/zxing/oned/rss/FinderPattern.java @@ -18,6 +18,9 @@ package com.google.zxing.oned.rss; import com.google.zxing.ResultPoint; +/** + * Encapsulates an RSS barcode finder pattern, including its start/end position and row. + */ public final class FinderPattern { private final int value; diff --git a/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java b/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java index bbeeac1a4..1847ea7ba 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java @@ -23,6 +23,7 @@ import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.ResultPointCallback; import com.google.zxing.common.BitArray; +import com.google.zxing.common.detector.MathUtils; import java.util.ArrayList; import java.util.Collection; @@ -209,7 +210,7 @@ public final class RSS14Reader extends AbstractRSSReader { } int numModules = outsideChar ? 16 : 15; - float elementWidth = (float) count(counters) / (float) numModules; + float elementWidth = (float) MathUtils.sum(counters) / (float) numModules; int[] oddCounts = this.getOddCounts(); int[] evenCounts = this.getEvenCounts(); @@ -355,8 +356,8 @@ public final class RSS14Reader extends AbstractRSSReader { private void adjustOddEvenCounts(boolean outsideChar, int numModules) throws NotFoundException { - int oddSum = count(getOddCounts()); - int evenSum = count(getEvenCounts()); + int oddSum = MathUtils.sum(getOddCounts()); + int evenSum = MathUtils.sum(getEvenCounts()); int mismatch = oddSum + evenSum - numModules; boolean oddParityBad = (oddSum & 0x01) == (outsideChar ? 1 : 0); boolean evenParityBad = (evenSum & 0x01) == 1; diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java index f6b0859d4..2e3e931ec 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java @@ -33,6 +33,7 @@ import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitArray; +import com.google.zxing.common.detector.MathUtils; import com.google.zxing.oned.rss.AbstractRSSReader; import com.google.zxing.oned.rss.DataCharacter; import com.google.zxing.oned.rss.FinderPattern; @@ -607,7 +608,7 @@ public final class RSSExpandedReader extends AbstractRSSReader { }//counters[] has the pixels of the module int numModules = 17; //left and right data characters have all the same length - float elementWidth = (float) count(counters) / (float) numModules; + float elementWidth = (float) MathUtils.sum(counters) / (float) numModules; // Sanity check: element width for pattern and the character should match float expectedElementWidth = (pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) / 15.0f; @@ -691,8 +692,8 @@ public final class RSSExpandedReader extends AbstractRSSReader { private void adjustOddEvenCounts(int numModules) throws NotFoundException { - int oddSum = count(this.getOddCounts()); - int evenSum = count(this.getEvenCounts()); + int oddSum = MathUtils.sum(this.getOddCounts()); + int evenSum = MathUtils.sum(this.getEvenCounts()); int mismatch = oddSum + evenSum - numModules; boolean oddParityBad = (oddSum & 0x01) == 1; boolean evenParityBad = (evenSum & 0x01) == 0; diff --git a/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java b/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java index 418f54cde..c7f50b4c0 100644 --- a/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java +++ b/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java @@ -18,6 +18,8 @@ package com.google.zxing.pdf417; import java.util.Arrays; import java.util.Collection; +import com.google.zxing.common.detector.MathUtils; + /** * @author SITA Lab (kevin.osullivan@sita.aero) * @author Guenther Grau @@ -40,12 +42,9 @@ public final class PDF417Common { private PDF417Common() { } + @Deprecated public static int getBitCountSum(int[] moduleBitCount) { - int bitCountSum = 0; - for (int count : moduleBitCount) { - bitCountSum += count; - } - return bitCountSum; + return MathUtils.sum(moduleBitCount); } public static int[] toIntArray(Collection list) { diff --git a/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java b/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java index 017f3f399..6eb2b1304 100644 --- a/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java +++ b/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java @@ -16,6 +16,7 @@ package com.google.zxing.pdf417.decoder; +import com.google.zxing.common.detector.MathUtils; import com.google.zxing.pdf417.PDF417Common; /** @@ -56,7 +57,7 @@ final class PDF417CodewordDecoder { } private static int[] sampleBitCounts(int[] moduleBitCount) { - float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount); + float bitCountSum = MathUtils.sum(moduleBitCount); int[] result = new int[PDF417Common.BARS_IN_MODULE]; int bitCountIndex = 0; int sumPreviousBits = 0; @@ -89,7 +90,7 @@ final class PDF417CodewordDecoder { } private static int getClosestDecodedValue(int[] moduleBitCount) { - int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount); + int bitCountSum = MathUtils.sum(moduleBitCount); float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE]; for (int i = 0; i < bitCountRatios.length; i++) { bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum; diff --git a/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java b/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java index e30e1d4ad..a1c2d8f38 100644 --- a/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java +++ b/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java @@ -22,6 +22,7 @@ import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; +import com.google.zxing.common.detector.MathUtils; import com.google.zxing.pdf417.PDF417Common; import com.google.zxing.pdf417.decoder.ec.ErrorCorrection; @@ -326,7 +327,7 @@ public final class PDF417ScanningDecoder { throw ChecksumException.getChecksumInstance(); } - private static BarcodeValue[][] createBarcodeMatrix(DetectionResult detectionResult) throws FormatException { + private static BarcodeValue[][] createBarcodeMatrix(DetectionResult detectionResult) { BarcodeValue[][] barcodeMatrix = new BarcodeValue[detectionResult.getBarcodeRowCount()][detectionResult.getBarcodeColumnCount() + 2]; for (int row = 0; row < barcodeMatrix.length; row++) { @@ -417,7 +418,7 @@ public final class PDF417ScanningDecoder { return null; } int endColumn; - int codewordBitCount = PDF417Common.getBitCountSum(moduleBitCount); + int codewordBitCount = MathUtils.sum(moduleBitCount); if (leftToRight) { endColumn = startColumn + codewordBitCount; } else { diff --git a/core/src/main/java/com/google/zxing/pdf417/encoder/Compaction.java b/core/src/main/java/com/google/zxing/pdf417/encoder/Compaction.java index d0a85d600..3a2c032f0 100644 --- a/core/src/main/java/com/google/zxing/pdf417/encoder/Compaction.java +++ b/core/src/main/java/com/google/zxing/pdf417/encoder/Compaction.java @@ -16,6 +16,9 @@ package com.google.zxing.pdf417.encoder; +/** + * Represents possible PDF417 barcode compaction types. + */ public enum Compaction { AUTO, diff --git a/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java b/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java index 986e6b997..4e53bbafe 100644 --- a/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java +++ b/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java @@ -34,7 +34,7 @@ import java.util.TimeZone; */ public final class CalendarParsedResultTestCase extends Assert { - private static final double EPSILON = 0.0000000001; + private static final double EPSILON = 1.0E-10; private static DateFormat makeGMTFormat() { DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); diff --git a/core/src/test/java/com/google/zxing/client/result/GeoParsedResultTestCase.java b/core/src/test/java/com/google/zxing/client/result/GeoParsedResultTestCase.java index 803cc0bb0..677b1bca5 100644 --- a/core/src/test/java/com/google/zxing/client/result/GeoParsedResultTestCase.java +++ b/core/src/test/java/com/google/zxing/client/result/GeoParsedResultTestCase.java @@ -28,7 +28,7 @@ import org.junit.Test; */ public final class GeoParsedResultTestCase extends Assert { - private static final double EPSILON = 0.0000000001; + private static final double EPSILON = 1.0E-10; @Test public void testGeo() { diff --git a/core/src/test/java/com/google/zxing/common/PerspectiveTransformTestCase.java b/core/src/test/java/com/google/zxing/common/PerspectiveTransformTestCase.java index 531c46bcd..651c6fb5d 100644 --- a/core/src/test/java/com/google/zxing/common/PerspectiveTransformTestCase.java +++ b/core/src/test/java/com/google/zxing/common/PerspectiveTransformTestCase.java @@ -24,7 +24,7 @@ import org.junit.Test; */ public final class PerspectiveTransformTestCase extends Assert { - private static final float EPSILON = 0.0001f; + private static final float EPSILON = 1.0E-4f; @Test public void testSquareToQuadrilateral() { diff --git a/core/src/test/java/com/google/zxing/common/detector/MathUtilsTestCase.java b/core/src/test/java/com/google/zxing/common/detector/MathUtilsTestCase.java index 9f1f2ec03..18f364cc9 100644 --- a/core/src/test/java/com/google/zxing/common/detector/MathUtilsTestCase.java +++ b/core/src/test/java/com/google/zxing/common/detector/MathUtilsTestCase.java @@ -21,6 +21,8 @@ import org.junit.Test; public final class MathUtilsTestCase extends Assert { + private static final float EPSILON = 1.0E-8f; + @Test public void testRound() { assertEquals(-1, MathUtils.round(-1.0f)); @@ -46,4 +48,21 @@ public final class MathUtilsTestCase extends Assert { assertEquals(0, MathUtils.round(Float.NaN)); } + @Test + public void testDistance() { + assertEquals((float) Math.sqrt(8.0), MathUtils.distance(1.0f, 2.0f, 3.0f, 4.0f), EPSILON); + assertEquals(0.0f, MathUtils.distance(1.0f, 2.0f, 1.0f, 2.0f), EPSILON); + + assertEquals((float) Math.sqrt(8.0), MathUtils.distance(1, 2, 3, 4), EPSILON); + assertEquals(0.0f, MathUtils.distance(1, 2, 1, 2), EPSILON); + } + + @Test + public void testSum() { + assertEquals(0, MathUtils.sum(new int[] {})); + assertEquals(1, MathUtils.sum(new int[] {1})); + assertEquals(4, MathUtils.sum(new int[] {1, 3})); + assertEquals(0, MathUtils.sum(new int[] {-1, 1})); + } + } diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 8ea649502..59ae86cbf 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -72,11 +72,9 @@ --> - diff --git a/zxing.appspot.com/src/main/java/com/google/zxing/web/generator/client/Generator.java b/zxing.appspot.com/src/main/java/com/google/zxing/web/generator/client/Generator.java index fd8e5e46a..6a8b30dad 100644 --- a/zxing.appspot.com/src/main/java/com/google/zxing/web/generator/client/Generator.java +++ b/zxing.appspot.com/src/main/java/com/google/zxing/web/generator/client/Generator.java @@ -43,6 +43,9 @@ import com.google.gwt.user.client.ui.Widget; import java.util.ArrayList; import java.util.List; +/** + * Main generator for the encoder web interface. + */ public final class Generator implements EntryPoint { private final List generators = new ArrayList<>(); diff --git a/zxingorg/src/main/java/com/google/zxing/web/RedirectFilter.java b/zxingorg/src/main/java/com/google/zxing/web/RedirectFilter.java index 487b768be..3931ff905 100644 --- a/zxingorg/src/main/java/com/google/zxing/web/RedirectFilter.java +++ b/zxingorg/src/main/java/com/google/zxing/web/RedirectFilter.java @@ -28,11 +28,24 @@ import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +/** + * A {@link Filter} which handles a few web app redirects, like redirecting {@code /} to the + * main page. + */ @WebFilter("/*") public final class RedirectFilter implements Filter { private static final String OLD_JAVADOC_PREFIX = "/w/docs/javadoc"; + private static final Collection REDIRECT_WELCOME_PATHS = new HashSet<>(); + static { + REDIRECT_WELCOME_PATHS.add("/"); + REDIRECT_WELCOME_PATHS.add("/index.jspx"); + REDIRECT_WELCOME_PATHS.add("/w/"); + REDIRECT_WELCOME_PATHS.add("/w/index.jspx"); + } @Override public void init(FilterConfig filterConfig) { @@ -45,8 +58,7 @@ public final class RedirectFilter implements Filter { FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String requestURI = request.getRequestURI(); - if ("/".equals(requestURI) || "/index.jspx".equals(requestURI) || - "/w/".equals(requestURI) || "/w/index.jspx".equals(requestURI)) { + if (REDIRECT_WELCOME_PATHS.contains(requestURI)) { redirect(servletResponse, "/w/decode.jspx"); } else if (requestURI.startsWith(OLD_JAVADOC_PREFIX)) { String withoutPrefix = requestURI.substring(OLD_JAVADOC_PREFIX.length());