From b669311c2eed9c9afe5f8d6f54ca0da551cab927 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sun, 7 Oct 2018 06:33:33 +0000 Subject: [PATCH] Added Javadoc and informal comments to some members, which differ from the parent project. --- src/io/nayuki/fastqrcodegen/BitBuffer.java | 5 ++++ src/io/nayuki/fastqrcodegen/QrCode.java | 3 +++ src/io/nayuki/fastqrcodegen/QrSegment.java | 29 ++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/io/nayuki/fastqrcodegen/BitBuffer.java b/src/io/nayuki/fastqrcodegen/BitBuffer.java index f187e9f..7031914 100644 --- a/src/io/nayuki/fastqrcodegen/BitBuffer.java +++ b/src/io/nayuki/fastqrcodegen/BitBuffer.java @@ -65,6 +65,11 @@ final class BitBuffer { } + /** + * Returns an array representing this buffer's bits packed into bytes + * in big endian. The current bit length must be a multiple of 8. + * @return a new byte array (not {@code null}) representing this bit sequence + */ public byte[] getBytes() { if (bitLength % 8 != 0) throw new IllegalStateException("Data is not a whole number of bytes"); diff --git a/src/io/nayuki/fastqrcodegen/QrCode.java b/src/io/nayuki/fastqrcodegen/QrCode.java index 4366d5f..a1e71e0 100644 --- a/src/io/nayuki/fastqrcodegen/QrCode.java +++ b/src/io/nayuki/fastqrcodegen/QrCode.java @@ -208,6 +208,7 @@ public final class QrCode { * −1), the resulting object still has a mask value between 0 and 7. */ public final int mask; + // The modules of this QR Code. Immutable after constructor finishes. Accessed through getModule(). private final int[] modules; @@ -363,6 +364,8 @@ public final class QrCode { } + // Sets the module at the given coordinates to the given color. + // Only used by the constructor. Coordinates must be in bounds. private void setModule(int x, int y, int black) { assert 0 <= x && x < size; assert 0 <= y && y < size; diff --git a/src/io/nayuki/fastqrcodegen/QrSegment.java b/src/io/nayuki/fastqrcodegen/QrSegment.java index 9f91ac4..cf0d655 100644 --- a/src/io/nayuki/fastqrcodegen/QrSegment.java +++ b/src/io/nayuki/fastqrcodegen/QrSegment.java @@ -30,6 +30,18 @@ import java.util.List; import java.util.Objects; +/** + * A segment of character/binary/control data in a QR Code symbol. + * Instances of this class are immutable. + *

The mid-level way to create a segment is to take the payload data and call a + * static factory function such as {@link QrSegment#makeNumeric(String)}. The low-level + * way to create a segment is to custom-make the bit buffer and call the {@link + * QrSegment#QrSegment(Mode,int,int[],int) constructor} with appropriate values.

+ *

This segment class imposes no length restrictions, but QR Codes have restrictions. + * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. + * Any segment longer than this is meaningless for the purpose of generating QR Codes. + * This class can represent kanji mode segments, but provides no help in encoding them.

+ */ public final class QrSegment { /*---- Static factory functions (mid level) ----*/ @@ -162,6 +174,14 @@ public final class QrSegment { } + /** + * Tests whether the specified string can be encoded as a segment in numeric mode. + * A string is encodable iff each character is in the range 0 to 9. + * @param text the string to test for encodability (not {@code null}) + * @return {@code true} iff each character is in the range 0 to 9. + * @throws NullPointerException if the string is {@code null} + * @see #makeNumeric(String) + */ public static boolean isNumeric(String text) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); @@ -172,6 +192,15 @@ public final class QrSegment { } + /** + * Tests whether the specified string can be encoded as a segment in alphanumeric mode. + * A string is encodable iff each character is in the following set: 0 to 9, A to Z + * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. + * @param text the string to test for encodability (not {@code null}) + * @return {@code true} iff each character is in the alphanumeric mode character set + * @throws NullPointerException if the string is {@code null} + * @see #makeAlphanumeric(String) + */ public static boolean isAlphanumeric(String text) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i);