Added Javadoc and informal comments to some members, which differ from the parent project.

pull/134/head
Project Nayuki 6 years ago
parent f6e7b17602
commit b669311c2e

@ -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() { public byte[] getBytes() {
if (bitLength % 8 != 0) if (bitLength % 8 != 0)
throw new IllegalStateException("Data is not a whole number of bytes"); throw new IllegalStateException("Data is not a whole number of bytes");

@ -208,6 +208,7 @@ public final class QrCode {
* −1), the resulting object still has a mask value between 0 and 7. */ * −1), the resulting object still has a mask value between 0 and 7. */
public final int mask; public final int mask;
// The modules of this QR Code. Immutable after constructor finishes. Accessed through getModule().
private final int[] modules; 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) { private void setModule(int x, int y, int black) {
assert 0 <= x && x < size; assert 0 <= x && x < size;
assert 0 <= y && y < size; assert 0 <= y && y < size;

@ -30,6 +30,18 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
/**
* A segment of character/binary/control data in a QR Code symbol.
* Instances of this class are immutable.
* <p>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.</p>
* <p>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.</p>
*/
public final class QrSegment { public final class QrSegment {
/*---- Static factory functions (mid level) ----*/ /*---- 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) { public static boolean isNumeric(String text) {
for (int i = 0; i < text.length(); i++) { for (int i = 0; i < text.length(); i++) {
char c = text.charAt(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) { public static boolean isAlphanumeric(String text) {
for (int i = 0; i < text.length(); i++) { for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i); char c = text.charAt(i);

Loading…
Cancel
Save