Add minimal javadoc to all classes (and enforce with checkstyle); minor refactoring to of array sum code

This commit is contained in:
Sean Owen 2016-06-04 15:36:22 +01:00
parent 7cf49565c2
commit 389f69f4b2
46 changed files with 207 additions and 30 deletions

View file

@ -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

View file

@ -46,6 +46,9 @@ public final class HttpHelper {
private HttpHelper() {
}
/**
* Enumeration of supported HTTP content types
*/
public enum ContentType {
/** HTML-like content type, including HTML, XHTML, etc. */
HTML,

View file

@ -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

View file

@ -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 {

View file

@ -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!

View file

@ -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;

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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;

View file

@ -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<Object,Object,Object> {
private static final String TAG = "SupplementalInfo";

View file

@ -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<Object,Object,List<AppInfo>> backgroundTask;

View file

@ -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;

View file

@ -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<Object,Object,String> {
private static final String TAG = BenchmarkAsyncTask.class.getSimpleName();

View file

@ -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();

View file

@ -20,6 +20,12 @@ import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
/**
* <p>Extends {@link DetectorResult} with more information specific to the Aztec format,
* like the number of layers and whether it's compact.</p>
*
* @author Sean Owen
*/
public final class AztecDetectorResult extends DetectorResult {
private final boolean compact;

View file

@ -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");

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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.
*/

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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;

View file

@ -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 {

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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<Integer> list) {

View file

@ -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;

View file

@ -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 {

View file

@ -16,6 +16,9 @@
package com.google.zxing.pdf417.encoder;
/**
* Represents possible PDF417 barcode compaction types.
*/
public enum Compaction {
AUTO,

View file

@ -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);

View file

@ -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() {

View file

@ -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() {

View file

@ -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}));
}
}

View file

@ -72,11 +72,9 @@
<property name="scope" value="protected"/>
</module>
-->
<!--
<module name="JavadocType">
<property name="scope" value="protected"/>
</module>
-->
<!--<module name="JavadocVariable"/>-->
<module name="JavadocStyle">
<property name="checkFirstSentence" value="false"/>

View file

@ -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<GeneratorSource> generators = new ArrayList<>();

View file

@ -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<String> 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());